W1thr

Функции-1

Feb 19th, 2021 (edited)
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.08 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Homework1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string[] initials = new string[0];
  10.             string[] placeOfWork = new string[0];
  11.  
  12.             bool isActive = true;
  13.  
  14.             while (isActive)
  15.             {
  16.                 Console.WriteLine("1) добавить досье\n" +
  17.                 "2) вывести все досье\n" +
  18.                 "3) удалить досье\n" +
  19.                 "4) поиск по фамилии\n" +
  20.                 "5) выход");
  21.  
  22.                 string userInput = Console.ReadLine();
  23.  
  24.                 Console.Clear();
  25.  
  26.                 switch (userInput)
  27.                 {
  28.                     case "1":
  29.                         AddDossier(ref initials, ref placeOfWork);
  30.  
  31.                         break;
  32.                     case "2":
  33.                         ShowDossier(initials, placeOfWork);
  34.  
  35.                         break;
  36.                     case "3":
  37.                         DeleteDossier(ref initials, ref placeOfWork);
  38.  
  39.                         break;
  40.                     case "4":
  41.                         FindBySurname(initials, placeOfWork);
  42.  
  43.                         break;
  44.                     case "5":
  45.                         isActive = false;
  46.                         break;
  47.                     default:
  48.                         Console.WriteLine("Нет такого пункта меню");
  49.                         break;
  50.                 }
  51.                 ClearConsole();
  52.             }
  53.         }
  54.  
  55.         static void AddDossier(ref string[] initials, ref string[] placeOfWork)
  56.         {
  57.             Console.WriteLine("Добавить досье");
  58.  
  59.             Console.Write("Введите ФИО: ");
  60.             AddElement(ref initials);
  61.  
  62.             Console.Write("Введите место работы: ");
  63.             AddElement(ref placeOfWork);
  64.  
  65.             Console.WriteLine("Новое досье: " + initials[initials.Length - 1] + " - " + placeOfWork[placeOfWork.Length - 1]);
  66.         }
  67.         static void AddElement(ref string[] array)
  68.         {
  69.             string[] tempArray = new string[array.Length + 1];
  70.             string userInput = Console.ReadLine();
  71.  
  72.             for (int i = 0; i < array.Length; i++)
  73.             {
  74.                 tempArray[i] = array[i];
  75.             }
  76.             tempArray[tempArray.Length - 1] = userInput;
  77.  
  78.             array = tempArray;
  79.         }
  80.  
  81.         static void ShowDossier(string[] initials, string[] placeOfWork)
  82.         {
  83.             Console.WriteLine("---ВСЕ ДОСЬЕ---");
  84.             for (int i = 1; i < initials.Length + 1; i++)
  85.             {
  86.                 Console.WriteLine($"{i}. {initials[i - 1]} - {placeOfWork[i - 1]}");
  87.             }
  88.         }
  89.  
  90.         static void DeleteDossier(ref string[] initials, ref string[] placeOfWork)
  91.         {
  92.             Console.Write("Введите номер досье, которое хотите удалить:");
  93.             string numberToDelete = Console.ReadLine();
  94.  
  95.             if (int.TryParse(numberToDelete, out int result))
  96.             {
  97.                 if (result > 0 && result <= initials.Length)
  98.                 {
  99.                     DeleteElement(ref initials, result);
  100.                     DeleteElement(ref placeOfWork, result);
  101.                 }
  102.                 else
  103.                 {
  104.                     Console.WriteLine("Такого досье нет!");
  105.                 }
  106.             }
  107.             else
  108.             {
  109.                 Console.WriteLine("Это не номер!");
  110.             }
  111.         }
  112.  
  113.         static void DeleteElement(ref string[] array, int numberToDelete)
  114.         {
  115.             string[] tempArray = new string[array.Length - 1];
  116.  
  117.             for (int i = 0; i < numberToDelete; i++)
  118.             {
  119.                 tempArray[i] = array[i];
  120.             }
  121.  
  122.             for (int i = numberToDelete; i < array.Length; i++)
  123.             {
  124.                 tempArray[i - 1] = array[i];
  125.             }
  126.  
  127.             array = tempArray;
  128.         }
  129.  
  130.         static void FindBySurname(string[] initials, string[] placeOfWork)
  131.         {
  132.             Console.Write("Введите ФИО:");
  133.             string userInput = Console.ReadLine();
  134.  
  135.             bool noMatch = true;
  136.  
  137.             for (int i = 0; i < initials.Length; i++)
  138.             {
  139.                 if (userInput.ToLower() == initials[i].ToLower())
  140.                 {
  141.                     Console.WriteLine($"{i + 1}. {initials[i]} - {placeOfWork[i]}");
  142.                     noMatch = false;
  143.                 }
  144.             }
  145.  
  146.             if (noMatch)
  147.             {
  148.                 Console.WriteLine("Неверное ФИО.");
  149.             }
  150.         }
  151.  
  152.         static bool Exit()
  153.         {
  154.             Console.WriteLine("Выход...");
  155.             return false;
  156.         }
  157.  
  158.         static void ClearConsole()
  159.         {
  160.             Console.WriteLine("Для продолжения нажмите любую клавишу...");
  161.             Console.ReadKey();
  162.             Console.Clear();
  163.         }
  164.     }
  165. }
  166.  
Add Comment
Please, Sign In to add comment