Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Kadr
- {
- class Program
- {
- static void Main(string[] args)
- {
- const string CommandAdd = "add";
- const string CommandPrint = "print";
- const string CommandDelete = "delete";
- const string CommandFind = "find";
- const string CommandExit = "exit";
- string[] fullNames = new string[0];
- string[] positions = new string[0];
- string userInput;
- bool isRunning = true;
- while (isRunning)
- {
- Console.Clear();
- Console.WriteLine($"{CommandAdd} - добавить досье\n{CommandPrint} - распечатать досье\n{CommandDelete} - удалить досье");
- Console.WriteLine($"{CommandFind} - найти номер досье по фамилии\n{CommandExit} - выйти из программы");
- Console.WriteLine();
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case CommandAdd:
- AddFile(ref fullNames, ref positions);
- break;
- case CommandPrint:
- PrintFiles(fullNames, positions);
- break;
- case CommandDelete:
- DeleteFile(ref fullNames, ref positions);
- break;
- case CommandFind:
- FindFiles(fullNames, positions);
- break;
- case CommandExit:
- isRunning = false;
- break;
- }
- }
- }
- static void AddFile(ref string[] fullNames, ref string[] positions)
- {
- string fullName;
- string position;
- Console.WriteLine("Введите ФИО");
- fullName = Console.ReadLine();
- Console.WriteLine("Введите должность");
- position = Console.ReadLine();
- fullNames = AddInArray(fullNames, fullName);
- positions = AddInArray(positions, position);
- Console.WriteLine("Количество досье в архиве: " + fullNames.Length);
- Console.ReadKey();
- }
- static void PrintFiles(string[] fullNames, string[] positions)
- {
- if (fullNames.Length == 0)
- {
- Console.WriteLine("В досье отсутствуют записи");
- }
- else
- {
- for (int i = 0; i < fullNames.Length; i++)
- Console.WriteLine($"{i + 1} - {fullNames[i]} - {positions[i]}");
- }
- Console.ReadKey();
- }
- static void DeleteFile(ref string[] fullNames, ref string[] positions)
- {
- Console.Write("Введите номер удаляемой записи ");
- int fileIndex = Convert.ToInt32(Console.ReadLine()) - 1;
- if (fileIndex >= fullNames.Length)
- {
- Console.WriteLine("Досье с данным номером отсутствует");
- }
- else
- {
- fullNames = DeleteFromArray(fullNames, fileIndex);
- positions = DeleteFromArray(positions, fileIndex);
- }
- Console.WriteLine("Количество досье в архиве: " + fullNames.Length);
- Console.ReadKey();
- }
- static void FindFiles(string[] fullNames, string[] positions)
- {
- Console.Write("Введите искомую фамилию ");
- string surnameRequest = Console.ReadLine();
- string foundEntries = "";
- int foundEntryCount = 0;
- for (int i = 0; i < fullNames.Length; i++)
- {
- string surname = fullNames[i].Split(' ')[0];
- if (surnameRequest == surname)
- {
- foundEntryCount++;
- foundEntries += string.Format($"{i} ");
- }
- }
- if (foundEntryCount == 0)
- {
- Console.WriteLine("Досье отсутствует");
- }
- else
- {
- Console.WriteLine("Фамилия встречается в досье: " + foundEntries);
- }
- Console.ReadKey();
- }
- static string[] AddInArray(string[] array, string value)
- {
- string[] temporaryArray = new string[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- temporaryArray[i] = array[i];
- }
- temporaryArray[array.Length] = value;
- return temporaryArray;
- }
- static string[] DeleteFromArray(string[] array, int index)
- {
- if(array.Length == 0)
- {
- return array;
- }
- string[] temporaryArray = new string[array.Length - 1];
- for (int i = 0; i < index; i++)
- {
- temporaryArray[i] = array[i];
- }
- for (int i = index; i < temporaryArray.Length; i++)
- {
- temporaryArray[i] = array[i + 1];
- }
- return temporaryArray;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement