Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal class Program
- {
- static void Main(string[] args)
- {
- const string AddDossierCommand = "Add Dossier";
- const string OutputAllDossierCommand = "Output all";
- const string DeleteDossierCommand = "Delete";
- const string ExitCommand = "Exit";
- List<string> fullNames = new List<string>();
- List<string> jobTitles = new List<string>();
- bool isWorking = true;
- while (isWorking)
- {
- string userInput;
- Console.WriteLine($"Введите: \n{AddDossierCommand} для добавления досье.\n{OutputAllDossierCommand} для вывода всех досье." +
- $"\n{DeleteDossierCommand} для удаления досье по ФИО.\n{ExitCommand} для выхода из программы.");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case AddDossierCommand:
- AddDossier(fullNames, jobTitles);
- break;
- case OutputAllDossierCommand:
- OutputDossier(fullNames, jobTitles);
- break;
- case DeleteDossierCommand:
- DeleteDossier(fullNames, jobTitles);
- break;
- case ExitCommand:
- Console.WriteLine("Вы вышли из программы.");
- isWorking = false;
- break;
- default:
- Console.WriteLine("Неизвестная программа.");
- break;
- }
- Console.ReadKey();
- Console.Clear();
- }
- }
- static void AddDossier(List<string> fullNames, List<string> jobTitles)
- {
- Console.Write("Введите ФИО: ");
- fullNames.Add(Console.ReadLine());
- Console.WriteLine();
- Console.Write("Введите должность: ");
- jobTitles.Add(Console.ReadLine());
- }
- static void OutputDossier(List<string> fullNames, List<string> jobTitles)
- {
- if (fullNames.Count == 0 && jobTitles.Count == 0)
- {
- Console.WriteLine("Список пуст.");
- }
- else
- {
- for (int i = 0; i < fullNames.Count; i++)
- {
- Console.Write($"{fullNames[i]} {jobTitles[i]} - ");
- }
- }
- }
- static void DeleteDossier(List<string> fullNames, List<string> jobTitles)
- {
- int indexForRemove;
- if (fullNames.Count == 0 && jobTitles.Count == 0)
- {
- Console.WriteLine("Список пуст.");
- return;
- }
- Console.Write("Введите ФИО для удаления досье:");
- string fullName = Console.ReadLine();
- indexForRemove = fullNames.BinarySearch(fullName);
- if (indexForRemove >= 0 && indexForRemove < fullNames.Count)
- {
- fullNames.RemoveAt(indexForRemove);
- jobTitles.RemoveAt(indexForRemove);
- }
- else
- {
- Console.WriteLine("Досье с таким ФИО нет в базе.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment