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[] name = new string[0];
- string[] surName = new string[0];
- string[] patronymic = new string[0];
- string[] post = new string[0];
- bool exit = false;
- while (!exit)
- {
- ShowMenu();
- switch (MenuInput())
- {
- case '1':
- Console.Write("Enter name: ");
- AddNewFile(ref name, Console.ReadLine());
- Console.Write("Enter surname: ");
- AddNewFile(ref surName, Console.ReadLine());
- Console.Write("Enter patronymic: ");
- AddNewFile(ref patronymic, Console.ReadLine());
- Console.Write("Enter post: ");
- AddNewFile(ref post, Console.ReadLine());
- break;
- case '2':
- ShowAllFiles(name, surName, patronymic, post);
- Console.ReadKey();
- break;
- case '3':
- Console.Write($"Select file: \n");
- ShowAllFiles(name, surName, patronymic, post);
- SelectFileForDelete(ref name, ref surName, ref patronymic, ref post, Convert.ToInt32(Console.ReadLine()));
- break;
- case '4':
- Console.Write("Write surname: ");
- FindFile(Console.ReadLine(), name, surName, patronymic, 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, string[] arr3, string[] arr4)
- {
- 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]} - {arr3[i]} - {arr4[i]}");
- }
- }
- }
- static void FindFile(string surname, string[] arr, string[] arr2, string[] arr3, string[] arr4)
- {
- for (int i = 0; i < arr2.Length; i++)
- {
- if (arr2[i].ToLower() == surname.ToLower())
- {
- Console.WriteLine($"{i + 1}. {arr[i]} - {arr2[i]} - {arr3[i]} - {arr4[i]}");
- }
- }
- }
- static void SelectFileForDelete(ref string[] arr, ref string[] arr2, ref string[] arr3, ref string[] arr4, int userInput)
- {
- DeleteFile(ref arr, userInput - 1);
- DeleteFile(ref arr2, userInput - 1);
- DeleteFile(ref arr3, userInput - 1);
- DeleteFile(ref arr4, 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;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement