Advertisement
Guest User

Ex4.1

a guest
Oct 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.57 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Ex4._1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string[] name = new string[3] { "Агатов Агатий Агатович", "Иванов Иван Иванович", "Аноним Лидия Петровна" };
  10.             string[] position = new string[3] { "Сантехник", "Глашатай", "Кассир" };
  11.  
  12.             bool work = true;
  13.             while (work)
  14.             {
  15.                 Console.Clear();
  16.                 Console.WriteLine("\n 1 - добавить досье;" +
  17.                     "\n 2 - вывести все досье;" +
  18.                     "\n 3 - удалить досье;" +
  19.                     "\n 4 - выход;" +
  20.                     "\n 5 - поиск по фамилии;");
  21.  
  22.                 switch (Convert.ToInt32(Console.ReadLine()))
  23.                 {
  24.                     case 1:
  25.                         AddMan(ref name, ref position);
  26.                         break;
  27.  
  28.                     case 2:
  29.                         PrintAllMan(name, position);
  30.                         break;
  31.  
  32.                     case 3:
  33.                         DeleteMan(ref name, ref position);
  34.                         break;
  35.  
  36.                     case 4:
  37.                         work = false;
  38.                         break;
  39.                     case 5:
  40.                         Found(name, position);
  41.                         break;
  42.                 }
  43.             }
  44.         }
  45.  
  46.         static void Found(string[]name,string[] position)
  47.         {
  48.             Console.Write("Введите фамилию: ");
  49.             string foundName = Console.ReadLine();
  50.  
  51.             int foundindex = FoundMan(name, foundName);
  52.  
  53.             if(foundindex!=-1)
  54.             {
  55.                 Console.WriteLine("Найдено: ");
  56.                 PrintMan(name, position, foundindex);
  57.             }
  58.             else
  59.                 Console.WriteLine("Досье с такой фамилией не найдено!");
  60.  
  61.             Console.WriteLine("Нажмите любую клавишу, для продолжения:");
  62.             Console.ReadKey();
  63.         }
  64.  
  65.         /// <summary>
  66.         /// Поиск досье по фамилии
  67.         /// </summary>
  68.         /// <param name="name">The name.</param>
  69.         /// <param name="position">The position.</param>
  70.         /// <param name="found">The found.</param>
  71.         /// <returns></returns>
  72.         static int FoundMan(string[] name, string found)
  73.         {
  74.             for (int i = 0; i < name.Length; i++)
  75.                 if (found.CompareTo(name[i].Split(' ')[0]) == 0)
  76.                     return i;
  77.  
  78.             return -1;
  79.         }
  80.  
  81.         /// <summary>
  82.         /// Функция добавления досье
  83.         /// </summary>
  84.         /// <param name="name">ФИО</param>
  85.         /// <param name="position">Должность</param>
  86.         static void AddMan(ref string[] name, ref string[] position)
  87.         {
  88.             string[] temp1 = name;
  89.             name = new string[temp1.Length + 1];
  90.  
  91.             string[] temp2 = position;
  92.             position = new string[temp2.Length + 1];
  93.  
  94.             for (int i = 0; i < temp1.Length; i++)
  95.             {
  96.                 name[i] = temp1[i];
  97.                 position[i] = temp2[i];
  98.             }
  99.  
  100.             Console.Write("Введите Фамилию: ");
  101.             string newName = Console.ReadLine() + " ";
  102.  
  103.             Console.Write("Введите Имя: ");
  104.             newName += Console.ReadLine() + " ";
  105.  
  106.             Console.Write("Введите Отчество: ");
  107.             newName += Console.ReadLine() + " ";
  108.  
  109.             name[name.Length - 1] = newName;
  110.  
  111.             Console.Write("Введите должность: ");
  112.             position[position.Length - 1] = Console.ReadLine();
  113.  
  114.         }
  115.  
  116.         /// <summary>
  117.         /// Функция выбора номера досье, которое надо удалить
  118.         /// </summary>
  119.         /// <param name="name"></param>
  120.         /// <param name="position"></param>
  121.         static void DeleteMan(ref string[] name, ref string[] position)
  122.         {
  123.             int index;
  124.             Console.WriteLine($"Введите номер досье, которое надо удалить. Всего досье: {name.Length}");
  125.             do
  126.             {
  127.                 index = Convert.ToInt32(Console.ReadLine());
  128.             } while (index < 1 || index > name.Length);
  129.  
  130.             DeleteMan(ref name, ref position, index);
  131.         }
  132.  
  133.         /// <summary>
  134.         /// Функция удаления досье под номером <paramref name="indexDelete"/>
  135.         /// </summary>
  136.         /// <param name="name">ФИО</param>
  137.         /// <param name="position">должность</param>
  138.         /// <param name="indexDelete">Номер должности, что надо удалить</param>
  139.         static void DeleteMan(ref string[] name, ref string[] position, int indexDelete)
  140.         {
  141.             string[] temp1 = name;
  142.             name = new string[temp1.Length - 1];
  143.  
  144.             string[] temp2 = position;
  145.             position = new string[temp2.Length - 1];
  146.  
  147.             int temp = 0;
  148.             for (int i = 0; i < temp1.Length; i++)
  149.             {
  150.                 if (i != indexDelete - 1)
  151.                 {
  152.                     name[temp] = temp1[i];
  153.                     position[temp] = temp2[i];
  154.  
  155.                     temp++;
  156.                 }
  157.             }
  158.         }
  159.  
  160.         /// <summary>
  161.         /// Вывод дасье человека по номеру <paramref name="index"/>
  162.         /// </summary>
  163.         /// <param name="name">The name.</param>
  164.         /// <param name="position">The position.</param>
  165.         /// <param name="index">The index.</param>
  166.         static void PrintMan(string[] name, string[] position, int index)
  167.         {
  168.             Console.WriteLine($"{(index + 1)} - {name[index]} - {position[index]}");
  169.         }
  170.  
  171.         /// <summary>
  172.         /// Выводит на печать все досье
  173.         /// </summary>
  174.         /// <param name="name">ФИО</param>
  175.         /// <param name="position">должность</param>
  176.         static void PrintAllMan(string[] name, string[] position)
  177.         {
  178.             for (int i = 0; i < name.Length; i++)
  179.             {
  180.                 PrintMan(name, position, i);
  181.             }
  182.             Console.WriteLine("Нажмите любую клавишу, для продолжения:");
  183.             Console.ReadKey();
  184.         }
  185.     }
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement