Advertisement
Rodunskiy

Untitled

Feb 28th, 2025
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.05 KB | None | 0 0
  1. namespace CSLight
  2. {
  3.     public class Program
  4.     {
  5.         private static object cw;
  6.  
  7.         static void Main(string[] args)
  8.         {
  9.             string[] listEmployees = new string[0];
  10.             string[] positions = new string[0];
  11.             bool canWork = true;  
  12.  
  13.             const string FillingDossierCommand = "1";
  14.             const string ShowAllDossierCommand = "2";
  15.             const string SearchLastnameCommand = "3";
  16.             const string DeleteDossierCommand = "4";
  17.             const string ExitProgrammCommand = "5";
  18.  
  19.             while (canWork)
  20.             {
  21.                 Console.WriteLine(
  22.                 $"{FillingDossierCommand})Добавить досье\n" +
  23.                 $"{ShowAllDossierCommand})Вывести все досье\n" +
  24.                 $"{SearchLastnameCommand})Поиск по фамилии\n" +
  25.                 $"{DeleteDossierCommand})Удалить досье\n" +
  26.                 $"{ExitProgrammCommand})Выход из программы\n");
  27.  
  28.                 switch (Console.ReadLine())
  29.                 {
  30.                     case FillingDossierCommand:
  31.                         FillDossier(ref listEmployees, ref positions);
  32.                         break;
  33.  
  34.                     case ShowAllDossierCommand:
  35.                         ShowAllDossier(listEmployees, positions);
  36.                         break;
  37.  
  38.                     case SearchLastnameCommand:
  39.                         SearchLastname(listEmployees);
  40.                         break;
  41.  
  42.                     case DeleteDossierCommand:
  43.                         DeleteDossier(ref listEmployees, ref positions);
  44.                         break;
  45.  
  46.                     case ExitProgrammCommand:
  47.                         canWork = false;
  48.                         break;
  49.                 }
  50.  
  51.             }
  52.  
  53.         }
  54.  
  55.         static void FillDossier(ref string[] listEmployees, ref string[] positions)
  56.         {
  57.             Console.WriteLine("Введите ФИО сотрудинка через пробел.");
  58.             string fullName = Console.ReadLine();
  59.             Console.WriteLine("Введите должность сотрудинка через пробел.");
  60.             string post = Console.ReadLine();
  61.  
  62.             listEmployees = ExpandArray(listEmployees, fullName);
  63.             positions = ExpandArray(positions, post);
  64.         }
  65.          
  66.         static void ShowAllDossier(string[] listEmployees, string[] positions)
  67.         {
  68.             if (listEmployees.Length == 0)
  69.             {
  70.                 Console.WriteLine("Досье отсутствуют.");
  71.                 return;
  72.             }
  73.  
  74.             for (int i = 0; i < listEmployees.Length; i++)
  75.             {
  76.                 Console.WriteLine($"{i + 1}){listEmployees[i]}-{positions[i]}");
  77.             }
  78.            
  79.             Console.ReadKey();
  80.         }
  81.  
  82.         static void SearchLastname(string[] array)
  83.         {
  84.             Console.WriteLine("Введите нужную фамилию для поиска");
  85.             string lastName = Console.ReadLine();
  86.  
  87.             Console.WriteLine($"Сотрудники с фамилией '{lastName}':");
  88.  
  89.             foreach (var worker in array)
  90.             {
  91.                 if (worker.StartsWith(lastName, StringComparison.OrdinalIgnoreCase))
  92.                 {
  93.                     Console.WriteLine(worker);
  94.                 }
  95.             }
  96.         }
  97.  
  98.         static void DeleteDossier(ref string[] listEmployees, ref string[] positions)
  99.         {
  100.             ShowAllDossier(listEmployees, positions);
  101.  
  102.             Console.WriteLine("Введите номер досье которое хотите удалить.");
  103.             int number = ReadInt();
  104.  
  105.             listEmployees = DeleteArrayElement(listEmployees, number);
  106.             positions = DeleteArrayElement(positions, number);
  107.         }
  108.  
  109.         static string[] ExpandArray(string[] array, string word)
  110.         {
  111.             string[] temporaryArray = new string[array.Length + 1];
  112.  
  113.             for (int i = 0; i < array.Length; i++)
  114.             {
  115.                 temporaryArray[i] = array[i];
  116.             }
  117.  
  118.             temporaryArray[temporaryArray.Length - 1] = word;
  119.  
  120.             array = temporaryArray;
  121.  
  122.             return array;
  123.         }
  124.  
  125.         static string[] DeleteArrayElement(string[] array, int number)
  126.         {
  127.             string[] temporaryArray = new string[array.Length - 1];
  128.             string dossier = array[number - 1];
  129.             int index = 0;
  130.  
  131.             foreach (var item in array)
  132.             {
  133.                 if (item != dossier)
  134.                 {
  135.                     temporaryArray[index++] = item;
  136.                 }
  137.             }
  138.  
  139.             array = temporaryArray;
  140.  
  141.             return array;
  142.         }
  143.  
  144.         static int ReadInt()
  145.         {
  146.             int number = 0;
  147.  
  148.             while (int.TryParse(Console.ReadLine(), out number) == false)
  149.             {
  150.                 Console.WriteLine("Это не число.");
  151.             }
  152.  
  153.             return number;
  154.         }
  155.     }
  156. }
  157.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement