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[1];
- string[] jobTitles = new string[1];
- 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(ref fullNames, ref jobTitles);
- break;
- case EndProgramCommand:
- EndProgram(out isWorking);
- break;
- default:
- UncorrectMessage();
- break;
- }
- Console.Clear();
- }
- }
- static void AddDossier(ref string[] fullNames, ref string[] jobTitles)
- {
- string fullName = "ФИО";
- string jobTitle = "досье";
- fullNames = FillingArray(fullNames, fullName);
- jobTitles = FillingArray(jobTitles, jobTitle);
- }
- static void OutputAllDossier(string[] fullNames, string[] jobTitles)
- {
- for (int i = 0; i < fullNames.Length - 1; i++)
- {
- if (i >= 0 && i < fullNames.Length - 2)
- {
- Console.Write($"{i + 1} {fullNames[i]} {jobTitles[i]} - ");
- }
- else
- {
- Console.Write($"{i + 1} {fullNames[i]} {jobTitles[i]}.");
- }
- }
- Console.ReadKey();
- }
- static void DeleteDossier(ref string[] fullNames, ref string[] jobTitles)
- {
- string[] newFullNames = new string[fullNames.Length - 1];
- string[] newJobTitles = new string[jobTitles.Length - 1];
- Console.Write("Введите номер досье, которое хотите удалить: ");
- int number = Convert.ToInt32(Console.ReadLine()) - 1;
- if (number <= 0 || number > fullNames.Length)
- {
- Console.WriteLine("Число вышло за пределы массива.");
- }
- for (int i = 0; i < number; i++)
- {
- FillingArraytoIndex(ref fullNames, ref newFullNames, number, out int j);
- FillingArraytoIndex(ref jobTitles, ref newJobTitles, number, out j);
- }
- for (int i = number + 1; i < fullNames.Length - 1; i++)
- {
- FillingArraytoIndex(ref fullNames, ref newFullNames, number, out int j);
- FillingArraytoIndex(ref jobTitles, ref newJobTitles, number, out j);
- }
- fullNames = newFullNames;
- jobTitles = newJobTitles;
- }
- static void FindLastName(ref string[] fullNames, ref string[] jobTitles)
- {
- Console.Write("Введите фамилию: ");
- string? lastName = Console.ReadLine();
- for (int i = 0; i < fullNames.Length - 1; i++)
- {
- if (fullNames[i].Split()[0] == lastName)
- {
- Console.WriteLine($"{i + 1} {fullNames[i]} {jobTitles[i]}");
- }
- }
- Console.ReadKey();
- }
- static void EndProgram(out bool isWorking)
- {
- Console.WriteLine("Выход из программы. Нажмите любую клавишу...");
- Console.ReadKey();
- isWorking = false;
- }
- static void UncorrectMessage()
- {
- Console.WriteLine("Введена некорректная команда. Попробуйте еще раз.");
- Console.ReadKey();
- }
- static string[] FillingArray(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 - 1] = name;
- array = tempArray;
- return array;
- }
- static void FillingArraytoIndex(ref string[] array, ref string[] newArray, int index, out int j)
- {
- j = 0;
- for (int i = 0; i < array.Length; i++)
- {
- if (i != index)
- {
- newArray[j] = array[i];
- j++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment