Advertisement
OwlyOwl

dzdzdzdz2.0

Apr 5th, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.09 KB | None | 0 0
  1. using System;
  2.  
  3. namespace kadry_huyadry
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string[] names = new string[0];
  10.             string[] position = new string[0];
  11.             bool quitRequest = false;
  12.             while (quitRequest != true)
  13.             {
  14.                 Console.WriteLine("Меню:\n1.Добавить досье\n2.Вывести все досье\n3.Удалить досье\n4.Поиск по фамилии\n5.Выход");
  15.                 int input = Convert.ToInt32(Console.ReadLine());
  16.                 switch (input)
  17.                 {
  18.                     case 1:
  19.                         Console.WriteLine("Введите фамилию:");
  20.                         string newName = Console.ReadLine();
  21.                         Console.WriteLine("Введите должность:");
  22.                         string newPosition = Console.ReadLine();
  23.                         names = AddFile(names, newName);
  24.                         position = AddFile(position, newPosition);
  25.                         Console.Clear();
  26.                         break;
  27.                     case 2:
  28.                         Console.Clear();
  29.                         Output(names, position);
  30.                         Console.ReadKey();
  31.                         Console.Clear();
  32.                         break;
  33.                     case 3:
  34.                         Console.Clear();
  35.                         Console.WriteLine("Введите номер досье, которое Вы хотите удалить:");
  36.                         int fileNum = Convert.ToInt32(Console.ReadLine());
  37.                         names = DelFile(names, fileNum);
  38.                         position = DelFile(position, fileNum);
  39.                         break;
  40.                     case 4:
  41.                         Console.Clear();
  42.                         int searchNum = SearchFile(names);
  43.                         if (searchNum >= 0)
  44.                         {
  45.                             Console.WriteLine("Его должность: " + position[searchNum]);
  46.                         }
  47.                         Console.ReadKey();
  48.                         Console.Clear();
  49.                         break;
  50.                     case 5:
  51.                         quitRequest = true;
  52.                         Console.Clear();
  53.                         Console.WriteLine("Завершение работы программы...");
  54.                         break;
  55.                 }
  56.             }
  57.         }
  58.  
  59.         static string[] AddFile(string[] arr, string newFile)
  60.         {
  61.             string[] tempArr = new string[arr.Length + 1];
  62.             for (int i = 0; i < arr.Length; i++)
  63.             {
  64.                 tempArr[i] = arr[i];
  65.             }
  66.             tempArr[tempArr.Length - 1] = newFile;
  67.             arr = tempArr;
  68.             return arr;
  69.         }
  70.  
  71.         static void Output(string[] names, string[] position)
  72.         {
  73.             for (int i = 0; i < names.Length; i++)
  74.             {
  75.                 Console.WriteLine($"{i + 1}.{ names[i]}  -   { position[i]}");
  76.             }
  77.         }
  78.  
  79.         static string[] DelFile(string[] names, int fileNum)
  80.         {
  81.             names[fileNum - 1] = names[names.Length - 1];
  82.             Array.Resize(ref names, names.Length - 1);
  83.             return names;
  84.         }
  85.  
  86.         static int SearchFile(string[] names)
  87.         {
  88.             Console.WriteLine("Введите фамилию для поиска:");
  89.             int fileFound = -1;
  90.             string surname;
  91.             surname = Convert.ToString(Console.ReadLine());
  92.             for (int i = 0; i < names.Length; i++)
  93.             {
  94.                 if (surname.ToLower() == names[i].ToLower())
  95.                 {
  96.                     Console.WriteLine($"Мистер - {names[i]}\nНомер его досье - {i + 1}");
  97.                     fileFound = i;
  98.                 }
  99.                 else
  100.                 {
  101.                     Console.WriteLine("Досье не найдено!");
  102.                 }
  103.             }
  104.             return fileFound;
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement