Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.06 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 Task1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.SetWindowSize(100, 55);
  14.  
  15.             string[] fullNames = new string[0];
  16.             string[] posts = new string[0];
  17.  
  18.             string[] fullNamesStaff = new string[]
  19.             {
  20.                 "Колесников Андрей Викторович",
  21.                 "Кондратьев Владимир Сергеевич",
  22.                 "Соловьёв Михаил Юрьевич",
  23.                 "Максимов Александр Константинович",
  24.                 "Петров Илья Валерьеви"
  25.             };
  26.             string[] postsStaff = new string[]
  27.             {
  28.                 "CEO",
  29.                 "Project Manager",
  30.                 "Middle developer",
  31.                 "Junior developer",
  32.                 "QA tester"
  33.             };
  34.  
  35.             string command = "";
  36.  
  37.             while (command != "/exit")
  38.             {
  39.                 Console.WriteLine("Меню. Выберите команду");
  40.                 Console.WriteLine("/add - добавить досье\n/addstaff - добавить штатных сотрудников" +
  41.                                   "\n/remove - удалить досье\n/show - вывести все досье" +
  42.                                   "\n/search - поиск досье по фамилии\n/exit - выход из программы");
  43.  
  44.                 command = Console.ReadLine().ToLower();
  45.  
  46.                 if (command == "/add")
  47.                 {
  48.                     Console.WriteLine("Введите ФИО:");
  49.                     string fullName = Console.ReadLine();
  50.  
  51.                     Console.WriteLine($"Введите должность сотрудника: {fullName}");
  52.                     string post = Console.ReadLine();
  53.  
  54.                     fullNames = Add(fullNames, fullName);
  55.                     posts = Add(posts, post);
  56.  
  57.                     Console.Clear();
  58.  
  59.                 }
  60.                 else if(command == "/addstaff")
  61.                 {
  62.                     Console.Clear();
  63.  
  64.                     fullNames = Add(fullNames, fullNamesStaff);
  65.                     posts = Add(posts, postsStaff);
  66.                 }
  67.                 else if (command == "/remove")
  68.                 {
  69.                     Console.WriteLine("Введите ФИО сотрудника которого вы хотите удалить");
  70.                     string remove = Console.ReadLine();
  71.  
  72.                     int indexRemove;
  73.                     fullNames = Remove(fullNames, remove, out indexRemove);
  74.  
  75.                     posts = Remove(posts, posts[indexRemove], out indexRemove);
  76.  
  77.                     Console.Clear();
  78.                 }
  79.                 else if (command == "/show")
  80.                 {
  81.                     Console.Clear();
  82.  
  83.                     Show(fullNames, posts);
  84.                 }
  85.                 else if (command == "/search")
  86.                 {
  87.  
  88.                 }
  89.                 else
  90.                 {
  91.  
  92.                     Console.ForegroundColor = ConsoleColor.Red;
  93.                     Console.WriteLine("Такой команды нет!");
  94.                     Console.ResetColor();
  95.                 }
  96.             }
  97.         }
  98.  
  99.         //------------------------------------------------------------------------------------------------------
  100.  
  101.         static string[] Add(string[] array, string addedElement)
  102.         {
  103.             string[] tempArray = new string[array.Length + 1];
  104.  
  105.             for (int i = 0; i < array.Length; i++)
  106.             {
  107.                 tempArray[i] = array[i];
  108.             }
  109.             tempArray[tempArray.Length - 1] = addedElement;
  110.  
  111.             return tempArray;
  112.  
  113.         }
  114.  
  115.         static string[] Add(string[] array, string[] addedArray)
  116.         {
  117.             string[] tempArray = new string[array.Length + addedArray.Length];
  118.             int tempIndex = 0;
  119.             for (int i = 0; i < array.Length; i++)
  120.             {
  121.                 tempArray[i] = array[i];
  122.                 tempIndex = i + 1;
  123.             }
  124.             for (int i = 0; i < addedArray.Length; i++)
  125.             {
  126.                 tempArray[tempIndex + i] = addedArray[i];
  127.             }
  128.  
  129.             return tempArray;
  130.         }
  131.  
  132.         static string[] Remove(string[] array, string remove, out int indexRemove)
  133.         {
  134.             string[] tempArray = new string[array.Length - 1];
  135.             int tempIndex = 0;
  136.  
  137.             for (int i = 0; i < array.Length; i++)
  138.             {
  139.                 if(array[i] != remove)
  140.                 {
  141.                     tempArray[i] = array[i];
  142.                 }
  143.                 else
  144.                 {
  145.                     tempIndex = i;
  146.                     break;
  147.                 }
  148.             }
  149.  
  150.             for (int i = tempIndex; i < array.Length - 1; i++)
  151.             {
  152.                 tempArray[i] = array[i + 1];
  153.             }
  154.  
  155.             indexRemove = tempIndex;
  156.  
  157.             return tempArray;
  158.         }
  159.  
  160.         static void Search()
  161.         {
  162.  
  163.         }
  164.  
  165.         static void Show(string[] fullNames, string[] posts, int left = 0, int top = 15)
  166.         {
  167.             Console.SetCursorPosition(left, top);
  168.  
  169.             Console.ForegroundColor = ConsoleColor.Green;
  170.  
  171.             if (fullNames.Length == posts.Length)
  172.             {
  173.                 for (int i = 0; i < fullNames.Length; i++)
  174.                 {
  175.                     Console.WriteLine($"{i + 1}. {fullNames[i]} - {posts[i]}");
  176.                 }
  177.             }
  178.             else
  179.             {
  180.                 Console.ForegroundColor = ConsoleColor.Red;
  181.                 Console.WriteLine("Кол-во ФИО и должностей должны быть одинаковыми!");
  182.                 Console.ResetColor();
  183.             }
  184.  
  185.             Console.ResetColor();
  186.  
  187.             Console.SetCursorPosition(0, 0);
  188.         }
  189.     }
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement