Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace CSLightFirst
- {
- class Program
- {
- public static void Main()
- {
- string[] fullNames = new string[0];
- string[] posts = new string[0];
- bool isExit = false;
- Console.WriteLine("Добро пожаловать в базу досье.\nДоступные действия:\n");
- while (!isExit)
- switch (GetUserInputInMainMenu())
- {
- case "1":
- Console.Clear();
- fullNames = AddNewData(fullNames, GetUserInput("Введите полное имя: "));
- posts = AddNewData(posts, GetUserInput("Введите должность: "));
- break;
- case "2":
- ShowAllDossiers(fullNames, posts);
- break;
- case "3":
- DeleteDossier(int.Parse(GetUserInput("Введите порядковый номер удаляемого досье: ")) - 1, fullNames, posts);
- break;
- case "4":
- int resultIndex = FindDossierIndex(GetUserInput("Введите фамилию для поиска: "), fullNames);
- Console.WriteLine($"Человек с такой фамилией находится под номером {resultIndex + 1}");
- break;
- case "5":
- isExit = true;
- break;
- default:
- Console.WriteLine("Неверная команда, попробуйте ещё раз.");
- break;
- }
- }
- private static string GetUserInputInMainMenu()
- {
- Console.WriteLine("\n1 - Добавить досье\n" +
- "2 - Вывести все досье\n" +
- "3 - Удалить досье\n" +
- "4 - Поиск по фамилии\n" +
- "5 - Выход из программы\n");
- Console.Write("Что бы Вы хотели сделать? ");
- return Console.ReadLine();
- }
- private static string GetUserInput(string lineForUser)
- {
- Console.Write(lineForUser);
- return Console.ReadLine();
- }
- private static string[] AddNewData(string[] data, string newData)
- {
- string[] updatedData = new string[data.Length + 1];
- for (int i = 0; i < data.Length; i++)
- updatedData[i] = data[i];
- updatedData[updatedData.Length - 1] = newData;
- return updatedData;
- }
- private static void ShowAllDossiers(string[] fullNames, string[] posts)
- {
- Console.Clear();
- Console.WriteLine("Полный список досье:\n" +
- " (№ : Полное имя - Должность)\n");
- for (int i = 0; i < fullNames.Length; i++)
- Console.WriteLine($" {i + 1} : {fullNames[i]} - {posts[i]}");
- Console.ReadKey();
- }
- private static void DeleteDossier(int index, string[] fullNames, string[] posts)
- {
- fullNames[index] = "Досье удалено";
- posts[index] = ":(";
- }
- private static int FindDossierIndex(string surnameToFind, string[] fullName)
- {
- for (int i = 0; i < fullName.Length; i++)
- {
- string surname = fullName[i].Split(' ')[0];
- if (surname == surnameToFind)
- return i;
- }
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement