public static void Rating_sort(Matriculant[] abitur, int Length) //Сортировка абитуриентов { if (abitur[0] == null) { Console.WriteLine("Your list is empty!"); return; } for (int i = 0; i < Length; i++) { for (int j = 0; j < Length - i - 1; j++) { if (abitur[j].total_score < abitur[j + 1].total_score) { Matriculant temp = abitur[j]; int temp_id = abitur[j].ID; abitur[j].ID = abitur[j + 1].ID; abitur[j] = abitur[j + 1]; abitur[j + 1].ID = temp_id; abitur[j + 1] = temp; } } } }
static void Main(string[] args) { int i = 0; Matriculant[] abitur = new Matriculant[255]; //Инициализация int[] speciality_count = new int[9]; int[] speciality_places = new int[9]; string[] speciality = new string[] { "ME", "PMEN", "PMS", "CMSN", "SIT", "ITP", "ASPI", "AI", "ITM" }; for (int j = 0; j < 9; j++) { speciality_count[j] = 0; speciality_places[j] = 5; //Кол-во бюджетных мест(можно изменить) } for (int exit = 0; exit != 1;) { Console.Clear(); Console.WriteLine("========================="); Console.WriteLine("Database of matriculants:"); Console.WriteLine("========================="); Console.WriteLine("1.Add Matriculant"); Console.WriteLine("2.Rating of matriculants"); //Главное МЕНЮ Console.WriteLine("3.Withdraw aplication"); Console.WriteLine("4.Enroll matriculants"); Console.WriteLine("5.List of students"); Console.WriteLine("6.Exit"); var choice = Console.ReadKey(); switch (choice.Key) { case ConsoleKey.D1: { Console.Clear(); abitur[i] = new Matriculant(); abitur[i].add(i); i++; break; } case ConsoleKey.D2: { Console.Clear(); Console.WriteLine("======================"); Console.WriteLine("Rating of matriculants"); Console.WriteLine("======================"); Console.WriteLine(); Matriculant.Rating_sort(abitur, i); for (int j = 0; j < i; j++) { abitur[j].show(); } Console.WriteLine("Click any button..."); Console.ReadKey(); break; } case ConsoleKey.D3: { Console.Clear(); Console.WriteLine("=================="); Console.WriteLine("Delete matriculant"); Console.WriteLine("=================="); Console.WriteLine(); if (abitur[0] == null) { Console.WriteLine("Your list is empty!"); Console.WriteLine("Click any button... "); Console.ReadKey(); break; } for (int j = 0; j < i; j++) { Console.WriteLine("Matriculant №" + (j + 1)); abitur[j].show(); } Console.WriteLine("\nChoose № of matriculant: "); int number = 0; do { try { number = int.Parse(Console.ReadLine()); if (number > i + 1) { Console.WriteLine("There are only " + i + " matriculants!"); number = 0; } } catch (FormatException) { Console.WriteLine("Invalid input!"); } } while (number == 0); for (int j = number - 1; j < i; j++) //Удаление заявки { if (j == i - 1) { abitur[j] = null; i--; break; } abitur[j] = abitur[j + 1]; abitur[j].ID--; } Console.WriteLine("Click any button... "); Console.ReadKey(); break; } case ConsoleKey.D4: { Console.Clear(); Console.WriteLine("======"); Console.WriteLine("Enroll"); Console.WriteLine("======"); Console.WriteLine(); Matriculant.Rating_sort(abitur, i); for (int j = 0; j < i; j++) { for (int count = 0; count < 9; count++) { if (abitur[j].speciality == speciality[count]) { speciality_count[count]++; } } } for (int count = 0; count < 9; count++) { if (speciality_count[count] > speciality_places[count]) { Matriculant.Enroll_by_score(abitur, i, speciality[count]); } else { Matriculant.Enroll_all(abitur, i, speciality[count]); } } Console.WriteLine("Enroll is over"); Console.WriteLine("Click any button... "); Console.ReadKey(); break; } case ConsoleKey.D5: { Console.Clear(); if (abitur[0] == null) { Console.WriteLine("Your list is empty!"); Console.WriteLine("Click any button... "); Console.ReadKey(); break; } Matriculant.Show_students(abitur, i); Console.WriteLine("Click any button..."); Console.ReadKey(); break; } case ConsoleKey.D6: { exit = 1; break; } default: { break; } } } }