Advertisement
OwlyOwl

dzdzdzd213123123

Apr 5th, 2020
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.75 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 = AddName(names, newName);
  24.                         position = AddPos(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 = DelName(names, fileNum);
  38.                         position = DelPos(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[] AddName(string[] names, string newName)
  60.         {
  61.             string[] tempNames = new string[names.Length + 1];
  62.             for (int i = 0; i < names.Length; i++)
  63.             {
  64.                 tempNames[i] = names[i];
  65.             }
  66.             tempNames[tempNames.Length - 1] = newName;
  67.             names = tempNames;
  68.             return names;
  69.         }
  70.  
  71.         static string[] AddPos(string[] position, string newPosition)
  72.         {
  73.             string[] tempPos = new string[position.Length + 1];
  74.             for (int i = 0; i < position.Length; i++)
  75.             {
  76.                 tempPos[i] = position[i];
  77.             }
  78.             tempPos[tempPos.Length - 1] = newPosition;
  79.             position = tempPos;
  80.             return position;
  81.         }
  82.  
  83.         static void Output(string[] names, string[] position)
  84.         {
  85.             for (int i = 0; i < names.Length; i++)
  86.             {
  87.                 Console.WriteLine($"{i + 1}.{ names[i]}  -   { position[i]}");
  88.             }
  89.         }
  90.  
  91.         static string[] DelName(string[] names, int fileNum)
  92.         {
  93.             names[names.Length - 1] = names[fileNum - 1];
  94.             Array.Resize(ref names, names.Length - 1);
  95.             return names;
  96.         }
  97.  
  98.         static string[] DelPos(string[] position, int fileNum)
  99.         {
  100.             position[position.Length - 1] = position[fileNum - 1];
  101.             Array.Resize(ref position, position.Length - 1);
  102.             return position;
  103.         }
  104.  
  105.         static int SearchFile(string[] names)
  106.         {
  107.             Console.WriteLine("Введите фамилию для поиска:");
  108.             int fileFound = -1;
  109.             string surname;
  110.             surname = Convert.ToString(Console.ReadLine());
  111.             for (int i = 0; i < names.Length; i++)
  112.             {
  113.                 if (surname.ToLower() == names[i].ToLower())
  114.                 {
  115.                     Console.WriteLine($"Мистер - {names[i]}\nНомер его досье - {i + 1}");
  116.                     fileFound = i;
  117.                 }
  118.                 else
  119.                 {
  120.                     Console.WriteLine("Досье не найдено!");
  121.                 }
  122.             }
  123.             return fileFound;
  124.         }
  125.     }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement