Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Homework4
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] fullname = new string[1];
- string[] position = new string[1];
- bool isMenu = true;
- int userInput;
- string newFullname;
- string newPosition;
- string fullnameSearch;
- int numberDossierDelete;
- while (isMenu)
- {
- Console.WriteLine("\nПриветствуем вас в меню!");
- Console.WriteLine("1 - Добавить досье\n2 - Вывод всех досье\n" +
- "3 - Удалить досье\n4 - Поиск по фамилли\n5 - Выход");
- userInput = Convert.ToInt32(Console.ReadLine());
- switch(userInput)
- {
- case 1:
- Console.Write("Введите ФИО - ");
- newFullname = Console.ReadLine();
- Console.Write("Введите должность - ");
- newPosition = Console.ReadLine();
- FillingDossier(ref fullname,ref position, newFullname, newPosition);
- break;
- case 2:
- PrintDossier(fullname, position);
- break;
- case 3:
- Console.WriteLine($"Введите номер досье для удаления, номер последнего имеющего досье - {fullname.Length-1} ");
- numberDossierDelete = Convert.ToInt32(Console.ReadLine());
- if(numberDossierDelete < 1 || numberDossierDelete > fullname.Length - 1)
- {
- Console.WriteLine($"Нужно было ввести цифру от 1 до {fullname.Length - 1}");
- }
- else
- {
- DeleteDossier(ref fullname, ref position, numberDossierDelete);
- PrintDossier(fullname, position);
- }
- break;
- case 4:
- Console.Write("Введите фамилию сотрудника, которого хотите найти - ");
- fullnameSearch = Console.ReadLine();
- SearchDossier(fullname, position ,fullnameSearch);
- break;
- case 5:
- isMenu = false;
- break;
- default:
- Console.WriteLine("Вы ввели что-то не то!");
- break;
- }
- }
- }
- static void FillingDossier(ref string[] fullname,ref string[] position, string newFullname, string newPosition)
- {
- string[] tempFullname = new string[fullname.Length+1];
- string[] tempPosition = new string[position.Length+1];
- for(int i = 0; i < fullname.Length; i++)
- {
- tempFullname[i] = fullname[i];
- tempPosition[i] = position[i];
- }
- fullname = tempFullname;
- position = tempPosition;
- fullname[fullname.Length - 1] = newFullname;
- position[position.Length - 1] = newPosition;
- }
- static void PrintDossier(string[] fullname, string[] position)
- {
- for(int i = 1; i < fullname.Length; i++)
- {
- Console.Write($"- {i} {fullname[i]} {position[i]} ");
- }
- }
- static void DeleteDossier(ref string[] fullname,ref string[] position, int numberDossierDelete)
- {
- string[] tempFullname = new string[fullname.Length-1];
- string[] tempPosition = new string[position.Length-1];
- for (int i = numberDossierDelete; i < fullname.Length-1; i++ )
- {
- fullname[i] = fullname[i + 1];
- position[i] = position[i + 1];
- }
- for (int i = 0; i < fullname.Length-1; i++)
- {
- tempFullname[i] = fullname[i];
- tempPosition[i] = position[i];
- }
- fullname = tempFullname;
- position = tempPosition;
- }
- static void SearchDossier(string[] fullname, string[] position, string fullnameSearch)
- {
- for (int i = 1; i < fullname.Length; i++)
- {
- string[] splitFullname = fullname[i].Split(' ');
- if(fullnameSearch.ToLower() == splitFullname[0].ToLower())
- {
- Console.WriteLine($"Сотрудник - {fullname[i]}, должность - {position[i]}");
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement