Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Home_Work
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] fullNames = new string[0];
- string[] positions = new string[0];
- bool isWorking = true;
- while (isWorking)
- {
- ShowCommand();
- switch (Console.ReadLine())
- {
- case "1":
- AddDossier(ref fullNames, ref positions);
- break;
- case "2":
- ShowDossiers(fullNames, positions);
- break;
- case "3":
- DeleteDossier(ref fullNames, ref positions);
- break;
- case "4":
- FindDossierBySurname(fullNames, positions);
- break;
- case "5":
- isWorking = false;
- break;
- default:
- Console.WriteLine("Команды с таким номером не существует.");
- break;
- }
- GetPush();
- }
- }
- static void ShowCommand()
- {
- Console.WriteLine("Доступны следующие команды:\n" +
- "1 - добавить досье\n" +
- "2 - вывести все досье\n" +
- "3 - удалить досье\n" +
- "4 - найти досье по фамилии\n" +
- "5 - закрыть программу ");
- }
- static void GetPush()
- {
- Console.WriteLine("Нажмите любую клавишу, что бы продолжить...");
- Console.ReadKey();
- Console.Clear();
- }
- static void AddDossier(ref string[] fullNames, ref string[] positions)
- {
- string fullName;
- string position;
- Console.Write("Введите ФИО: ");
- fullName = Console.ReadLine();
- Console.Write("Введите должность: ");
- position = Console.ReadLine();
- fullNames = ExpandArray(fullNames, fullName);
- positions = ExpandArray(positions, position);
- }
- static string[] ExpandArray(string[] arrayForExpansion, string value)
- {
- string[] tempArray = new string[arrayForExpansion.Length + 1];
- for (int i = 0; i < arrayForExpansion.Length; i++)
- {
- tempArray[i] = arrayForExpansion[i];
- }
- tempArray[tempArray.Length - 1] = value;
- return tempArray;
- }
- static bool CheckForMissingData(string[] fullNames)
- {
- if (fullNames.Length > 0)
- {
- return false;
- }
- else
- {
- Console.WriteLine("Данные отсутвуют.");
- return true;
- }
- }
- static void ShowDossiers(string[] fullNames, string[] positions)
- {
- if (CheckForMissingData(fullNames) == false)
- {
- for (int i = 0; i < fullNames.Length; i++)
- {
- Console.WriteLine((i + 1) + ". " + fullNames[i] + " - " + positions[i]);
- }
- }
- }
- static void DeleteDossier(ref string[] fullNames, ref string[] positions)
- {
- if (CheckForMissingData(fullNames) == false)
- {
- int index;
- Console.WriteLine("Введите порядковый номер досье: ");
- index = GetIndex(fullNames.Length);
- fullNames = ReduceArray(index, fullNames);
- positions = ReduceArray(index, positions);
- }
- }
- static int GetIndex(int maxIndex)
- {
- bool isExistsIndex = false;
- int number = 0;
- string userInput;
- while (isExistsIndex == false)
- {
- Console.Write("Введите число: ");
- userInput = Console.ReadLine();
- if (Int32.TryParse(userInput, out number))
- {
- if (number > 0 && number <= maxIndex)
- {
- isExistsIndex = true;
- }
- else
- {
- Console.WriteLine("Досье с таким номером не существует.");
- }
- }
- else
- {
- Console.WriteLine("Это не число.");
- }
- }
- return number - 1;
- }
- static string[] ReduceArray(int index, string[] arrayForReduce)
- {
- string[] tempArray = new string[arrayForReduce.Length - 1];
- for (int i = 0; i < index; i++)
- {
- tempArray[i] = arrayForReduce[i];
- }
- for (int i = index; i < tempArray.Length; i++)
- {
- tempArray[i] = arrayForReduce[i + 1];
- }
- return tempArray;
- }
- static void FindDossierBySurname(string[] fullNames, string[] positions)
- {
- if (CheckForMissingData(fullNames) == false)
- {
- string userInput;
- Console.WriteLine("Введите фамилию: ");
- userInput = Console.ReadLine();
- for (int i = 0; i < fullNames.Length; i++)
- {
- if(userInput == fullNames[i].Split(' ')[0])
- {
- Console.WriteLine((i + 1) + ". " + fullNames[i] + " - " + positions[i]);
- }
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment