Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Ijunior
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- const string CommandAddDossier = "1";
- const string CommandShowDossier = "2";
- const string CommandRemoveDossier = "3";
- const string CommandSearchDossier = "4";
- const string CommandExit = "5";
- bool isWork = true;
- string userInput;
- string[] names = new string[0];
- string[] positions = new string[0];
- while (isWork)
- {
- Console.Write($"{CommandAddDossier} - добавить досье" +
- $"\n{CommandShowDossier} - посмотреть все досье" +
- $"\n{CommandRemoveDossier} - удалить досье" +
- $"\n{CommandSearchDossier} - найти досье" +
- $"\n{CommandExit} - выход" +
- $"\nВведите команду: ");
- userInput = Console.ReadLine();
- Console.Clear();
- switch (userInput)
- {
- case CommandAddDossier:
- AddDossier(ref names, ref positions);
- break;
- case CommandShowDossier:
- ShowDossier(names, positions);
- break;
- case CommandRemoveDossier:
- RemoveDossier(ref names, ref positions);
- break;
- case CommandSearchDossier:
- SearchDossier(names, positions);
- break;
- case CommandExit:
- isWork = false;
- break;
- default:
- Console.WriteLine("Некорректный запрос");
- break;
- }
- Console.ReadKey();
- Console.Clear();
- }
- }
- static void AddDossier(ref string[] names, ref string[] positions)
- {
- Console.Write("Введите ФИО сотрудника: ");
- string name = Console.ReadLine();
- names = ExpandArray(names, name);
- Console.Write("Введите должность сотрудника: ");
- string position = Console.ReadLine();
- positions = ExpandArray(positions, position);
- }
- static string[] ExpandArray(string[] array, string value)
- {
- string[] expandedArray = new string[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- expandedArray[i] = array[i];
- }
- expandedArray[expandedArray.Length - 1] = value;
- return expandedArray;
- }
- static void ShowDossier(string[] names, string[] positions)
- {
- if (IsArrayFull(names))
- {
- for (int i = 0; i < names.Length; i++)
- {
- Console.WriteLine(i + 1 + " - " + names[i] + " - " + positions[i]);
- }
- }
- }
- static bool IsArrayFull(string[] array)
- {
- if (array.Length > 0)
- {
- return true;
- }
- Console.WriteLine("Список пуст");
- return false;
- }
- static void RemoveDossier(ref string[] names, ref string[] positions)
- {
- ShowDossier(names, positions);
- if (IsArrayFull(names))
- {
- Console.Write("Выберите номер для удаления: ");
- string userInput = Console.ReadLine();
- if (int.TryParse(userInput, out int index))
- {
- if (index > 0 && index <= names.Length)
- {
- index--;
- names = ReduceArray(names, index);
- positions = ReduceArray(positions, index);
- }
- else
- {
- Console.WriteLine("Некорректный ввод");
- }
- }
- else
- {
- Console.WriteLine("Некорректный ввод");
- }
- }
- }
- static string[] ReduceArray(string[] array, int index)
- {
- string[] reducedArray = new string[array.Length - 1];
- for (int i = 0; i < index; i++)
- {
- reducedArray[i] = array[i];
- }
- index++;
- for (int i = index; i < array.Length; i++)
- {
- reducedArray[i - 1] = array[i];
- }
- return reducedArray;
- }
- static void SearchDossier(string[] names, string[] positions)
- {
- if (IsArrayFull(names))
- {
- char separator = ' ';
- bool haveLastName = true;
- Console.Write("Введите фамилию: ");
- string lastName = Console.ReadLine();
- for (int i = 0; i < names.Length; i++)
- {
- string[] separatedName = names[i].Split(separator);
- if (separatedName[0].ToLower() == lastName.ToLower())
- {
- Console.WriteLine(i + 1 + " - " + names[i] + " - " + positions[i]);
- haveLastName = false;
- }
- }
- if (haveLastName)
- {
- Console.WriteLine("Досье не найдено");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment