Advertisement
SnowPhoenix347

4.1

Nov 5th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.61 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[] fio = new string[0];
  10.             string[] post = new string[0];
  11.  
  12.             bool exit = false;
  13.  
  14.             while (!exit)
  15.             {
  16.                 ShowMenu();
  17.                 switch (MenuInput())
  18.                 {
  19.                     case '1':
  20.                         Console.Write("Введите ФИО через пробел: ");
  21.                         AddNewFile(ref fio, Console.ReadLine());
  22.                         Console.Write("Введите пост: ");
  23.                         AddNewFile(ref post, Console.ReadLine());
  24.                         break;
  25.                     case '2':
  26.                         ShowAllFiles(fio, post);
  27.                         Console.ReadKey();
  28.                         break;
  29.                     case '3':
  30.                         Console.Write($"Выбрать досье: \n");
  31.                         ShowAllFiles(fio, post);
  32.                         SelectFileForDelete(ref fio,  ref post, ConvertToInt());
  33.                         break;
  34.                     case '4':
  35.                         Console.Write("Введите фамилию: ");
  36.                         FindFile(Console.ReadLine(), fio, post);
  37.                         Console.ReadKey();
  38.                         break;
  39.                     case '5':
  40.                         exit = true;
  41.                         break;
  42.                     default:
  43.                         Console.WriteLine("Incorrect enter");
  44.                         break;
  45.                 }
  46.  
  47.                 Console.Clear();
  48.             }
  49.         }
  50.  
  51.         static void ShowMenu()
  52.         {
  53.             Console.WriteLine("\tMenu\n" +
  54.                               "1. Add new file\n" +
  55.                               "2. Show all files\n" +
  56.                               "3. Delete file\n" +
  57.                               "4. Find file\n" +
  58.                               "5. Exit");
  59.         }
  60.  
  61.         static char MenuInput()
  62.         {
  63.             char menuInput = Console.ReadKey(true).KeyChar;
  64.             return menuInput;
  65.         }
  66.  
  67.         static void AddNewFile(ref string[] arr, string str)
  68.         {
  69.             string[] tempArr = new string[arr.Length + 1];
  70.             for (int i = 0; i < arr.Length; i++)
  71.             {
  72.                 tempArr[i] = arr[i];
  73.             }
  74.            
  75.             tempArr[tempArr.Length - 1] = str;
  76.            
  77.             arr = tempArr;
  78.         }
  79.  
  80.         static void ShowAllFiles(string[] arr, string[] arr2)
  81.         {
  82.             if (arr.Length == 0)
  83.             {
  84.                 Console.WriteLine("Empty list");
  85.             }
  86.             else
  87.             {
  88.                 for (int i = 0; i < arr.Length; i++)
  89.                 {
  90.                     Console.WriteLine($"{i + 1}. {arr[i]} - {arr2[i]}");
  91.                 }
  92.             }
  93.         }
  94.  
  95.         static void FindFile(string surname, string[] arr, string[] arr2)
  96.         {
  97.             for (int i = 0; i < arr.Length; i++)
  98.             {
  99.                 string[] tempArr = arr[i].Split(' ');
  100.                 if (tempArr[1].ToLower() == surname.ToLower())
  101.                 {
  102.                     Console.WriteLine($"{i + 1}. {arr[i]} - {arr2[i]}");
  103.                 }
  104.             }
  105.         }
  106.        
  107.         static void SelectFileForDelete(ref string[] arr, ref string[] arr2, int userInput)
  108.         {
  109.            
  110.             DeleteFile(ref arr, userInput - 1);
  111.             DeleteFile(ref arr2, userInput - 1);
  112.         }
  113.  
  114.         static void DeleteFile(ref string[] arr, int userInput)
  115.         {
  116.             string[] tempArr = new string[arr.Length - 1];
  117.             arr[userInput] = null;
  118.             for (int i = 0; i < arr.Length - 1; i++)
  119.             {
  120.                 if (arr[i] != null)
  121.                 {
  122.                     tempArr[i] = arr[i];
  123.                 }
  124.                 else
  125.                 {
  126.                     tempArr[i] = arr[i+1];
  127.                 }
  128.  
  129.             }
  130.  
  131.             arr = tempArr;
  132.         }
  133.         static int ConvertToInt()
  134.         {
  135.             Console.WriteLine("Enter file number");
  136.             int output;
  137.             bool enterIsCorrect = false;
  138.             do
  139.             {
  140.                 string input = Console.ReadLine();
  141.                 enterIsCorrect = int.TryParse(input, out output);
  142.                 if (!enterIsCorrect)
  143.                 {
  144.                     Console.WriteLine("Error enter. Try again");
  145.                 }
  146.             } while (!enterIsCorrect);
  147.  
  148.             return output;
  149.         }
  150.     }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement