Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace kadry_huyadry
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] names = new string[0];
- string[] position = new string[0];
- bool quitRequest = false;
- while (quitRequest != true)
- {
- Console.WriteLine("Меню:\n1.Добавить досье\n2.Вывести все досье\n3.Удалить досье\n4.Поиск по фамилии\n5.Выход");
- int input = Convert.ToInt32(Console.ReadLine());
- switch (input)
- {
- case 1:
- Console.WriteLine("Введите фамилию:");
- string newName = Console.ReadLine();
- Console.WriteLine("Введите должность:");
- string newPosition = Console.ReadLine();
- names = AddFile(names, newName);
- position = AddFile(position, newPosition);
- Console.Clear();
- break;
- case 2:
- Console.Clear();
- Output(names, position);
- Console.ReadKey();
- Console.Clear();
- break;
- case 3:
- Console.Clear();
- Console.WriteLine("Введите номер досье, которое Вы хотите удалить:");
- int fileNum = Convert.ToInt32(Console.ReadLine());
- names = DelFile(names, fileNum);
- position = DelFile(position, fileNum);
- break;
- case 4:
- Console.Clear();
- int searchNum = SearchFile(names);
- if (searchNum >= 0)
- {
- Console.WriteLine("Его должность: " + position[searchNum]);
- }
- Console.ReadKey();
- Console.Clear();
- break;
- case 5:
- quitRequest = true;
- Console.Clear();
- Console.WriteLine("Завершение работы программы...");
- break;
- }
- }
- }
- static string[] AddFile(string[] arr, string newFile)
- {
- string[] tempArr = new string[arr.Length + 1];
- for (int i = 0; i < arr.Length; i++)
- {
- tempArr[i] = arr[i];
- }
- tempArr[tempArr.Length - 1] = newFile;
- arr = tempArr;
- return arr;
- }
- static void Output(string[] names, string[] position)
- {
- for (int i = 0; i < names.Length; i++)
- {
- Console.WriteLine($"{i + 1}.{ names[i]} - { position[i]}");
- }
- }
- static string[] DelFile(string[] names, int fileNum)
- {
- names[fileNum - 1] = names[names.Length - 1];
- Array.Resize(ref names, names.Length - 1);
- return names;
- }
- static int SearchFile(string[] names)
- {
- Console.WriteLine("Введите фамилию для поиска:");
- int fileFound = -1;
- string surname;
- surname = Convert.ToString(Console.ReadLine());
- for (int i = 0; i < names.Length; i++)
- {
- if (surname.ToLower() == names[i].ToLower())
- {
- Console.WriteLine($"Мистер - {names[i]}\nНомер его досье - {i + 1}");
- fileFound = i;
- }
- else
- {
- Console.WriteLine("Досье не найдено!");
- }
- }
- return fileFound;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement