static void Part2() { Dictionary <int, MyClassLibrary10.Person> collection = new Dictionary <int, MyClassLibrary10.Person>(1); do { Console.WriteLine("1.Создать"); Console.WriteLine("2.Добавить элемент в конец"); Console.WriteLine("3.Удалить элемент"); Console.WriteLine("4.Вывод на экран"); Console.WriteLine("5.Количество рабочих"); Console.WriteLine("6.Количество инженеров заданной квалификации"); Console.WriteLine("7.Клонирование"); Console.WriteLine("8.Поиск"); Console.WriteLine("0.Назад"); int oper = int.Parse(Console.ReadLine()); if (oper == 0) { break; } switch (oper) { case 1: { Console.WriteLine("Словарь из 6 элементов создан\n"); collection.Add(1, new MyClassLibrary10.Employee() { Name = "Григорий Першин", Age = 35, Experience = 12 }); collection.Add(2, new MyClassLibrary10.Employee() { Name = "Паластрова Нина", Age = 46, Experience = 25 }); collection.Add(3, new MyClassLibrary10.Worker() { Name = "Лазарева Лариса", Age = 21, Experience = 1, WorkPlace = "ОАО Мотовилихинские заводы" }); collection.Add(4, new MyClassLibrary10.Worker() { Name = "Шаклеин Никита", Age = 20, Experience = 2, WorkPlace = "КамКабель" }); collection.Add(5, new MyClassLibrary10.Engneer() { Name = "Катаев Евгений", Age = 31, Experience = 8, Qualification = "вторая" }); collection.Add(6, new MyClassLibrary10.Engneer() { Name = "Поляков Cвятослав", Age = 53, Experience = 30, Qualification = "высшая" }); break; } case 2: { Add(ref collection); break; } case 3: { if (collection.Count > 0) { Delete(ref collection); } else { Console.WriteLine("Словарь пуст"); } break; } case 4: { Print(collection); break; } case 5: { CountOfWorkers(collection); break; } case 6: { CountOfEngeneer(collection); break; } case 7: { Console.WriteLine("\nДемонстрация клонирования"); Console.ForegroundColor = ConsoleColor.White; MyClassLibrary10.Employee obj = new MyClassLibrary10.Employee("Паластрова Нина", 46, 25); MyClassLibrary10.Employee copy = (MyClassLibrary10.Employee)obj.Clone(); Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Результат клонирования:"); Console.ForegroundColor = ConsoleColor.White; copy.PrintInfo(); break; } case 8: { bool index = true; MyClassLibrary10.Engneer findEng = new MyClassLibrary10.Engneer("Катаев Евгений", 31, 8, "вторая"); Console.WriteLine("Введите номер элемента"); index = collection.ContainsValue(findEng); if (!index) { Console.WriteLine("Элемент не найден"); } else { Console.WriteLine($"Элемент найден"); } break; } default: break; } }while (true); }
static void Part1() { List <MyClassLibrary10.Person> list = new List <MyClassLibrary10.Person>(1); list.Add(new MyClassLibrary10.Employee() { Name = "Григорий", Age = 35, Experience = 12 }); list.Add(new MyClassLibrary10.Employee() { Name = "Нина", Age = 46, Experience = 25 }); list.Add(new MyClassLibrary10.Worker() { Name = "Лариса", Age = 21, Experience = 1, WorkPlace = "ОАО Мотовилихинские заводы" }); list.Add(new MyClassLibrary10.Worker() { Name = "Никита", Age = 20, Experience = 2, WorkPlace = "КамКабель" }); list.Add(new MyClassLibrary10.Engneer() { Name = "Евгений", Age = 31, Experience = 8, Qualification = "вторая" }); list.Add(new MyClassLibrary10.Engneer() { Name = "Святослав", Age = 53, Experience = 30, Qualification = "высшая" }); Console.WriteLine("Список создан"); Menu(ref list); Console.ForegroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Выбирите запрос:"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("2.Количество объектов класса Worker "); Console.WriteLine("3.Количество инженеров с заданной квалификацией"); Console.WriteLine("4.Имена служащих со стажем не менее заданного"); Console.WriteLine("Введите номер запроса или \"exit\" для перехода к следующим действиям"); string s1 = ""; try { s1 = Console.ReadLine(); while (s1 != "exit") { int number = Convert.ToInt32(s1); if (number == 2) { CountOfWorkers(list); } if (number == 3) { CountOfEngeneer(list); } if (number == 4) { CountOfEmployees(list); } Console.WriteLine("Введите номер запроса или \"exit\" для перехода к следующим действиям"); s1 = Console.ReadLine(); } } catch (FormatException) { Console.WriteLine("Номер введен неверно"); } Console.WriteLine("\nДемонстрация клонирования"); Console.ForegroundColor = ConsoleColor.White; MyClassLibrary10.Employee obj = new MyClassLibrary10.Employee("Паластрова Нина Васильевна", 46, 25); MyClassLibrary10.Employee copy = (MyClassLibrary10.Employee)obj.Clone(); Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Результат клонирования:"); Console.ForegroundColor = ConsoleColor.White; copy.PrintInfo(); Console.WriteLine("Сортировка по стажу"); Console.WriteLine("До сортировки"); Print(list); Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ "); Console.ForegroundColor = ConsoleColor.White; list.Sort(); Print(list); Console.WriteLine("Поиск элемента"); MyClassLibrary10.Engneer findEng = new MyClassLibrary10.Engneer("Катаев Евгений", 31, 8, "вторая"); int index = -1; index = list.BinarySearch(findEng); findEng.PrintInfo(); if (index == -1) { Console.WriteLine("Элемент не найден"); } else { Console.WriteLine($"Элемент найден на позиции {index}"); } }