SaNik74

Personnel accounting advanced

Apr 9th, 2023 (edited)
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.22 KB | None | 0 0
  1. internal class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         const string AddDossierCommand = "Add Dossier";
  6.         const string OutputAllDossierCommand = "Output all";
  7.         const string DeleteDossierCommand = "Delete";
  8.         const string ExitCommand = "Exit";
  9.  
  10.         List<string> fullNames = new List<string>();
  11.         List<string> jobTitles = new List<string>();
  12.         bool isWorking = true;
  13.  
  14.         while (isWorking)
  15.         {
  16.             string userInput;
  17.  
  18.             Console.WriteLine($"Введите: \n{AddDossierCommand} для добавления досье.\n{OutputAllDossierCommand} для вывода всех досье." +
  19.                 $"\n{DeleteDossierCommand} для удаления досье по ФИО.\n{ExitCommand} для выхода из программы.");
  20.             userInput = Console.ReadLine();
  21.  
  22.             switch (userInput)
  23.             {
  24.                 case AddDossierCommand:
  25.                     AddDossier(fullNames, jobTitles);
  26.                     break;
  27.  
  28.                 case OutputAllDossierCommand:
  29.                     OutputDossier(fullNames, jobTitles);
  30.                     break;
  31.  
  32.                 case DeleteDossierCommand:
  33.                     DeleteDossier(fullNames, jobTitles);
  34.                     break;
  35.                 case ExitCommand:
  36.                     Console.WriteLine("Вы вышли из программы.");
  37.                     isWorking = false;
  38.                     break;
  39.  
  40.                 default:
  41.                     Console.WriteLine("Неизвестная программа.");
  42.                     break;
  43.             }
  44.  
  45.             Console.ReadKey();
  46.             Console.Clear();
  47.         }
  48.     }
  49.  
  50.     static void AddDossier(List<string> fullNames, List<string> jobTitles)
  51.     {
  52.         Console.Write("Введите ФИО: ");
  53.         fullNames.Add(Console.ReadLine());
  54.         Console.WriteLine();
  55.         Console.Write("Введите должность: ");
  56.         jobTitles.Add(Console.ReadLine());
  57.     }
  58.  
  59.     static void OutputDossier(List<string> fullNames, List<string> jobTitles)
  60.     {
  61.         if (fullNames.Count == 0 && jobTitles.Count == 0)
  62.         {
  63.             Console.WriteLine("Список пуст.");
  64.         }
  65.         else
  66.         {
  67.             for (int i = 0; i < fullNames.Count; i++)
  68.             {
  69.                 Console.Write($"{fullNames[i]} {jobTitles[i]} - ");
  70.             }
  71.         }
  72.     }
  73.  
  74.     static void DeleteDossier(List<string> fullNames, List<string> jobTitles)
  75.     {
  76.         int indexForRemove;
  77.  
  78.         if (fullNames.Count == 0 && jobTitles.Count == 0)
  79.         {
  80.             Console.WriteLine("Список пуст.");
  81.             return;
  82.         }
  83.  
  84.         Console.Write("Введите ФИО для удаления досье:");
  85.         string fullName = Console.ReadLine();
  86.         indexForRemove = fullNames.BinarySearch(fullName);
  87.  
  88.         if (indexForRemove >= 0 && indexForRemove < fullNames.Count)
  89.         {
  90.             fullNames.RemoveAt(indexForRemove);
  91.             jobTitles.RemoveAt(indexForRemove);
  92.         }
  93.         else
  94.         {
  95.             Console.WriteLine("Досье с таким ФИО нет в базе.");
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment