Askor

Hw19

Jul 9th, 2020 (edited)
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.92 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Test
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string userInput;
  10.             string form = "";
  11.             string[] names = new string[0];
  12.             string[] jobs = new string[0];
  13.             bool isProgramActive = true;
  14.  
  15.             while (isProgramActive)
  16.             {
  17.                 Console.WriteLine("Заполнить досье - 1 | Показать список досье - 2 | Удалить досье - 3 | Поиск досье по фамилии - 4 | Выход - 5");
  18.                 userInput = Console.ReadLine();
  19.  
  20.                 switch (userInput)
  21.                 {
  22.                     case "1":
  23.                         AddForm(ref names, ref jobs);                        
  24.                         break;
  25.                     case "2":
  26.                         ShowForm(form, names, jobs);
  27.                         break;
  28.                     case "3":
  29.                         DeleteForm(ref names, ref jobs);
  30.                         break;
  31.                     case "4":
  32.                         SearchBySurName(names, jobs);
  33.                         break;
  34.                     case "5":
  35.                         isProgramActive = false;
  36.                         break;
  37.                 }
  38.  
  39.                 Console.WriteLine("\nНажмите любую клавишу для продолжения...");
  40.                 Console.ReadKey();
  41.                 Console.Clear();
  42.             }
  43.         }
  44.  
  45.         static string[] ReSize(ref string[] array, string userInput)
  46.         {
  47.             string[] tempArray = new string[array.Length + 1];
  48.             tempArray[tempArray.Length - 1] = userInput;
  49.  
  50.             for (int i = 0; i < array.Length; i++)
  51.             {
  52.                 tempArray[i] = array[i];
  53.             }
  54.  
  55.             array = tempArray;
  56.  
  57.             return array;
  58.         }
  59.  
  60.         static string[] ReSize(ref string[] array)
  61.         {
  62.             string[] tempArray = new string[array.Length - 1];
  63.  
  64.             for (int i = 0; i < tempArray.Length; i++)
  65.             {
  66.                 tempArray[i] = array[i];
  67.             }
  68.  
  69.             array = tempArray;
  70.  
  71.             return array;
  72.         }
  73.  
  74.         static void AddForm(ref string[] names, ref string[] jobs)
  75.         {
  76.             string name;
  77.             string job;
  78.  
  79.             Console.Write("Введите ФИО: ");
  80.             name = Console.ReadLine();
  81.  
  82.             Console.Write("Введите должность: ");
  83.             job = Console.ReadLine();
  84.  
  85.             ReSize(ref names, name);
  86.             ReSize(ref jobs, job);
  87.  
  88.             Console.WriteLine("\nДосье добавлено.");
  89.         }
  90.  
  91.         static void ShowForm(string form, string[] names, string[] jobs)
  92.         {
  93.  
  94.             for (int i = 0; i < names.Length; i++)
  95.             {
  96.                 form = (i + 1) + "." + names[i] + "-" + jobs[i];
  97.                 Console.WriteLine(form);
  98.             }
  99.         }
  100.  
  101.         static void DeleteForm(ref string[] names, ref string[] jobs)
  102.         {
  103.             int numberOfForm;
  104.             bool isFormFound = false;
  105.  
  106.             Console.Write("Введите номер досье для удаления: ");
  107.             numberOfForm = Convert.ToInt32(Console.ReadLine());
  108.  
  109.             for (int i = 0; i < names.Length; i++)
  110.             {
  111.                 if(numberOfForm == i + 1)
  112.                 {
  113.                     names[i] = names[names.Length - 1];
  114.                     jobs[i] = jobs[jobs.Length - 1];
  115.  
  116.                     isFormFound = true;
  117.                 }
  118.             }
  119.  
  120.             if (isFormFound)
  121.             {
  122.                 ReSize(ref names);
  123.                 ReSize(ref jobs);
  124.  
  125.                 Console.WriteLine($"\nДосье {numberOfForm} удалено.");
  126.             }
  127.             else
  128.             {
  129.                 Console.WriteLine("\nТакого досье нет.");
  130.             }
  131.         }
  132.  
  133.         static void SearchBySurName(string[] names, string[] jobs)
  134.         {
  135.             bool isFormFound = false;
  136.             string name;
  137.             string[] surName;
  138.  
  139.             Console.Write("Введите фамилию: ");
  140.             name = Console.ReadLine();
  141.  
  142.             for (int i = 0; i < names.Length; i++)
  143.             {
  144.                 surName = names[i].Split();
  145.  
  146.                 for (int j = 0; j < surName.Length; j++)
  147.                 {
  148.                     if (name.ToLower() == surName[j].ToLower())
  149.                     {
  150.                         name = $"{i + 1}.{names[i]} - {jobs[i]}";
  151.                         isFormFound = true;
  152.                         break;
  153.                     }
  154.                 }
  155.             }
  156.  
  157.             if (isFormFound)
  158.             {
  159.                 Console.WriteLine(name);
  160.             }
  161.             else
  162.             {
  163.                 Console.WriteLine("\nТакого досье нет.");
  164.             }
  165.         }
  166.     }
  167. }
Add Comment
Please, Sign In to add comment