Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- internal class Program
- {
- static void Main(string[] args)
- {
- const string AddDossierCommand = "add";
- const string OutputDossierCommand = "output all";
- const string DeleteDossierCommand = "delete";
- const string FindLastNameCommand = "find";
- const string EndProgramCommand = "exit";
- string[] fullNames = new string[0];
- string[] jobTitles = new string[0];
- bool isWorking = true;
- while (isWorking)
- {
- Console.WriteLine($"База данных:" +
- $"\nДля добавления досье введите - {AddDossierCommand}." +
- $"\nДля вывода всей базы введите - {OutputDossierCommand}." +
- $"\nДля удаления досье введите - {DeleteDossierCommand}." +
- $"\nДля поиска по фамилии введите - {FindLastNameCommand}." +
- $"\nДля выхода введите - {EndProgramCommand}.");
- string? userInput = Console.ReadLine();
- switch (userInput)
- {
- case AddDossierCommand:
- AddDossier(ref fullNames, ref jobTitles);
- break;
- case OutputDossierCommand:
- OutputAllDossier(fullNames, jobTitles);
- break;
- case DeleteDossierCommand:
- DeleteDossier(ref fullNames, ref jobTitles);
- break;
- case FindLastNameCommand:
- FindLastName(fullNames, jobTitles);
- break;
- case EndProgramCommand:
- isWorking = EndProgram(isWorking);
- break;
- default:
- DisplayUncorrectMessage();
- break;
- }
- Console.Clear();
- }
- }
- static void AddDossier(ref string[] fullNames, ref string[] jobTitles)
- {
- string fullName = "ФИО";
- string jobTitle = "должность";
- fullNames = AddData(fullNames, fullName);
- jobTitles = AddData(jobTitles, jobTitle);
- }
- static void OutputAllDossier(string[] fullNames, string[] jobTitles)
- {
- if (fullNames.Length == 0)
- {
- Console.WriteLine("Массив пуст.");
- Console.ReadKey();
- }
- else
- {
- for (int i = 0; i < fullNames.Length - 1; i++)
- {
- int serialNumber = i + 1;
- Console.Write($"{serialNumber} {fullNames[i]} {jobTitles[i]} - ");
- }
- Console.Write($"{fullNames.Length} {fullNames[fullNames.Length - 1]} {jobTitles[fullNames.Length - 1]}.");
- Console.ReadKey();
- }
- }
- static void DeleteDossier(ref string[] fullNames, ref string[] jobTitles)
- {
- if (fullNames.Length > 0)
- {
- Console.Write("Введите номер досье, которое хотите удалить: ");
- int number = Convert.ToInt32(Console.ReadLine()) - 1;
- if (number >= fullNames.Length || number < 0)
- {
- Console.WriteLine("Число вышло за пределы массива.");
- Console.ReadKey();
- }
- else
- {
- fullNames = FillingArraytoIndex(fullNames, number);
- jobTitles = FillingArraytoIndex(jobTitles, number);
- }
- }
- else
- {
- Console.WriteLine("Массив пуст.");
- Console.ReadKey();
- }
- }
- static void FindLastName(string[] fullNames, string[] jobTitles)
- {
- if (fullNames.Length == 0)
- {
- Console.WriteLine("Массив пуст.");
- Console.ReadKey();
- }
- else
- {
- Console.Write("Введите фамилию: ");
- string? lastName = Console.ReadLine();
- bool isFound = false;
- for (int i = 0; i < fullNames.Length; i++)
- {
- int serialNumber = i + 1;
- if (fullNames[i].Split()[0] == lastName)
- {
- Console.WriteLine($"{serialNumber} {fullNames[i]} {jobTitles[i]}");
- isFound = true;
- }
- }
- if (isFound == false)
- {
- Console.WriteLine($"Досье с фамилией {lastName} не найдено.");
- }
- Console.ReadKey();
- }
- }
- static bool EndProgram(bool isWorking)
- {
- Console.WriteLine("Выход из программы. Нажмите любую клавишу...");
- Console.ReadKey();
- return false;
- }
- static void DisplayUncorrectMessage()
- {
- Console.WriteLine("Введена некорректная команда. Попробуйте еще раз.");
- Console.ReadKey();
- }
- static string[] AddData(string[] array, string indexName)
- {
- string[] tempArray = new string[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- tempArray[i] = array[i];
- }
- Console.Write($"Введите {indexName}: ");
- string? name = Console.ReadLine();
- tempArray[array.Length] = name;
- array = tempArray;
- return array;
- }
- static string[] FillingArraytoIndex(string[] array, int index)
- {
- string[] tempArray = new string[array.Length - 1];
- for (int i = 0; i < index; i++)
- {
- tempArray[i] = array[i];
- }
- for (int i = index + 1; i < array.Length; i++)
- {
- tempArray[i - 1] = array[i];
- }
- array = tempArray;
- return array;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement