Advertisement
AlexRaynor

4.1 HR

Sep 18th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp17
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] namesArray = { " Иванов А.А.", " Петров Б.Б. ", " Стрелков В.В." };
  14.             string[] positionArray = { " Наемник", " Торговец", " Алхимик" };
  15.             int UserInput;
  16.             String NewName;
  17.             String NewPosition;
  18.             bool needToExit = false;
  19.  
  20.             while (needToExit == false)
  21.             {
  22.                 Console.WriteLine("\nДоступные команды:\n1 - добавить досье  \n2 - вывести все досье \n3 - удалить досье  \n4 - выход ");
  23.                 UserInput = int.Parse(Console.ReadLine());
  24.                 switch (UserInput)
  25.                 {
  26.                     case 1:
  27.                         Console.WriteLine("Введите ФИО");
  28.                         NewName = Console.ReadLine();
  29.                         namesArray = ExpandArray(namesArray, NewName);
  30.                         Console.WriteLine("Введите должность");
  31.                         NewPosition = Console.ReadLine();
  32.                         positionArray = ExpandArray(positionArray, NewPosition);
  33.  
  34.                         break;
  35.                     case 2:
  36.                         if (namesArray.Length > 0 && positionArray.Length > 0)
  37.                         {
  38.                             Console.WriteLine("");
  39.                             DisplayArray(namesArray, positionArray);
  40.                         }
  41.                         else
  42.                         {
  43.                             Console.WriteLine("Досье пусты...");
  44.                         }
  45.  
  46.                         break;
  47.                     case 3:
  48.                         if (namesArray.Length > 0 && positionArray.Length > 0)
  49.                         {
  50.                             namesArray = DecreaseArray(namesArray);
  51.                             positionArray = DecreaseArray(positionArray);
  52.                             Console.WriteLine("Удалено последнее досье с конца списка");
  53.                         }
  54.                         else
  55.                         {
  56.                             Console.WriteLine("Досье пусты...");
  57.                         }
  58.  
  59.                         break;
  60.                     case 4:
  61.                         Console.WriteLine("Выход из программы...");
  62.                         needToExit = true;
  63.                         break;
  64.  
  65.                     default:
  66.                         Console.WriteLine("Выберите одну из 4х команд");
  67.                         break;
  68.                 }
  69.  
  70.  
  71.             }
  72.  
  73.  
  74.         }
  75.  
  76.  
  77.         static string[] ExpandArray(string[] arrays, string arrayElement)
  78.         {
  79.             string[] tempArray = new string[arrays.Length + 1];
  80.             for (int i = 0; i < arrays.Length; i++)
  81.             {
  82.                 tempArray[i] = arrays[i];
  83.             }
  84.             tempArray[tempArray.Length - 1] = " " + arrayElement;
  85.  
  86.             arrays = tempArray;
  87.  
  88.             return arrays;
  89.  
  90.  
  91.         }
  92.  
  93.         static void DisplayArray (string[] arrays, string[] addArrays)
  94.         {
  95.  
  96.             for (int i = 0; i < arrays.Length; i++)
  97.             {
  98.                 Console.WriteLine((i+1) + ". - " + arrays[i] + " -" + addArrays[i]);  
  99.             }
  100.  
  101.  
  102.         }
  103.  
  104.         static string[] DecreaseArray(string[] arrays)
  105.         {
  106.             string[] tempArray = new string[arrays.Length - 1];
  107.             for (int i = 0; i < (arrays.Length - 1); i++)
  108.             {
  109.                 tempArray[i] = arrays[i];
  110.             }
  111.  
  112.             arrays = tempArray;
  113.  
  114.             return arrays;
  115.  
  116.  
  117.         }
  118.  
  119.  
  120.  
  121.  
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement