Advertisement
SnowPhoenix347

4.1

Nov 4th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.65 KB | None | 0 0
  1. using System;
  2.  
  3. namespace FifthProject
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string[] name = new string[0];
  10.             string[] surName = new string[0];
  11.             string[] patronymic = new string[0];
  12.             string[] post = new string[0];
  13.  
  14.             bool exit = false;
  15.  
  16.             while (!exit)
  17.             {
  18.                 ShowMenu();
  19.                 switch (MenuInput())
  20.                 {
  21.                     case '1':
  22.                         Console.Write("Enter name: ");
  23.                         AddNewFile(ref name, Console.ReadLine());
  24.                         Console.Write("Enter surname: ");
  25.                         AddNewFile(ref surName, Console.ReadLine());
  26.                         Console.Write("Enter patronymic: ");
  27.                         AddNewFile(ref patronymic, Console.ReadLine());
  28.                         Console.Write("Enter post: ");
  29.                         AddNewFile(ref post, Console.ReadLine());
  30.                         break;
  31.                     case '2':
  32.                         ShowAllFiles(name, surName, patronymic, post);
  33.                         Console.ReadKey();
  34.                         break;
  35.                     case '3':
  36.                         Console.Write($"Select file: \n");
  37.                         ShowAllFiles(name, surName, patronymic, post);
  38.                         SelectFileForDelete(ref name, ref surName, ref patronymic, ref post, Convert.ToInt32(Console.ReadLine()));
  39.                         break;
  40.                     case '4':
  41.                         Console.Write("Write surname: ");
  42.                         FindFile(Console.ReadLine(), name, surName, patronymic, post);
  43.                         Console.ReadKey();
  44.                         break;
  45.                     case '5':
  46.                         exit = true;
  47.                         break;
  48.                     default:
  49.                         Console.WriteLine("Incorrect enter");
  50.                         break;
  51.                 }
  52.  
  53.                 Console.Clear();
  54.             }
  55.         }
  56.  
  57.         static void ShowMenu()
  58.         {
  59.             Console.WriteLine("\tMenu\n" +
  60.                               "1. Add new file\n" +
  61.                               "2. Show all files\n" +
  62.                               "3. Delete file\n" +
  63.                               "4. Find file\n" +
  64.                               "5. Exit");
  65.         }
  66.  
  67.         static char MenuInput()
  68.         {
  69.             char menuInput = Console.ReadKey(true).KeyChar;
  70.             return menuInput;
  71.         }
  72.  
  73.         static void AddNewFile(ref string[] arr, string str)
  74.         {
  75.             string[] tempArr = new string[arr.Length + 1];
  76.             for (int i = 0; i < arr.Length; i++)
  77.             {
  78.                 tempArr[i] = arr[i];
  79.             }
  80.            
  81.             tempArr[tempArr.Length - 1] = str;
  82.            
  83.             arr = tempArr;
  84.         }
  85.  
  86.         static void ShowAllFiles(string[] arr, string[] arr2, string[] arr3, string[] arr4)
  87.         {
  88.             if (arr.Length == 0)
  89.             {
  90.                 Console.WriteLine("Empty list");
  91.             }
  92.             else
  93.             {
  94.                 for (int i = 0; i < arr.Length; i++)
  95.                 {
  96.                     Console.WriteLine($"{i + 1}. {arr[i]} - {arr2[i]} - {arr3[i]} - {arr4[i]}");
  97.                 }
  98.             }
  99.         }
  100.  
  101.         static void FindFile(string surname, string[] arr, string[] arr2, string[] arr3, string[] arr4)
  102.         {
  103.             for (int i = 0; i < arr2.Length; i++)
  104.             {
  105.                 if (arr2[i].ToLower() == surname.ToLower())
  106.                 {
  107.                     Console.WriteLine($"{i + 1}. {arr[i]} - {arr2[i]} - {arr3[i]} - {arr4[i]}");
  108.                 }
  109.             }
  110.         }
  111.        
  112.         static void SelectFileForDelete(ref string[] arr, ref string[] arr2, ref string[] arr3, ref string[] arr4, int userInput)
  113.         {
  114.            
  115.             DeleteFile(ref arr, userInput - 1);
  116.             DeleteFile(ref arr2, userInput - 1);
  117.             DeleteFile(ref arr3, userInput - 1);
  118.             DeleteFile(ref arr4, userInput - 1);
  119.         }
  120.  
  121.         static void DeleteFile(ref string[] arr, int userInput)
  122.         {
  123.             string[] tempArr = new string[arr.Length - 1];
  124.             arr[userInput] = null;
  125.             for (int i = 0; i < arr.Length - 1; i++)
  126.             {
  127.                 if (arr[i] != null)
  128.                 {
  129.                     tempArr[i] = arr[i];
  130.                 }
  131.                 else
  132.                 {
  133.                     tempArr[i] = arr[i+1];
  134.                 }
  135.  
  136.             }
  137.  
  138.             arr = tempArr;
  139.         }
  140.     }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement