Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp28
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- const string CommandAddDossier = "1";
- const string CommandShowDossier = "2";
- const string CommandDeleteDossier = "3";
- const string CommandSearchName = "4";
- const string CommandExitProgram = "5";
- string[] names = new string[0];
- string[] positions = new string[0];
- string userInput;
- bool isWork = true;
- while (isWork)
- {
- Console.WriteLine(" МЕНЮ");
- Console.WriteLine(
- " 1) Добавить досье.\n" +
- " 2) Показать досье.\n" +
- " 3) Удалить досье.\n" +
- " 4) Поиск по фамилии.\n" +
- " 5) Выход.");
- userInput = Console.ReadLine();
- Console.Clear();
- switch (userInput)
- {
- case CommandAddDossier:
- AddDossier(ref names, ref positions);
- break;
- case CommandShowDossier:
- ShowDossier(names, positions);
- break;
- case CommandDeleteDossier:
- DeleteDossier(ref names, ref positions);
- break;
- case CommandSearchName:
- SearchName(names, positions);
- break;
- case CommandExitProgram:
- isWork = false;
- break;
- }
- }
- }
- static void AddElement(ref string[] array, string text)
- {
- Console.Write(text);
- string userInput = Console.ReadLine();
- string[] temporaryArray = new string[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- temporaryArray[i] = array[i];
- }
- temporaryArray[temporaryArray.Length - 1] = userInput;
- array = temporaryArray;
- }
- static void AddDossier(ref string[] names, ref string[] positions)
- {
- AddElement(ref names, "Укажите ваше ФИО :");
- AddElement(ref positions, "Укажите вашу должность :");
- }
- static void ShowDossier(string[] names, string[] positions)
- {
- for (int i = 0; i < names.Length; i++)
- {
- ShowElement(i, names[i], positions[i]);
- }
- }
- static void DeleteElement(ref string[] array, int index)
- {
- string[] tempArray = new string[array.Length - 1];
- for (int i = 0; i < index - 1; i++)
- {
- tempArray[i] = array[i];
- }
- for (int i = index - 1; i < tempArray.Length; i++)
- {
- tempArray[i] = array[i + 1];
- }
- array = tempArray;
- }
- static void DeleteDossier(ref string[] names, ref string[] positions)
- {
- Console.Write("Укажите номер досье которое нужно удалить : ");
- string userInput = Console.ReadLine();
- bool isNumber = int.TryParse(userInput, out int numberValue);
- if (isNumber && numberValue <= names.Length)
- {
- DeleteElement(ref names, numberValue);
- DeleteElement(ref positions, numberValue);
- Console.WriteLine($"Досье {userInput} удалено.");
- }
- else
- {
- Console.WriteLine($"Досье {userInput} нету.");
- }
- }
- static void SearchName(string[] names, string[] positions)
- {
- Console.Write("Введите фамилию : ");
- string userInput = Console.ReadLine();
- string[] nameElements;
- bool isFound = false;
- for (int i = 0; i < names.Length; i++)
- {
- nameElements = names[i].Split(' ');
- for (int j = 0; j < nameElements.Length; j++)
- {
- if (nameElements[j].ToLower() == userInput.ToLower())
- {
- Console.Write("Найден : ");
- ShowElement(i, names[i], positions[i]);
- isFound = true;
- }
- }
- }
- if (isFound == false)
- {
- Console.WriteLine("Ничего не найдено.");
- }
- }
- static void ShowElement(int index ,string name , string position)
- {
- Console.WriteLine($"{index + 1}) {name} - {position}.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment