Advertisement
Briotar

Homework 4

May 11th, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.01 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Homework4
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string[] fullname = new string[1];
  10.             string[] position = new string[1];
  11.             bool isMenu = true;
  12.             int userInput;
  13.             string newFullname;
  14.             string newPosition;
  15.             string fullnameSearch;
  16.             int numberDossierDelete;
  17.  
  18.             while (isMenu)
  19.             {
  20.                 Console.WriteLine("\nПриветствуем вас в меню!");
  21.                 Console.WriteLine("1 - Добавить досье\n2 - Вывод всех досье\n" +
  22.                     "3 - Удалить досье\n4 - Поиск по фамилли\n5 - Выход");
  23.                 userInput = Convert.ToInt32(Console.ReadLine());
  24.                
  25.                 switch(userInput)
  26.                 {
  27.                     case 1:
  28.                         Console.Write("Введите ФИО - ");
  29.                         newFullname = Console.ReadLine();
  30.                         Console.Write("Введите должность - ");
  31.                         newPosition = Console.ReadLine();
  32.  
  33.                         FillingDossier(ref fullname,ref position, newFullname, newPosition);
  34.                         break;
  35.  
  36.                     case 2:
  37.                         PrintDossier(fullname, position);
  38.                         break;
  39.  
  40.                     case 3:
  41.                         Console.WriteLine($"Введите номер досье для удаления, номер последнего имеющего досье - {fullname.Length-1} ");
  42.                         numberDossierDelete = Convert.ToInt32(Console.ReadLine());
  43.  
  44.                         if(numberDossierDelete < 1 || numberDossierDelete > fullname.Length - 1)
  45.                         {
  46.                             Console.WriteLine($"Нужно было ввести цифру от 1 до {fullname.Length - 1}");
  47.                         }
  48.                         else
  49.                         {
  50.                             DeleteDossier(ref fullname, ref position, numberDossierDelete);
  51.                             PrintDossier(fullname, position);
  52.                         }
  53.                         break;
  54.  
  55.                     case 4:
  56.                         Console.Write("Введите фамилию сотрудника, которого хотите найти - ");
  57.                         fullnameSearch = Console.ReadLine();
  58.  
  59.                         SearchDossier(fullname, position ,fullnameSearch);
  60.                         break;
  61.  
  62.                     case 5:
  63.                         isMenu = false;
  64.                         break;
  65.  
  66.                     default:
  67.                         Console.WriteLine("Вы ввели что-то не то!");
  68.                         break;
  69.                 }
  70.             }
  71.         }
  72.  
  73.         static void FillingDossier(ref string[] fullname,ref string[] position, string newFullname, string newPosition)
  74.         {
  75.             string[] tempFullname = new string[fullname.Length+1];
  76.             string[] tempPosition = new string[position.Length+1];
  77.  
  78.             for(int i = 0; i < fullname.Length; i++)
  79.             {
  80.                 tempFullname[i] = fullname[i];
  81.                 tempPosition[i] = position[i];
  82.             }
  83.             fullname = tempFullname;
  84.             position = tempPosition;
  85.             fullname[fullname.Length - 1] = newFullname;
  86.             position[position.Length - 1] = newPosition;
  87.  
  88.         }
  89.  
  90.         static void PrintDossier(string[] fullname, string[] position)
  91.         {
  92.             for(int i = 1; i < fullname.Length; i++)
  93.             {
  94.                 Console.Write($"- {i} {fullname[i]} {position[i]} ");
  95.             }
  96.         }
  97.  
  98.         static void DeleteDossier(ref string[] fullname,ref string[] position, int numberDossierDelete)
  99.         {
  100.             string[] tempFullname = new string[fullname.Length-1];
  101.             string[] tempPosition = new string[position.Length-1];
  102.  
  103.             for (int i = numberDossierDelete; i < fullname.Length-1; i++ )
  104.             {
  105.                 fullname[i] = fullname[i + 1];
  106.                 position[i] = position[i + 1];
  107.             }
  108.  
  109.             for (int i = 0; i < fullname.Length-1; i++)
  110.             {
  111.                 tempFullname[i] = fullname[i];
  112.                 tempPosition[i] = position[i];
  113.             }
  114.             fullname = tempFullname;
  115.             position = tempPosition;
  116.         }
  117.  
  118.         static void SearchDossier(string[] fullname, string[] position, string fullnameSearch)
  119.         {
  120.  
  121.             for (int i = 1; i < fullname.Length; i++)
  122.             {
  123.                 string[] splitFullname = fullname[i].Split(' ');
  124.  
  125.                 if(fullnameSearch.ToLower() == splitFullname[0].ToLower())
  126.                 {
  127.                     Console.WriteLine($"Сотрудник - {fullname[i]}, должность - {position[i]}");
  128.                     break;
  129.                 }
  130.             }
  131.  
  132.         }
  133.     }
  134. }
  135.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement