Dr_Max_Experience

Task 22

Nov 23rd, 2021 (edited)
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.23 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> fullNames = 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 fullNames);
  28.                         break;
  29.  
  30.                     case "output_all":
  31.                         OutputAll(posts, fullNames);
  32.                         break;
  33.  
  34.                     case "delete":
  35.                         OutputAll(posts, fullNames);
  36.                         DeleteDossier(posts, fullNames);
  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> fullNames)
  52.         {
  53.             Console.Write("Введите должность: ");
  54.             string userInputPost = Console.ReadLine();
  55.             posts.Add(userInputPost);
  56.  
  57.             Console.Write("Введите ФИО: ");
  58.             string userInputfullNames = Console.ReadLine();
  59.             fullNames.Add(userInputfullNames);
  60.  
  61.             Console.Write("Досье успешно добавлено!\nНажмите любую клавишу для продолжения...");
  62.         }
  63.  
  64.         static void OutputAll(List<string> posts, List<string> fullNames)
  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]} - {fullNames[i]}");
  72.             }
  73.         }
  74.  
  75.         static void DeleteDossier(List<string> posts, List<string> fullNames)
  76.         {
  77.             if (posts.Count > 0)
  78.             {
  79.                 int dossierIndex;
  80.                 int dossierNumber;
  81.                 bool userInputIntCorrect = false;
  82.  
  83.                 while (userInputIntCorrect == false)
  84.                 {
  85.                     Console.Write("Введите номер досье, для его удаления: ");
  86.                     string userInput = Console.ReadLine();
  87.  
  88.                     if (userInputIntCorrect = int.TryParse(userInput, out dossierNumber))
  89.                     {
  90.                         dossierIndex = dossierNumber - 1;
  91.  
  92.                         if (dossierIndex >= 0 && dossierIndex < posts.Count)
  93.                         {
  94.                             fullNames.RemoveAt(dossierIndex);
  95.                             posts.RemoveAt(dossierIndex);
  96.                             Console.Write("Досье успешно удалено!");
  97.                         }
  98.                         else
  99.                         {
  100.                             Console.Write("Такого досье нет!");
  101.                         }
  102.                     }
  103.                     else
  104.                     {
  105.                         Console.WriteLine("Некорректный ввод! Повторите попытку.");
  106.                     }
  107.                 }
  108.  
  109.                
  110.             }
  111.             else
  112.             {
  113.                 Console.WriteLine("Не найдено ни одного досье!");
  114.             }
  115.         }
  116.     }
  117. }
Add Comment
Please, Sign In to add comment