Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Kadr
- {
- class Program
- {
- static void Main(string[] args)
- {
- const string CommandAdd = "add";
- const string CommandPrint = "print";
- const string CommandDelete = "delete";
- const string CommandExit = "exit";
- List<string> fullNames = new List<string>();
- List<string> positions = new List<string>();
- string userInput;
- bool isRunning = true;
- while (isRunning)
- {
- Console.Clear();
- Console.WriteLine($"{CommandAdd} - добавить досье\n{CommandPrint} - распечатать досье\n{CommandDelete} - удалить досье");
- Console.WriteLine($"{CommandExit} - выйти из программы");
- Console.WriteLine();
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case CommandAdd:
- AddFile(fullNames, positions);
- break;
- case CommandPrint:
- PrintFiles(fullNames, positions);
- break;
- case CommandDelete:
- DeleteFile(fullNames, positions);
- break;
- case CommandExit:
- isRunning = false;
- break;
- }
- }
- }
- static void AddFile(List<string> fullNames, List<string> positions)
- {
- Console.WriteLine("Введите ФИО");
- fullNames.Add(Console.ReadLine());
- Console.WriteLine("Введите должность");
- positions.Add(Console.ReadLine());
- Console.WriteLine("Количество досье в архиве: " + fullNames.Count);
- Console.ReadKey();
- }
- static void PrintFiles(List<string> fullNames, List<string> positions)
- {
- if (fullNames.Count == 0)
- {
- Console.WriteLine("В досье отсутствуют записи");
- }
- else
- {
- for (int i = 0; i < fullNames.Count; i++)
- Console.WriteLine($"{i + 1} - {fullNames[i]} - {positions[i]}");
- }
- Console.ReadKey();
- }
- static void DeleteFile(List<string> fullNames, List<string> positions)
- {
- int fileIndex;
- Console.Write("Введите номер удаляемой записи ");
- string userInput = Console.ReadLine();
- if (int.TryParse(userInput, out fileIndex) == false)
- {
- Console.WriteLine("Ошибка ввода номера");
- }
- else
- {
- fileIndex = fileIndex - 1;
- if ((fileIndex >= fullNames.Count) || (fileIndex < 0))
- {
- Console.WriteLine("Досье с данным номером отсутствует");
- }
- else
- {
- fullNames.RemoveAt(fileIndex);
- positions.RemoveAt(fileIndex);
- }
- }
- Console.WriteLine("Количество досье в архиве: " + fullNames.Count);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement