Advertisement
Fle2x

Untitled

Apr 23rd, 2020
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.13 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Hr
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string[] fullName = { "Беляев Матвей Артёмович", "Блажевич Игорь Юрьевич", "Валиева Руфина Рафаэлевна", "Возвышаев Александр Андреевич", "Гриненко Алексей Алексеевич", "Жигляев Родион Алексеевич" };
  10.             string[] position = { "Event-менеджер", "SEO-оптимизатор", "SMM-менеджер", "Авиадиспетчер", "Адвокат", "Актер" };
  11.             bool exit = false;
  12.  
  13.             while (!exit)
  14.             {
  15.                 Console.WriteLine("Выберите пункт меню:\n1.Добавить досье\n2.Вывести все досье\n3.Удалить досье\n4.Поиск по фамилии\n5.Выход", '-');
  16.                 int menu = Convert.ToInt32(Console.ReadLine());
  17.                 Console.WriteLine();
  18.                 if (menu == 1)
  19.                 {
  20.                     AddFullNameAndPosition(ref fullName, ref position);
  21.                 }
  22.                 else if (menu == 2)
  23.                 {
  24.                     Console.WriteLine("Все досье: ");
  25.                     PrintFullNameAndPosition(fullName, position);
  26.                 }
  27.                 else if (menu == 3)
  28.                 {
  29.                     if (fullName.Length == 0)
  30.                     {
  31.                         Console.WriteLine("Нет записей.");
  32.                     }
  33.                     else
  34.                     {
  35.                         Console.WriteLine("Выберите досье,которое хотите удалить: ");
  36.                         RemoveFullNameAndPosition(ref fullName, ref position);
  37.                     }
  38.                 }
  39.                 else if (menu == 4)
  40.                 {
  41.                     Console.WriteLine("Напишите фамилию: ");
  42.                     SearchFullName(fullName, position);
  43.                 }
  44.                 else if (menu == 5)
  45.                 {
  46.                     exit = true;
  47.                 }
  48.                 else
  49.                 {
  50.                     Console.WriteLine("Нет такого пункта меню.");
  51.                 }
  52.             }
  53.             Console.ReadKey();
  54.         }
  55.  
  56.         static void AddFullNameAndPosition(ref string[] fullName, ref string[] position)
  57.         {
  58.             string[] tempFullName = new string[fullName.Length + 1];
  59.             string[] tempPosition = new string[position.Length + 1];
  60.  
  61.             Console.WriteLine("Введите ФИО: ");
  62.             string enterFullName = Console.ReadLine();
  63.             tempFullName[tempFullName.Length - 1] = enterFullName;
  64.  
  65.             Console.WriteLine("Введите должность: ");
  66.             string enterPosition = Console.ReadLine();
  67.             tempPosition[tempPosition.Length - 1] = enterPosition;
  68.  
  69.             SetValues(tempFullName, ref fullName, tempPosition, ref position);
  70.  
  71.  
  72.             Console.WriteLine();
  73.         }
  74.  
  75.         static void RemoveFullNameAndPosition(ref string[] fullName, ref string[] position)
  76.         {
  77.             string[] tempRemoveFullname = new string[fullName.Length - 1];
  78.             string[] tempRemovePosition = new string[position.Length - 1];
  79.             PrintFullNameAndPosition(fullName, position);
  80.             int id = Convert.ToInt32(Console.ReadLine());
  81.             Console.WriteLine();
  82.             if (tempRemoveFullname.Length >= id)
  83.             {
  84.                 ProcessFullNameAndposition(tempRemoveFullname, ref fullName, tempRemovePosition, ref position, id);
  85.                 Console.WriteLine($"Вы удалили досье под номером - {id}");
  86.             }
  87.             else
  88.             {
  89.                 Console.WriteLine($"Досье под номером {id} не существует.");
  90.             }
  91.             Console.WriteLine();
  92.         }
  93.  
  94.         static void SetValues(string[] tempFullName, ref string[] fullName, string[] tempPosition, ref string[] position)
  95.         {
  96.             for (int i = 0; i < fullName.Length; i++)
  97.             {
  98.                 tempFullName[i] = fullName[i];
  99.                 tempPosition[i] = position[i];
  100.             }
  101.             fullName = tempFullName;
  102.             position = tempPosition;
  103.         }
  104.  
  105.         static void ProcessFullNameAndposition(string[] tempFullName, ref string[] fullName, string[] tempPosition, ref string[] position, int id)
  106.         {
  107.             for (int i = 0; i < tempFullName.Length; i++)
  108.             {
  109.                 if (i < id)
  110.                 {
  111.                     tempFullName[i] = fullName[i];
  112.                     tempPosition[i] = position[i];
  113.                 }
  114.                 else
  115.                 {
  116.                     tempFullName[i] = fullName[i + 1];
  117.                     tempPosition[i] = position[i + 1];
  118.                 }
  119.             }
  120.             fullName = tempFullName;
  121.             position = tempPosition;
  122.         }
  123.  
  124.         static void PrintFullNameAndPosition(string[] fullName, string[] position)
  125.         {
  126.             for (int i = 0; i < fullName.Length; i++)
  127.             {
  128.                 Console.WriteLine($"{i}. {fullName[i]} - {position[i]}");
  129.             }
  130.             Console.WriteLine();
  131.         }
  132.  
  133.         static void SearchFullName(string[] fullName, string[] position)
  134.         {
  135.             string searchFullName = Console.ReadLine();
  136.             bool isFind = false;
  137.             for (int i = 0; i < fullName.Length; i++)
  138.             {
  139.                 if (fullName[i].ToLower() == searchFullName.ToLower())
  140.                 {
  141.                     Console.WriteLine($"Результат поиска {searchFullName} :");
  142.                     Console.WriteLine($"{fullName[i]} - {position[i]}");
  143.                     isFind = true;
  144.                 }
  145.             }
  146.             if (isFind == false)
  147.             {
  148.                 Console.WriteLine("По вашему запросу ничего не найдено.");
  149.             }
  150.             Console.WriteLine();
  151.         }
  152.  
  153.     }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement