Advertisement
TravaMan

Basic_Task16

Dec 13th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.65 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Basic_Task16
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string inputMenu = null;
  10.             string[] fios = new string[0];
  11.             string[] positions = new string[0];
  12.             while (inputMenu != "0")
  13.             {
  14.                 Console.WriteLine("Меню:");
  15.                 Console.WriteLine("1.Добавить досье");
  16.                 Console.WriteLine("2.Вывести все досье");
  17.                 Console.WriteLine("3.Удалить досье");
  18.                 Console.WriteLine("4.Поиск по фамилии");
  19.                 Console.WriteLine("0.Выход");
  20.                 inputMenu = Console.ReadLine();
  21.                 switch (inputMenu)
  22.                 {
  23.                     case "1":
  24.                         {
  25.                             string fio;
  26.  
  27.                             Console.WriteLine("Введите имя");
  28.                             fio = Console.ReadLine();
  29.                             Console.WriteLine("Введите фамилию");
  30.                             fio += " " + Console.ReadLine();
  31.                             Console.WriteLine("Введите отчество");
  32.                             fio += " " + Console.ReadLine();
  33.  
  34.                             Console.WriteLine("Введите его должность");
  35.                             string position = Console.ReadLine();
  36.  
  37.                             AddDosier(ref fios, ref positions, fio, position);
  38.                             break;
  39.                         }
  40.                     case "2":
  41.                         {
  42.                             WriteAllDosier(fios, positions);
  43.                             break;
  44.                         }
  45.                     case "3":
  46.                         {
  47.                             Console.WriteLine("Введите порядковый номер досье, которое удалить");
  48.                             string pos = Console.ReadLine();
  49.  
  50.                             RemoveDosier(ref fios, ref positions, int.Parse(pos) - 1);
  51.  
  52.                             break;
  53.                         }
  54.                     case "4":
  55.                         {
  56.                             Console.WriteLine("Введите фамилию");
  57.                             string lastname = Console.ReadLine();
  58.  
  59.                             SearchByLastName(fios, positions, lastname);
  60.  
  61.                             break;
  62.                         }
  63.                     case "0":
  64.                         {
  65.                             break;
  66.                         }
  67.                 }
  68.             }
  69.         }
  70.  
  71.         static void AddDosier(ref string[] fios, ref string[] positions, string fio, string position)
  72.         {
  73.             string[] tempFios = new string[fios.Length + 1];
  74.             string[] tempPositions = new string[positions.Length + 1];
  75.  
  76.             for (int i = 0; i < fios.Length; i++)
  77.             {
  78.                 tempFios[i] = fios[i];
  79.                 tempPositions[i] = positions[i];
  80.             }
  81.             tempFios[tempFios.Length - 1] = fio;
  82.             tempPositions[tempPositions.Length - 1] = position;
  83.  
  84.             fios = tempFios;
  85.             positions = tempPositions;
  86.         }
  87.  
  88.         static void WriteAllDosier(string[] fios, string[] positions)
  89.         {
  90.             for (int i = 0; i < fios.Length; i++)
  91.             {
  92.                 Console.WriteLine($"{i+1}. {fios[i]} - {positions[i]}");
  93.             }
  94.         }
  95.  
  96.         static void RemoveDosier(ref string[] fios, ref string[] positions, int pos)
  97.         {
  98.             if (fios.Length != 0 && pos >= 0 && pos < fios.Length)
  99.             {
  100.                 string[] tempFios = new string[fios.Length - 1];
  101.                 string[] tempPositions = new string[positions.Length - 1];
  102.  
  103.                 for (int i = 0; i < fios.Length - 1; i++)
  104.                 {
  105.                     if (i != pos)
  106.                     {
  107.                         tempFios[i] = fios[i];
  108.                         tempPositions[i] = positions[i];
  109.                     } else
  110.                     {
  111.                         i--;
  112.                     }
  113.                 }
  114.                 fios = tempFios;
  115.                 positions = tempPositions;
  116.             }
  117.         }
  118.  
  119.         static void SearchByLastName(string[] fios, string[] positions, string lastName)
  120.         {
  121.             for (int i = 0; i < fios.Length; i++)
  122.             {
  123.                 if (fios[i].Contains(lastName))
  124.                 {
  125.                     Console.WriteLine($"{i}. {fios[i]} - {positions[i]}");
  126.                 }
  127.             }
  128.         }
  129.     }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement