Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Basic_Task16
- {
- class Program
- {
- static void Main(string[] args)
- {
- string inputMenu = null;
- string[] fios = new string[0];
- string[] positions = new string[0];
- while (inputMenu != "0")
- {
- Console.WriteLine("Меню:");
- Console.WriteLine("1.Добавить досье");
- Console.WriteLine("2.Вывести все досье");
- Console.WriteLine("3.Удалить досье");
- Console.WriteLine("4.Поиск по фамилии");
- Console.WriteLine("0.Выход");
- inputMenu = Console.ReadLine();
- switch (inputMenu)
- {
- case "1":
- {
- string fio;
- Console.WriteLine("Введите имя");
- fio = Console.ReadLine();
- Console.WriteLine("Введите фамилию");
- fio += " " + Console.ReadLine();
- Console.WriteLine("Введите отчество");
- fio += " " + Console.ReadLine();
- Console.WriteLine("Введите его должность");
- string position = Console.ReadLine();
- AddDosier(ref fios, ref positions, fio, position);
- break;
- }
- case "2":
- {
- WriteAllDosier(fios, positions);
- break;
- }
- case "3":
- {
- Console.WriteLine("Введите порядковый номер досье, которое удалить");
- string pos = Console.ReadLine();
- RemoveDosier(ref fios, ref positions, int.Parse(pos) - 1);
- break;
- }
- case "4":
- {
- Console.WriteLine("Введите фамилию");
- string lastname = Console.ReadLine();
- SearchByLastName(fios, positions, lastname);
- break;
- }
- case "0":
- {
- break;
- }
- }
- }
- }
- static void AddDosier(ref string[] fios, ref string[] positions, string fio, string position)
- {
- string[] tempFios = new string[fios.Length + 1];
- string[] tempPositions = new string[positions.Length + 1];
- for (int i = 0; i < fios.Length; i++)
- {
- tempFios[i] = fios[i];
- tempPositions[i] = positions[i];
- }
- tempFios[tempFios.Length - 1] = fio;
- tempPositions[tempPositions.Length - 1] = position;
- fios = tempFios;
- positions = tempPositions;
- }
- static void WriteAllDosier(string[] fios, string[] positions)
- {
- for (int i = 0; i < fios.Length; i++)
- {
- Console.WriteLine($"{i+1}. {fios[i]} - {positions[i]}");
- }
- }
- static void RemoveDosier(ref string[] fios, ref string[] positions, int pos)
- {
- if (fios.Length != 0 && pos >= 0 && pos < fios.Length)
- {
- string[] tempFios = new string[fios.Length - 1];
- string[] tempPositions = new string[positions.Length - 1];
- for (int i = 0; i < fios.Length - 1; i++)
- {
- if (i != pos)
- {
- tempFios[i] = fios[i];
- tempPositions[i] = positions[i];
- } else
- {
- i--;
- }
- }
- fios = tempFios;
- positions = tempPositions;
- }
- }
- static void SearchByLastName(string[] fios, string[] positions, string lastName)
- {
- for (int i = 0; i < fios.Length; i++)
- {
- if (fios[i].Contains(lastName))
- {
- Console.WriteLine($"{i}. {fios[i]} - {positions[i]}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement