Advertisement
Rodunskiy

Untitled

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