Advertisement
Rodunskiy

Untitled

Feb 28th, 2025
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.26 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.             Console.WriteLine("Введите нужную фамилию для поиска");
  83.             string lastName = Console.ReadLine();
  84.  
  85.             Console.WriteLine($"Сотрудники с фамилией '{lastName}':");
  86.  
  87.             foreach (var worker in array)
  88.             {
  89.                 if (worker.StartsWith(lastName, StringComparison.OrdinalIgnoreCase))
  90.                 {
  91.                     Console.WriteLine(worker);
  92.                 }
  93.             }
  94.         }
  95.  
  96.         static void DeleteDossier(ref string[] listEmployees, ref string[] positions)
  97.         {
  98.             ShowAllDossier(listEmployees, positions);
  99.  
  100.             Console.WriteLine("Введите номер досье которое хотите удалить.");
  101.             int number = ReadInt();
  102.  
  103.             listEmployees = DeleteArrayElement(listEmployees, number);
  104.             positions = DeleteArrayElement(positions, number);
  105.         }
  106.  
  107.         static string[] ExpandArray(string[] array, string word)
  108.         {
  109.             string[] temporaryArray = new string[array.Length + 1];
  110.  
  111.             for (int i = 0; i < array.Length; i++)
  112.             {
  113.                 temporaryArray[i] = array[i];
  114.             }
  115.  
  116.             temporaryArray[temporaryArray.Length - 1] = word;
  117.  
  118.             array = temporaryArray;
  119.  
  120.             return array;
  121.         }
  122.  
  123.         static string[] DeleteArrayElement(string[] array, int number)
  124.         {
  125.             string[] temporaryArray = new string[array.Length - 1];
  126.  
  127.             //foreach (var item in array)
  128.             //{
  129.             //    if (item != dossier)
  130.             //    {
  131.             //        temporaryArray[index++] = item;
  132.             //    }
  133.             //}
  134.  
  135.             for (int i = 0; i < (number - 1); i++)
  136.             {
  137.                 temporaryArray[i] = array[i];
  138.             }
  139.  
  140.             for (int i = (number - 1); i < (temporaryArray.Length); i++)
  141.             {
  142.                 temporaryArray[i] = array[i + 1];
  143.             }
  144.  
  145.             array = temporaryArray;
  146.  
  147.             return array;
  148.         }
  149.  
  150.         static int ReadInt()
  151.         {
  152.             int number = 0;
  153.  
  154.             while (int.TryParse(Console.ReadLine(), out number) == false)
  155.             {
  156.                 Console.WriteLine("Это не число.");
  157.             }
  158.  
  159.             return number;
  160.         }
  161.     }
  162. }
  163.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement