kwest87

Untitled

Dec 18th, 2022
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. /*
  8. Используя одну из изученных коллекций, вы смогли бы сильно себе упростить код выполненной программы, ведь у нас данные, это ФИО и позиция.
  9. Поиск в данном задании не нужен.
  10.  
  11. 1) добавить досье
  12.  
  13. 2) вывести все досье (в одну строку через “-” фио и должность)
  14.  
  15. 3) удалить досье
  16.  
  17. 4) выход
  18. */
  19.  
  20. namespace ConsoleApp10
  21. {
  22.     internal class Program
  23.     {
  24.         static void Main(string[] args)
  25.         {
  26.             Dictionary<string, string> dossier = new Dictionary<string, string>();
  27.             bool isWork = true;
  28.             int userInput;
  29.  
  30.             while (isWork)
  31.             {
  32.                 Console.Clear();
  33.                 Console.WriteLine("\tМеню\n1)Добавить досье.\n2)Показать все досье.\n3)Удалить досье.\n4)Выход.");
  34.                 userInput = int.Parse(Console.ReadLine());
  35.  
  36.                 switch (userInput)
  37.                 {
  38.                     case 1:
  39.                         AddDossier(dossier);
  40.                         break;
  41.                     case 2:
  42.                         ShowDossier(dossier);
  43.                         break;
  44.                     case 3:
  45.                         DeleteDossier(dossier);
  46.                         break;
  47.                     case 4:
  48.                         Console.WriteLine("Заврешение работы программы.");
  49.                         isWork = false;
  50.                         break;
  51.                     default:
  52.                         Console.WriteLine("Ошибка , попробуйте ещё раз.");
  53.                         break;
  54.                 }
  55.             }
  56.         }
  57.  
  58.         static void AddDossier(Dictionary<string, string> dossier)
  59.         {
  60.             Console.Write("Укажите фамилию : ");
  61.             string surnameInput = Console.ReadLine();
  62.             Console.Write("Укажите должность " + surnameInput + " : ");
  63.             string jobTitleInput = Console.ReadLine();
  64.             dossier.Add(surnameInput, jobTitleInput);
  65.         }
  66.  
  67.         static void ShowDossier(Dictionary<string, string> dossier)
  68.         {
  69.             int numberPerson = 0;
  70.  
  71.             foreach (var person in dossier)
  72.             {
  73.                 Console.WriteLine(++numberPerson + ")" + person.Key + " - " + person.Value);
  74.             }
  75.  
  76.             Console.WriteLine("Для продолжения нажмите клавишу.");
  77.             Console.ReadKey();
  78.         }
  79.  
  80.         static void DeleteDossier(Dictionary<string, string> dossier)
  81.         {
  82.             Console.Write("Укажите фамилию для удаления : ");
  83.             string surnameInput = Console.ReadLine();
  84.  
  85.             if (dossier.Remove(surnameInput) == false)
  86.             {
  87.                 Console.WriteLine("Таких нету.Нажмите клавишу.");
  88.                 Console.ReadKey();
  89.             }
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment