Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.83 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string [] namesArray = new string [0];
  10.             string [] positionsArray = new string [0];
  11.             string userInput;
  12.  
  13.             do
  14.             {
  15.                 Console.WriteLine("1. Добавить досье");
  16.                 Console.WriteLine("2. Вывести все досье");
  17.                 Console.WriteLine("3. Удалить досье");
  18.                 Console.WriteLine("4. Выход");
  19.  
  20.                 Console.WriteLine("Введите нужный пункт меню");
  21.                 userInput = Console.ReadLine();
  22.  
  23.                 switch (userInput)
  24.                 {
  25.                     case "1":
  26.                         AddNewDosje(ref namesArray, ref positionsArray);
  27.                         Console.Clear();
  28.                         break;
  29.  
  30.                     case "2":
  31.                         PrintDosje(namesArray, positionsArray);
  32.                         break;
  33.  
  34.                     case "3":
  35.                         DeleteDosje(ref namesArray, ref positionsArray);
  36.                         break;
  37.  
  38.                     case "4":
  39.                         break;
  40.                 }
  41.  
  42.             } while (userInput != "4");
  43.  
  44.         }
  45.  
  46.         static void AddNewDosje( ref string[] namesArray, ref string[] positionsArray)
  47.         {
  48.  
  49.             Console.WriteLine("Введите Фамилию Имя Отчество\n");
  50.             string name = Console.ReadLine();
  51.  
  52.             Console.WriteLine("Введите должность\n");
  53.             string position = Console.ReadLine();
  54.  
  55.             string[] tempNamesArray = new string[namesArray.Length + 1];
  56.            
  57.             for (int i = 0; i < namesArray.Length; i++)
  58.             {
  59.                 tempNamesArray[i] = namesArray[i];
  60.             }
  61.  
  62.             namesArray = tempNamesArray;
  63.             namesArray[namesArray.Length - 1] = name;
  64.  
  65.             string[] tempPositionsArray = new string[positionsArray.Length + 1];
  66.            
  67.             for (int i = 0; i < positionsArray.Length; i++)
  68.             {
  69.                 tempPositionsArray[i] = positionsArray[i];
  70.             }
  71.  
  72.             positionsArray = tempPositionsArray;
  73.             positionsArray[positionsArray.Length - 1] = position;
  74.         }
  75.  
  76.         static void PrintDosje(string[] namesArray, string[] positionsArray)
  77.         {
  78.             Console.Clear();
  79.  
  80.             for (int i = 0; i < namesArray.Length; i++)
  81.             {
  82.                
  83.                 Console.WriteLine((i + 1) + ". " + namesArray[i] + " - " + positionsArray[i]);
  84.             }
  85.  
  86.             Console.ReadLine();
  87.             Console.Clear();
  88.         }
  89.  
  90.         static void DeleteDosje(ref string[] namesArray, ref string[] positionsArray)
  91.         {
  92.             Console.WriteLine("Введите Фамилию человека, досье которого вы хотите удалить\n");
  93.             string name = Console.ReadLine();
  94.  
  95.             for (int i = 0; i < namesArray.Length; i++)
  96.             {
  97.                 if (namesArray[i] == name)
  98.                 {
  99.                     Console.WriteLine("Досье найдено !\n");
  100.                     Console.WriteLine((i + 1) + ". " + namesArray[i] + " - " + positionsArray[i] +"\n");
  101.                     Console.WriteLine("Нажмите Enter, чтобы удалить досье");
  102.                     Console.ReadLine();
  103.  
  104.                     namesArray[i] = null;
  105.                     positionsArray[i] = null;
  106.  
  107.                     Console.WriteLine("Досье удалено !\n");
  108.                     Console.WriteLine("Для выхода в меню нажмите Enter");
  109.                     Console.ReadLine();
  110.                 }
  111.             }
  112.         }
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement