Advertisement
MaoChessy

Task 19

Oct 30th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace C_sharp_Light
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] name = new string[0];
  11.             string[] post = new string[0];
  12.             bool isOpen = true;
  13.             while (isOpen)
  14.             {
  15.                 Console.WriteLine("Программа досье\nУправление:\n1) Добавить досье\n2) Вывести все досье\n3) Удалить досье по номеру(не индекс массива)\n4) Поиск по фамилии \n0) Выход\n\n");
  16.                 ConsoleKeyInfo key = Console.ReadKey();
  17.                 Console.Clear();
  18.                 switch (key.Key)
  19.                 {
  20.                     case ConsoleKey.D1:
  21.                         AddDossier(ref name, ref post);
  22.                         break;
  23.                     case ConsoleKey.D2:
  24.                         WriteAllDossier(name, post);
  25.                         break;
  26.                     case ConsoleKey.D3:
  27.                         DeletDossier(ref name, ref post);
  28.                         break;
  29.                     case ConsoleKey.D4:
  30.                         SearchByLastName(name);
  31.                         break;
  32.                     case ConsoleKey.D0:
  33.                         isOpen = false;
  34.                         break;
  35.                 }
  36.             }
  37.         }
  38.         static void AddDossier(ref string[] name, ref string[] post)
  39.         {
  40.             Console.Write("Введите имя = ");
  41.             string nameTemp = Console.ReadLine();
  42.             Console.Write("Введите должность = ");
  43.             string postTemp = Console.ReadLine();
  44.  
  45.             name = ResizeArray(name);
  46.             post = ResizeArray(post);
  47.  
  48.             name[name.Length - 1] = nameTemp;
  49.             post[post.Length - 1] = postTemp;
  50.             Console.WriteLine("\n\nУдачное добавление!");
  51.             Console.ReadKey();
  52.             Console.Clear();
  53.         }
  54.         static void WriteAllDossier(string[] name, string[] post)
  55.         {
  56.             for (int i = 0; i < name.Length; i++)
  57.             {
  58.                 Console.Write($"{i + 1} - ");
  59.                 Console.SetCursorPosition(6, i);
  60.                 Console.Write($"Имя: {name[i]}");
  61.                 Console.SetCursorPosition(24, i);
  62.                 Console.Write($"Должность: {post[i]}");
  63.                 Console.WriteLine();
  64.             }
  65.             Console.ReadKey();
  66.             Console.Clear();
  67.         }
  68.         static void SearchByLastName(string[] name)
  69.         {
  70.             Console.Clear();
  71.             Console.Write("Введите фамилию: ");
  72.             string searchName = Console.ReadLine();
  73.             searchName.ToLower();
  74.             Console.WriteLine("\n\n");
  75.  
  76.             int[] result = new int[0];
  77.  
  78.             for (int i = 0; i < name.Length; i++)
  79.             {
  80.                 string temp = name[i];
  81.                 temp.ToLower();
  82.                 if (temp == searchName)
  83.                 {
  84.                     result = ResizeArray(result);
  85.                     result[result.Length - 1] = i;
  86.                 }
  87.             }
  88.             Console.WriteLine("Следующие номера имеют искоемую фамилю:");
  89.             for (int i = 0; i < result.Length; i++)
  90.             {
  91.                 Console.Write($"{i}  ");
  92.                 if (i % 3 == 0 && i != 0)
  93.                     Console.WriteLine();
  94.             }
  95.             Console.ReadKey();
  96.             Console.Clear();
  97.         }
  98.         static void DeletDossier(ref string[] name, ref string[] post)
  99.         {
  100.             Console.Clear();
  101.             Console.Write("Введите номер для удаления: ");
  102.             int number = Convert.ToInt32(Console.ReadLine());
  103.             number--;
  104.             name = DeResizeArray(name, number);
  105.             post = DeResizeArray(post, number);
  106.             Console.Clear();
  107.         }
  108.         static public string[] DeResizeArray(string[] array, int number)
  109.         {
  110.             string[] tempArray = new string[array.Length - 1];
  111.             for (int i = 0; i < array.Length; i++)
  112.             {
  113.                 if (i != number)
  114.                     tempArray[i] = array[i];
  115.             }
  116.             return tempArray;
  117.         }
  118.         static public string[] ResizeArray(string[] array)
  119.         {
  120.             string[] tempArray = new string[array.Length + 1];
  121.             for (int i = 0; i < array.Length; i++)
  122.             {
  123.                 tempArray[i] = array[i];
  124.             }
  125.             return tempArray;
  126.         }
  127.         static public int[] ResizeArray(int[] array)
  128.         {
  129.             int[] tempArray = new int[array.Length + 1];
  130.             for (int i = 0; i < array.Length; i++)
  131.             {
  132.                 tempArray[i] = array[i];
  133.             }
  134.             return tempArray;
  135.         }
  136.     }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement