Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace FifthProject
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] fio = new string[0];
- string[] post = new string[0];
- bool exit = false;
- while (!exit)
- {
- ShowMenu();
- switch (MenuInput())
- {
- case '1':
- Console.Write("Введите ФИО через пробел: ");
- AddNewFile(ref fio, Console.ReadLine());
- Console.Write("Введите пост: ");
- AddNewFile(ref post, Console.ReadLine());
- break;
- case '2':
- ShowAllFiles(fio, post);
- Console.ReadKey();
- break;
- case '3':
- Console.Write($"Выбрать досье: \n");
- ShowAllFiles(fio, post);
- SelectFileForDelete(ref fio, ref post, ConvertToInt());
- break;
- case '4':
- Console.Write("Введите фамилию: ");
- FindFile(Console.ReadLine(), fio, post);
- Console.ReadKey();
- break;
- case '5':
- exit = true;
- break;
- default:
- Console.WriteLine("Incorrect enter");
- break;
- }
- Console.Clear();
- }
- }
- static void ShowMenu()
- {
- Console.WriteLine("\tMenu\n" +
- "1. Add new file\n" +
- "2. Show all files\n" +
- "3. Delete file\n" +
- "4. Find file\n" +
- "5. Exit");
- }
- static char MenuInput()
- {
- char menuInput = Console.ReadKey(true).KeyChar;
- return menuInput;
- }
- static void AddNewFile(ref string[] arr, string str)
- {
- string[] tempArr = new string[arr.Length + 1];
- for (int i = 0; i < arr.Length; i++)
- {
- tempArr[i] = arr[i];
- }
- tempArr[tempArr.Length - 1] = str;
- arr = tempArr;
- }
- static void ShowAllFiles(string[] arr, string[] arr2)
- {
- if (arr.Length == 0)
- {
- Console.WriteLine("Empty list");
- }
- else
- {
- for (int i = 0; i < arr.Length; i++)
- {
- Console.WriteLine($"{i + 1}. {arr[i]} - {arr2[i]}");
- }
- }
- }
- static void FindFile(string surname, string[] arr, string[] arr2)
- {
- for (int i = 0; i < arr.Length; i++)
- {
- string[] tempArr = arr[i].Split(' ');
- if (tempArr[1].ToLower() == surname.ToLower())
- {
- Console.WriteLine($"{i + 1}. {arr[i]} - {arr2[i]}");
- }
- }
- }
- static void SelectFileForDelete(ref string[] arr, ref string[] arr2, int userInput)
- {
- DeleteFile(ref arr, userInput - 1);
- DeleteFile(ref arr2, userInput - 1);
- }
- static void DeleteFile(ref string[] arr, int userInput)
- {
- string[] tempArr = new string[arr.Length - 1];
- arr[userInput] = null;
- for (int i = 0; i < arr.Length - 1; i++)
- {
- if (arr[i] != null)
- {
- tempArr[i] = arr[i];
- }
- else
- {
- tempArr[i] = arr[i+1];
- }
- }
- arr = tempArr;
- }
- static int ConvertToInt()
- {
- Console.WriteLine("Enter file number");
- int output;
- bool enterIsCorrect = false;
- do
- {
- string input = Console.ReadLine();
- enterIsCorrect = int.TryParse(input, out output);
- if (!enterIsCorrect)
- {
- Console.WriteLine("Error enter. Try again");
- }
- } while (!enterIsCorrect);
- return output;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement