Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace kadry_huyadry
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] names = new string[0];
- string[] position = new string[0];
- bool quitRequest = false;
- while (quitRequest != true)
- {
- Console.WriteLine("Меню:\n1.Добавить досье\n2.Вывести все досье\n3.Удалить досье\n4.Поиск по фамилии\n5.Выход");
- int input = Convert.ToInt32(Console.ReadLine());
- switch (input)
- {
- case 1:
- Console.WriteLine("Введите фамилию:");
- string newName = Console.ReadLine();
- Console.WriteLine("Введите должность:");
- string newPosition = Console.ReadLine();
- names = AddName(names, newName);
- position = AddPos(position, newPosition);
- Console.Clear();
- break;
- case 2:
- Console.Clear();
- Output(names, position);
- Console.ReadKey();
- Console.Clear();
- break;
- case 3:
- Console.Clear();
- Console.WriteLine("Введите номер досье, которое Вы хотите удалить:");
- int fileNum = Convert.ToInt32(Console.ReadLine());
- names = DelName(names, fileNum);
- position = DelPos(position, fileNum);
- break;
- case 4:
- Console.Clear();
- int searchNum = SearchFile(names);
- if (searchNum >=0)
- {
- Console.WriteLine("Его должность: " + position[searchNum]);
- }
- Console.ReadKey();
- Console.Clear();
- break;
- case 5:
- quitRequest = true;
- Console.Clear();
- Console.WriteLine("Завершение работы программы...");
- break;
- }
- }
- }
- static string[] AddName(string[] names, string newName)
- {
- string[] tempNames = new string[names.Length + 1];
- for (int i = 0; i < names.Length; i++)
- {
- tempNames[i] = names[i];
- }
- tempNames[tempNames.Length - 1] = newName;
- names = tempNames;
- return names;
- }
- static string[] AddPos(string[] position, string newPosition)
- {
- string[] tempPos = new string[position.Length + 1];
- for (int i = 0; i < position.Length; i++)
- {
- tempPos[i] = position[i];
- }
- tempPos[tempPos.Length - 1] = newPosition;
- position = tempPos;
- return position;
- }
- static void Output(string[] names, string[] position)
- {
- for (int i = 0; i < names.Length; i++)
- {
- Console.WriteLine($"{i + 1}.{ names[i]} - { position[i]}");
- }
- }
- static string[] DelName(string[] names, int fileNum)
- {
- names[names.Length - 1] = names[fileNum - 1];
- Array.Resize(ref names, names.Length - 1);
- return names;
- }
- static string[] DelPos(string[] position, int fileNum)
- {
- position[position.Length - 1] = position[fileNum - 1];
- Array.Resize(ref position, position.Length - 1);
- return position;
- }
- static int SearchFile(string[] names)
- {
- Console.WriteLine("Введите фамилию для поиска:");
- int fileFound = -1;
- string surname;
- surname = Convert.ToString(Console.ReadLine());
- for (int i = 0; i < names.Length; i++)
- {
- if (surname.ToLower() == names[i].ToLower())
- {
- Console.WriteLine($"Мистер - {names[i]}\nНомер его досье - {i + 1}");
- fileFound = i;
- }
- else
- {
- Console.WriteLine("Досье не найдено!");
- }
- }
- return fileFound;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement