Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp7
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] fullNames = new string[0];
- string[] posts = new string[0];
- bool isWorking = true;
- while (isWorking)
- {
- Console.Clear();
- Console.WriteLine("1.Добавить досье 2.Вывести досье 3.Удалить досье 4.Поиск по фамилии 5.Выход");
- char userInput = Console.ReadKey(true).KeyChar;
- switch (userInput)
- {
- case '1':
- AddDossier(ref fullNames, ref posts);
- break;
- case '2':
- ShowDossiers(ref fullNames, ref posts);
- break;
- case '3':
- DeleteDossier(ref fullNames, ref posts);
- break;
- case '4':
- FindBySurname(fullNames, posts);
- break;
- case '5':
- isWorking = false;
- Console.WriteLine("Нажмите на любую кнопку...");
- break;
- default:
- Console.WriteLine("Умри");
- break;
- }
- Console.ReadKey();
- }
- }
- public static void FindBySurname(string[] fullNames, string[] posts)
- {
- Console.Write("Введите фамилию: ");
- string userInput = Console.ReadLine();
- string[] foundUsers = GetElements(fullNames,userInput);
- if (foundUsers.Length != 0)
- ShowArray(foundUsers, fullNames, posts);
- else
- Console.WriteLine("Работник не найден");
- }
- public static void ShowArray(string[] array,string[] fullNames, string[] posts)
- {
- for (int i = 0; i < array.Length; i++)
- {
- ShowDossier(fullNames,posts,Convert.ToInt32(array[i]));
- }
- }
- public static void ShowDossier(string[] fullNames, string[] posts, int index)
- {
- Console.WriteLine($"id:{index + 1} ФИО: {fullNames[index]} Должность: {posts[index]}");
- }
- public static string[] GetElements(string[] fullNames,string value)
- {
- string[] elements = new string[0];
- for (int i = 0; i < fullNames.Length; i++)
- {
- if (fullNames[i].Contains(value))
- {
- ResizeArray(ref elements, i.ToString());
- }
- }
- return elements;
- }
- public static void DeleteDossier(ref string[] fullNames, ref string[] posts)
- {
- Console.Write("Введите номер работника: ");
- string userInput = Console.ReadLine();
- int element;
- if (int.TryParse(userInput, out element))
- {
- if (element > 0 && element <= fullNames.Length)
- {
- DeleteElementArray(ref fullNames,element);
- DeleteElementArray(ref posts,element);
- Console.WriteLine($"Досье работника под номером {element} удалено");
- }
- else
- {
- Console.WriteLine("Работника под таким номером не существует!");
- }
- }
- else
- {
- Console.WriteLine("Ввод только числа!!!!");
- }
- }
- public static void DeleteElementArray(ref string[] array, int numberElement)
- {
- numberElement--;
- string[] tempArray = new string[array.Length - 1];
- for (int i = 0; i < numberElement; i++)
- {
- tempArray[i] = array[i];
- }
- for (int i = numberElement + 1; i < array.Length; i++)
- {
- tempArray[i - 1] = array[i];
- }
- array = tempArray;
- }
- public static void ShowDossiers(ref string[] fullNames, ref string[] posts)
- {
- if (fullNames.Length > 0)
- for (int i = 0; i < fullNames.Length; i++)
- Console.Write($"\n{i + 1} - ФИО:{fullNames[i]} || Должность: {posts[i]}");
- else
- Console.WriteLine("Пусто");
- }
- public static void AddDossier(ref string[] fullNames, ref string[] posts)
- {
- Console.Write("Введите ФИО работника: ");
- string fullName = Console.ReadLine();
- Console.Write("Введите должность работника: ");
- string post = Console.ReadLine();
- ResizeArray(ref fullNames,fullName);
- ResizeArray(ref posts, post);
- Console.WriteLine("Досье добавлено!");
- }
- public static void ResizeArray(ref string[] array, string value)
- {
- string[] tempArray = new string[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- tempArray[i] = array[i];
- }
- tempArray[tempArray.Length - 1] = value;
- array = tempArray;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment