Advertisement
Rodunskiy

Untitled

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