Dr_Max_Experience

Task 28

Nov 28th, 2021 (edited)
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.34 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. namespace HomeWorks
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> posts = new List<string>();
  12.             List<string> initials = new List<string>();
  13.             string userInput = "";
  14.  
  15.             while (userInput != "exit")
  16.             {
  17.                 Console.Clear();
  18.  
  19.                 Console.WriteLine("1) add - Добавить досье\n2) output_all - Вывести все досье\n" +
  20.                     "3) delete - удалить досье\n4) exit - Выход из программы\n");
  21.                 Console.Write("Введите команду: ");
  22.                 userInput = Console.ReadLine();
  23.  
  24.                 switch (userInput)
  25.                 {
  26.                     case "add":
  27.                         addDossier(ref posts, ref initials);
  28.                         break;
  29.  
  30.                     case "output_all":
  31.                         outputAll(posts, initials);
  32.                         break;
  33.  
  34.                     case "delete":
  35.                         outputAll(posts, initials);
  36.                         deleteDossier(posts, initials);
  37.                         break;
  38.  
  39.                     case "exit":
  40.                         Console.Write("Все досье будут удалены!\nНажмите любую клавишу для выхода...");
  41.                         break;
  42.  
  43.                     default:
  44.                         Console.Write("Такой команды нет!\nНажмите любую клавишу для продолжения...");
  45.                         break;
  46.                 }
  47.                 Console.ReadKey();
  48.             }
  49.         }
  50.  
  51.         static void addDossier(ref List<string> posts, ref List<string> initials)
  52.         {
  53.             Console.Write("Введите должность: ");
  54.             string userInputPost = Console.ReadLine();
  55.             posts.Add(userInputPost);
  56.  
  57.             Console.Write("Введите ФИО: ");
  58.             string userInputInitials = Console.ReadLine();
  59.             initials.Add(userInputInitials);
  60.  
  61.             Console.Write("Досье успешно добавлено!\nНажмите любую клавишу для продолжения...");
  62.         }
  63.  
  64.         static void outputAll(List<string> posts, List<string> initials)
  65.         {
  66.             int dossierNumber;
  67.  
  68.             for (int i = 0; i < posts.Count; i++)
  69.             {
  70.                 dossierNumber = i + 1;
  71.                 Console.WriteLine($"{dossierNumber}.  {posts[i]} - {initials[i]}");
  72.             }
  73.         }
  74.  
  75.         static void deleteDossier(List<string> posts, List<string> initials)
  76.         {
  77.             Console.Write("Введите номер досье, для его удаления: ");
  78.             int userInput = Convert.ToInt32(Console.ReadLine());
  79.             int dossierIndex = userInput - 1;
  80.  
  81.             if (userInput > 0 && userInput <= posts.Count)
  82.             {
  83.                 initials.RemoveAt(dossierIndex);
  84.                 posts.RemoveAt(dossierIndex);
  85.                 Console.Write("Досье успешно удалено!");
  86.             }
  87.             else
  88.             {
  89.                 Console.Write("Такого досье нет!");
  90.             }
  91.         }
  92.     }
  93. }
Add Comment
Please, Sign In to add comment