Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Homework1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] initials = new string[0];
- string[] placeOfWork = new string[0];
- bool isActive = true;
- while (isActive)
- {
- Console.WriteLine("1) добавить досье\n" +
- "2) вывести все досье\n" +
- "3) удалить досье\n" +
- "4) поиск по фамилии\n" +
- "5) выход");
- string userInput = Console.ReadLine();
- Console.Clear();
- switch (userInput)
- {
- case "1":
- AddDossier(ref initials, ref placeOfWork);
- break;
- case "2":
- ShowDossier(initials, placeOfWork);
- break;
- case "3":
- DeleteDossier(ref initials, ref placeOfWork);
- break;
- case "4":
- FindBySurname(initials, placeOfWork);
- break;
- case "5":
- isActive = false;
- break;
- default:
- Console.WriteLine("Нет такого пункта меню");
- break;
- }
- ClearConsole();
- }
- }
- static void AddDossier(ref string[] initials, ref string[] placeOfWork)
- {
- Console.WriteLine("Добавить досье");
- Console.Write("Введите ФИО: ");
- AddElement(ref initials);
- Console.Write("Введите место работы: ");
- AddElement(ref placeOfWork);
- Console.WriteLine("Новое досье: " + initials[initials.Length - 1] + " - " + placeOfWork[placeOfWork.Length - 1]);
- }
- static void AddElement(ref string[] array)
- {
- string[] tempArray = new string[array.Length + 1];
- string userInput = Console.ReadLine();
- for (int i = 0; i < array.Length; i++)
- {
- tempArray[i] = array[i];
- }
- tempArray[tempArray.Length - 1] = userInput;
- array = tempArray;
- }
- static void ShowDossier(string[] initials, string[] placeOfWork)
- {
- Console.WriteLine("---ВСЕ ДОСЬЕ---");
- for (int i = 1; i < initials.Length + 1; i++)
- {
- Console.WriteLine($"{i}. {initials[i - 1]} - {placeOfWork[i - 1]}");
- }
- }
- static void DeleteDossier(ref string[] initials, ref string[] placeOfWork)
- {
- Console.Write("Введите номер досье, которое хотите удалить:");
- string numberToDelete = Console.ReadLine();
- if (int.TryParse(numberToDelete, out int result))
- {
- if (result > 0 && result <= initials.Length)
- {
- DeleteElement(ref initials, result);
- DeleteElement(ref placeOfWork, result);
- }
- else
- {
- Console.WriteLine("Такого досье нет!");
- }
- }
- else
- {
- Console.WriteLine("Это не номер!");
- }
- }
- static void DeleteElement(ref string[] array, int numberToDelete)
- {
- string[] tempArray = new string[array.Length - 1];
- for (int i = 0; i < numberToDelete; i++)
- {
- tempArray[i] = array[i];
- }
- for (int i = numberToDelete; i < array.Length; i++)
- {
- tempArray[i - 1] = array[i];
- }
- array = tempArray;
- }
- static void FindBySurname(string[] initials, string[] placeOfWork)
- {
- Console.Write("Введите ФИО:");
- string userInput = Console.ReadLine();
- bool noMatch = true;
- for (int i = 0; i < initials.Length; i++)
- {
- if (userInput.ToLower() == initials[i].ToLower())
- {
- Console.WriteLine($"{i + 1}. {initials[i]} - {placeOfWork[i]}");
- noMatch = false;
- }
- }
- if (noMatch)
- {
- Console.WriteLine("Неверное ФИО.");
- }
- }
- static bool Exit()
- {
- Console.WriteLine("Выход...");
- return false;
- }
- static void ClearConsole()
- {
- Console.WriteLine("Для продолжения нажмите любую клавишу...");
- Console.ReadKey();
- Console.Clear();
- }
- }
- }
Add Comment
Please, Sign In to add comment