Advertisement
Vlad_Savitskiy

Dossiers

Apr 14th, 2020
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.86 KB | None | 0 0
  1. using System;
  2.  
  3. namespace CSLightFirst
  4. {
  5.     class Program
  6.     {
  7.         public static void Main()
  8.         {
  9.             string[] fullNames = new string[0];
  10.             string[] posts = new string[0];
  11.             bool isExit = false;
  12.  
  13.             Console.WriteLine("Добро пожаловать в базу досье.\nДоступные действия:\n");
  14.  
  15.             while (!isExit)
  16.                 switch (GetUserInputInMainMenu())
  17.                 {
  18.                     case "1":
  19.                         Console.Clear();
  20.                         fullNames = AddNewData(fullNames, GetUserInput("Введите полное имя: "));
  21.                         posts = AddNewData(posts, GetUserInput("Введите должность: "));
  22.                         break;
  23.                     case "2":
  24.                         ShowAllDossiers(fullNames, posts);
  25.                         break;
  26.                     case "3":
  27.                         DeleteDossier(int.Parse(GetUserInput("Введите порядковый номер удаляемого досье: ")) - 1, fullNames, posts);
  28.                         break;
  29.                     case "4":
  30.                         int resultIndex = FindDossierIndex(GetUserInput("Введите фамилию для поиска: "), fullNames);
  31.                         Console.WriteLine($"Человек с такой фамилией находится под номером {resultIndex + 1}");
  32.                         break;
  33.                     case "5":
  34.                         isExit = true;
  35.                         break;
  36.                     default:
  37.                         Console.WriteLine("Неверная команда, попробуйте ещё раз.");
  38.                         break;
  39.                 }
  40.         }
  41.  
  42.         private static string GetUserInputInMainMenu()
  43.         {
  44.             Console.WriteLine("\n1 - Добавить досье\n" +
  45.                               "2 - Вывести все досье\n" +
  46.                               "3 - Удалить досье\n" +
  47.                               "4 - Поиск по фамилии\n" +
  48.                               "5 - Выход из программы\n");
  49.             Console.Write("Что бы Вы хотели сделать? ");
  50.             return Console.ReadLine();
  51.         }
  52.  
  53.         private static string GetUserInput(string lineForUser)
  54.         {
  55.             Console.Write(lineForUser);
  56.             return Console.ReadLine();
  57.         }
  58.  
  59.         private static string[] AddNewData(string[] data, string newData)
  60.         {
  61.             string[] updatedData = new string[data.Length + 1];
  62.  
  63.             for (int i = 0; i < data.Length; i++)
  64.                 updatedData[i] = data[i];
  65.  
  66.             updatedData[updatedData.Length - 1] = newData;
  67.  
  68.             return updatedData;
  69.         }
  70.  
  71.         private static void ShowAllDossiers(string[] fullNames, string[] posts)
  72.         {
  73.             Console.Clear();
  74.             Console.WriteLine("Полный список досье:\n" +
  75.                               " (№ : Полное имя - Должность)\n");
  76.  
  77.             for (int i = 0; i < fullNames.Length; i++)
  78.                 Console.WriteLine($"  {i + 1} : {fullNames[i]} - {posts[i]}");
  79.  
  80.             Console.ReadKey();
  81.         }
  82.  
  83.         private static void DeleteDossier(int index, string[] fullNames, string[] posts)
  84.         {
  85.             fullNames[index] = "Досье удалено";
  86.             posts[index] = ":(";
  87.         }
  88.  
  89.         private static int FindDossierIndex(string surnameToFind, string[] fullName)
  90.         {
  91.             for (int i = 0; i < fullName.Length; i++)
  92.             {
  93.                 string surname = fullName[i].Split(' ')[0];
  94.                 if (surname == surnameToFind)
  95.                     return i;
  96.             }
  97.  
  98.             return 0;
  99.         }
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement