Advertisement
GPbl3YH

CSLight #19

Jan 25th, 2021 (edited)
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.16 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 CSLight
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] fullNames = { "Иванов Иван Иванович" };
  14.             string[] positions = { "Программист" };
  15.  
  16.             int userChoice;
  17.             bool isWorking = true;
  18.  
  19.             while (isWorking)
  20.             {
  21.                 Console.WriteLine("1) добавить досье\n2) вывести все досье\n3) удалить досье\n4) поиск по фамилии\n5) выход\n");
  22.                 userChoice = Convert.ToInt32(Console.ReadLine());
  23.                 Console.Clear();
  24.                 switch (userChoice)
  25.                 {
  26.                     case 1:
  27.                         AddDossier(ref fullNames, ref positions);
  28.                         break;
  29.                     case 2:
  30.                         PrintDossier(fullNames, positions);
  31.                         break;
  32.                     case 3:
  33.                         DeleteDossier(ref fullNames, ref positions);
  34.                         break;
  35.                     case 4:
  36.                         Search(fullNames, positions);
  37.                         break;
  38.                     case 5:
  39.                         isWorking = false;
  40.                         break;
  41.                     default:
  42.                         Console.WriteLine("\nПовторите ввод:");
  43.                         break;
  44.                 }
  45.                 Console.ReadKey();
  46.                 Console.Clear();
  47.             }
  48.         }
  49.  
  50.         static void PrintDossier(string[] fullNames, string[] positions)
  51.         {
  52.             Console.WriteLine("Список сотрудников:");
  53.             for (int i = 0; i < fullNames.Length; i++)
  54.             {
  55.                 Console.Write($"{i + 1}. " + fullNames[i] + " - " + positions[i] + "  ");
  56.             }
  57.         }
  58.  
  59.         static void DeleteDossier(ref string[] fullNames, ref string[] positions)
  60.         {
  61.             string fullName;
  62.             int indexForDelete = 0;
  63.  
  64.             string[] tempFullNames = new string[fullNames.Length - 1];
  65.             string[] tempPositions = new string[positions.Length - 1];
  66.  
  67.             Console.WriteLine("Введите инициалы сотрудника: ");
  68.             fullName = Console.ReadLine();
  69.  
  70.             for (int i = 0; i < fullNames.Length; i++)
  71.             {
  72.                 if (fullNames[i].Contains(fullName))
  73.                 {
  74.                     indexForDelete = i;
  75.                 }
  76.             }
  77.  
  78.             for (int i = 0; i < indexForDelete; i++)
  79.             {
  80.                 tempFullNames[i] = fullNames[i];
  81.                 tempPositions[i] = positions[i];
  82.             }
  83.  
  84.             for (int i = indexForDelete + 1; i < fullNames.Length; i++)
  85.             {
  86.                 tempFullNames[i - 1] = fullNames[i];
  87.                 tempPositions[i - 1] = positions[i];
  88.             }
  89.  
  90.             ReplaceArray(ref tempFullNames, ref fullNames, ref tempPositions, ref positions);
  91.         }
  92.  
  93.         static void AddDossier(ref string[] fullNames, ref string[] positions)
  94.         {
  95.             string fullName;
  96.             string position;
  97.  
  98.             string[] tempFullNames = new string[fullNames.Length + 1];
  99.             string[] tempPositions = new string[positions.Length + 1];
  100.  
  101.             Console.WriteLine("Введите ФИО сотрудника:");
  102.             fullName = Console.ReadLine();
  103.             Console.WriteLine("\nВведите должность сотрудника: ");
  104.             position = Console.ReadLine();
  105.  
  106.             for (int i = 0; i < fullNames.Length; i++)
  107.             {
  108.                 tempFullNames[i] = fullNames[i];
  109.                 tempPositions[i] = positions[i];
  110.             }
  111.  
  112.             tempFullNames[tempPositions.Length - 1] = fullName;
  113.             tempPositions[tempPositions.Length - 1] = position;
  114.  
  115.             ReplaceArray(ref tempFullNames, ref fullNames, ref tempPositions, ref positions);
  116.         }
  117.  
  118.         static void ReplaceArray(ref string[] previousFullNames, ref string[] presentFullNames, ref string[] previousPositions, ref string[] presentPositions)
  119.         {
  120.             presentFullNames = previousFullNames;
  121.             presentPositions = previousPositions;
  122.         }
  123.  
  124.         static void Search(string[] fullNames, string[] positions)
  125.         {
  126.             Console.WriteLine("Введите фамилию сотрудника: ");
  127.             string lastName = Console.ReadLine();
  128.  
  129.             for (int i = 0; i < fullNames.Length; i++)
  130.             {
  131.                 if (fullNames[i].Contains(lastName))
  132.                 {
  133.                     Console.WriteLine("\n" + fullNames[i] + " занимает должность " + positions[i]);
  134.                 }
  135.                 else
  136.                 {
  137.                     if (i == fullNames.Length - 1)
  138.                     {
  139.                         Console.WriteLine("\nНет сотрудников с такой фамилией");
  140.                     }
  141.                 }
  142.             }
  143.         }
  144.     }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement