Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Test
- {
- class Program
- {
- static void Main(string[] args)
- {
- string userInput;
- string form = "";
- string[] names = new string[0];
- string[] jobs = new string[0];
- bool isProgramActive = true;
- while (isProgramActive)
- {
- Console.WriteLine("Заполнить досье - 1 | Показать список досье - 2 | Удалить досье - 3 | Поиск досье по фамилии - 4 | Выход - 5");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "1":
- AddForm(ref names, ref jobs);
- break;
- case "2":
- ShowForm(form, names, jobs);
- break;
- case "3":
- DeleteForm(ref names, ref jobs);
- break;
- case "4":
- SearchBySurName(names, jobs);
- break;
- case "5":
- isProgramActive = false;
- break;
- }
- Console.WriteLine("\nНажмите любую клавишу для продолжения...");
- Console.ReadKey();
- Console.Clear();
- }
- }
- static string[] ReSize(ref string[] array, string userInput)
- {
- string[] tempArray = new string[array.Length + 1];
- tempArray[tempArray.Length - 1] = userInput;
- for (int i = 0; i < array.Length; i++)
- {
- tempArray[i] = array[i];
- }
- array = tempArray;
- return array;
- }
- static string[] ReSize(ref string[] array)
- {
- string[] tempArray = new string[array.Length - 1];
- for (int i = 0; i < tempArray.Length; i++)
- {
- tempArray[i] = array[i];
- }
- array = tempArray;
- return array;
- }
- static void AddForm(ref string[] names, ref string[] jobs)
- {
- string name;
- string job;
- Console.Write("Введите ФИО: ");
- name = Console.ReadLine();
- Console.Write("Введите должность: ");
- job = Console.ReadLine();
- ReSize(ref names, name);
- ReSize(ref jobs, job);
- Console.WriteLine("\nДосье добавлено.");
- }
- static void ShowForm(string form, string[] names, string[] jobs)
- {
- for (int i = 0; i < names.Length; i++)
- {
- form = (i + 1) + "." + names[i] + "-" + jobs[i];
- Console.WriteLine(form);
- }
- }
- static void DeleteForm(ref string[] names, ref string[] jobs)
- {
- int numberOfForm;
- bool isFormFound = false;
- Console.Write("Введите номер досье для удаления: ");
- numberOfForm = Convert.ToInt32(Console.ReadLine());
- for (int i = 0; i < names.Length; i++)
- {
- if(numberOfForm == i + 1)
- {
- names[i] = names[names.Length - 1];
- jobs[i] = jobs[jobs.Length - 1];
- isFormFound = true;
- }
- }
- if (isFormFound)
- {
- ReSize(ref names);
- ReSize(ref jobs);
- Console.WriteLine($"\nДосье {numberOfForm} удалено.");
- }
- else
- {
- Console.WriteLine("\nТакого досье нет.");
- }
- }
- static void SearchBySurName(string[] names, string[] jobs)
- {
- bool isFormFound = false;
- string name;
- string[] surName;
- Console.Write("Введите фамилию: ");
- name = Console.ReadLine();
- for (int i = 0; i < names.Length; i++)
- {
- surName = names[i].Split();
- for (int j = 0; j < surName.Length; j++)
- {
- if (name.ToLower() == surName[j].ToLower())
- {
- name = $"{i + 1}.{names[i]} - {jobs[i]}";
- isFormFound = true;
- break;
- }
- }
- }
- if (isFormFound)
- {
- Console.WriteLine(name);
- }
- else
- {
- Console.WriteLine("\nТакого досье нет.");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment