kwest87

Untitled

Apr 12th, 2022
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.98 KB | None | 0 0
  1. [StartCode]
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApp11
  9. {
  10.     internal class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string[] fullNames = new string[0];
  15.             string[] positions = new string[0];
  16.             string menuOption;
  17.             bool exit = false;
  18.  
  19.             while (exit == false)
  20.             {
  21.                 Console.WriteLine("        МЕНЮ");
  22.                 Console.WriteLine();
  23.                 Console.WriteLine("1 - Добавить досье.\n2 - Список досье.\n3 - Удалить досье.\n4 - Поиск по фамилии.\n5 - Выход.");
  24.                 menuOption = Console.ReadLine();
  25.  
  26.                 switch (menuOption)
  27.                 {
  28.                     case "1":
  29.                         AddElements(ref fullNames, ref positions);
  30.                         break;
  31.                     case "2":
  32.                         ShowLists(fullNames, positions, "Список досье :");
  33.                         break;
  34.                     case "3":
  35.                         DeleteDossier(ref fullNames, ref positions);
  36.                         break;
  37.                     case "4":
  38.                         SearchSurname(fullNames, positions);
  39.                         break;
  40.                     case "5":
  41.                         exit = true;
  42.                         break;
  43.                 }
  44.             }
  45.         }
  46.  
  47.         static void AddElements(ref string[] fullNames, ref string[] positions)
  48.         {
  49.             AddElement(ref fullNames,"Добавить ФИО :");
  50.             AddElement(ref positions,"Добавить должность :");
  51.         }
  52.  
  53.         static void ShowLists(string[] fullNames, string[] positions, string text)
  54.         {
  55.             Console.WriteLine(text);
  56.             int indent = 1;
  57.  
  58.             for (int i = 0; i < fullNames.Length; i++)
  59.             {
  60.                 Console.WriteLine((i + indent) + ") " + fullNames[i] + " - " + positions[i] + ".");
  61.             }
  62.         }
  63.  
  64.         static void DeleteDossier(ref string[] fullNames, ref string[] positions)
  65.         {
  66.             int number = Convert.ToInt32(Console.ReadLine());
  67.             DeleteElement(number, ref fullNames);
  68.             DeleteElement(number, ref positions);
  69.         }
  70.  
  71.         static void SearchSurname(string[] fullNames, string[] positions)
  72.         {
  73.             Console.WriteLine("Введите фамилию :");
  74.             string surname = Console.ReadLine();
  75.  
  76.             for (int i = 0; i < fullNames.Length; i++)
  77.             {
  78.                 string[] words = fullNames[i].Split(' ');
  79.  
  80.                 if (words[0] == surname)
  81.                 {
  82.                     Console.WriteLine(fullNames[i] + " - " + positions[i]);
  83.                 }
  84.             }
  85.         }
  86.  
  87.         static void DeleteElement(int number, ref string[] element)
  88.         {
  89.             if (0< number && number <= element.Length)
  90.             {
  91.                 string[] tempElement = new string[element.Length - 1];
  92.  
  93.                 for (int i = number - 1; i < element.Length - 1; i++)
  94.                 {
  95.                     element[i] = element[i + 1];
  96.                 }
  97.  
  98.                 for (int i = 0; i < element.Length - 1; i++)
  99.                 {
  100.                     tempElement[i] = element[i];
  101.                 }
  102.  
  103.                 element = tempElement;
  104.             }
  105.         }
  106.  
  107.         static void AddElement(ref string[] element,string text)
  108.         {
  109.             string[] tempElement = new string[element.Length + 1];
  110.  
  111.             for (int i = 0; i < element.Length; i++)
  112.             {
  113.                 tempElement[i] = element[i];
  114.             }
  115.  
  116.             Console.WriteLine(text);
  117.             string newElement = Convert.ToString(Console.ReadLine());
  118.             tempElement[tempElement.Length - 1] = newElement;
  119.             element = tempElement;
  120.         }
  121.     }
  122. }
  123. [EndCode]
Advertisement
Add Comment
Please, Sign In to add comment