Advertisement
loleckek228

4.1

Sep 11th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.55 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _4._1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string[] workers = new string[0];
  10.             string[] positions = new string[0];
  11.            
  12.             int countWorkers = 0;
  13.             int countPositions = 0;
  14.  
  15.             while (true)
  16.             {
  17.                 //Console.Clear();
  18.                 Console.WriteLine(">Добавить досье");
  19.                 Console.WriteLine(">Поиск сотрудника");
  20.                 Console.WriteLine(">Вывести все досье");
  21.                 Console.WriteLine(">Удалить досье");
  22.                 Console.WriteLine(">Выход");
  23.  
  24.                 string operation = Console.ReadLine();
  25.  
  26.                 switch (operation)
  27.                 {
  28.                     case "Добавить досье":                        
  29.                         Console.Clear();
  30.                         Console.WriteLine("Добавления сотрудников в досье");
  31.                         Console.WriteLine("Введите ФИО сотрудника: ");
  32.                         string worker = Console.ReadLine();
  33.                         Console.WriteLine("Введите должность сотрудника: ");
  34.                         string position = Console.ReadLine();
  35.  
  36.                         add(ref workers, countWorkers, worker);
  37.                         countWorkers++;
  38.  
  39.                         add(ref positions, countPositions, position);
  40.                         countPositions++;
  41.                         Console.Clear();
  42.                         break;
  43.  
  44.                     case "Поиск сотрудника":
  45.                        
  46.                         Console.Clear();
  47.                         Console.WriteLine("Поиск сотрудников по фамилии");
  48.                         Console.WriteLine("Введите фамилию сотрудника");
  49.                         string lastName = Console.ReadLine();
  50.                        
  51.                         for (int i = 0; i < workers.Length; i++)
  52.                         {
  53.                             string [] splitWorkers = workers[i].Split(" ");
  54.                             for (int j = 0; j < splitWorkers.Length; j+= 3)
  55.                             {
  56.                                 if (lastName.Equals(splitWorkers[j]))
  57.                                 {
  58.                                     Console.WriteLine(workers[i]
  59.                                         + "-" + positions[i]);
  60.                                     break;
  61.                                 }                                
  62.                             }                          
  63.                         }                      
  64.                         break;
  65.  
  66.                     case "Вывести все досье":
  67.                         Console.Clear();
  68.                         Console.Clear();
  69.                         if (countWorkers != 0)
  70.                         {
  71.                             for (int i = 0; i < workers.Length; i++)
  72.                             {
  73.                                 Console.WriteLine(i + 1 + ") " + workers[i] + " - "
  74.                                     + positions[i]);
  75.                             }
  76.                         }
  77.                         else
  78.                         {
  79.                             Console.WriteLine("В досье нет сотрудников");
  80.                         }
  81.                         break;
  82.  
  83.                     case "Удалить досье":                        
  84.                         Console.Clear();
  85.                         if (countWorkers != 0)
  86.                         {
  87.                             Console.WriteLine("Удаления сотрудника из досье");
  88.                             for (int i = 0; i < workers.Length; i++)
  89.                             {
  90.                                 Console.WriteLine(i + 1 + ") " + workers[i] + " - "
  91.                                     + positions[i]);
  92.                             }
  93.                             Console.WriteLine("Введите ФИО сотрудника: ");
  94.                             int indexRemoveWorker = -1;
  95.                             string removeWorker = Console.ReadLine();
  96.  
  97.                             for (int i = 0; i < workers.Length; i++)
  98.                             {
  99.                                 if (removeWorker.Equals(workers[i]))
  100.                                 {
  101.                                     indexRemoveWorker = i;
  102.                                 }                                
  103.                             }
  104.  
  105.                             if (indexRemoveWorker != -1)
  106.                             {
  107.                                 remove(ref workers, indexRemoveWorker);
  108.                                 countWorkers--;
  109.                                 remove(ref positions, indexRemoveWorker);
  110.                                 countPositions--;
  111.                                 Console.Clear();                                
  112.                                 Console.WriteLine("Досье удалено");
  113.                             }
  114.                             else
  115.                             {
  116.                                 Console.WriteLine("Ошибка ввода");
  117.                             }
  118.                         }
  119.                         else
  120.                         {
  121.                             Console.WriteLine("В досье нет сотрудников");
  122.                         }
  123.  
  124.                         break;
  125.  
  126.                     case "Выход":
  127.                         Console.Clear();
  128.                         Environment.Exit(0);
  129.                         break;
  130.                 }                
  131.             }          
  132.         }
  133.  
  134.         static void add(ref string[] array, int count, string value)
  135.         {
  136.             string[] newArray = new string[array.Length + 1];
  137.  
  138.             for (int i = 0; i < array.Length; i++)
  139.             {
  140.                 newArray[i] = array[i];
  141.             }
  142.             newArray[count] = value;
  143.             array = newArray;            
  144.         }
  145.  
  146.         static void remove(ref string[] array, int index)
  147.         {
  148.             string[] newArray = new string[array.Length - 1];
  149.             int count = 0;
  150.             for (int i = 0; i < array.Length; i++)
  151.             {
  152.                 if (index == i) continue;
  153.                 newArray[count] = array[i];
  154.                 count++;
  155.             }
  156.             array = newArray;
  157.         }        
  158.     }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement