Advertisement
TargeTPoweR

Dossier2

Mar 30th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 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 Tasks
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string[] name = { "Петров Анатолий Поликарпович", "Сидоров Святослав Иванович" };
  14. string[] position = { "Завхоз", "Большая насяльника" };
  15. bool exit = true;
  16.  
  17. MenuDraw();
  18.  
  19. while (exit)
  20. {
  21. int userInput = Convert.ToInt32(Console.ReadLine());
  22.  
  23. switch (userInput)
  24. {
  25. case 1:
  26. Console.Clear();
  27. Console.WriteLine("Введите ФИО: ");
  28. AddDossier(ref name);
  29. Console.WriteLine("Введите должность: ");
  30. AddDossier(ref position);
  31. MenuDraw();
  32. break;
  33. case 2:
  34. Console.Clear();
  35. WriteDossiers(name, position);
  36. MenuDraw();
  37. break;
  38. case 3:
  39. Console.Clear();
  40. Console.WriteLine("Введите порядковый номер удаляемого досье.");
  41. int deleteNumber = Convert.ToInt32(Console.ReadLine());
  42. DeleteDossier(ref name, deleteNumber);
  43. DeleteDossier(ref position, deleteNumber);
  44. MenuDraw();
  45. break;
  46. case 4:
  47. Console.Clear();
  48. FindDossier(name, position);
  49. MenuDraw();
  50. break;
  51. case 5:
  52. exit = false;
  53. break;
  54. default:
  55. Console.WriteLine("Такой команды нет.");
  56. break;
  57. }
  58. }
  59. }
  60.  
  61. static void AddDossier(ref string[] increasingArray)
  62. {
  63. Array.Resize(ref increasingArray, increasingArray.Length + 1);
  64. string newInput = Console.ReadLine();
  65. increasingArray[increasingArray.Length - 1] = newInput;
  66. }
  67.  
  68. static void WriteDossiers(string[] showNameArray, string[] showPositionArray)
  69. {
  70. for (int i = 0; i < showNameArray.Length; i++)
  71. {
  72. Console.Write(i + 1 + " ");
  73. Console.Write(showNameArray[i] + "-");
  74. Console.Write(showPositionArray[i] + ". ");
  75. }
  76. Console.WriteLine("");
  77. }
  78.  
  79. static void DeleteDossier(ref string[] decreasingArray, int removableDossierIndex)
  80. {
  81. if (removableDossierIndex < 1 || removableDossierIndex > decreasingArray.Length)
  82. {
  83. Console.WriteLine("Досье с таким номером не существует!");
  84. }
  85. else
  86. {
  87. string[] newName = new string[decreasingArray.Length - 1];
  88. for (int i = 0; i < decreasingArray.Length; i++)
  89. {
  90. if (i < (removableDossierIndex - 1))
  91. {
  92. newName[i] = decreasingArray[i];
  93. }
  94. else if (i > (removableDossierIndex - 1))
  95. {
  96. newName[i - 1] = decreasingArray[i];
  97. }
  98. }
  99. decreasingArray = newName;
  100. }
  101. }
  102.  
  103. static void FindDossier(string[] arrayForSearching, string[] arrayToShowPosition)
  104. {
  105. Console.WriteLine("Введите фамилию");
  106. string secondNameInput = Console.ReadLine();
  107. string secondName = secondNameInput.ToLower();
  108. bool secondNameFound = false;
  109.  
  110. for (int i = 0; i < arrayForSearching.Length; i++)
  111. {
  112. bool comparision = arrayForSearching[i].ToLower().Contains(secondName);
  113.  
  114. if (comparision == true)
  115. {
  116. Console.WriteLine(i + 1 + "." + arrayForSearching[i] + "." + arrayToShowPosition[i]);
  117. secondNameFound = true;
  118. break;
  119. }
  120. }
  121. if (secondNameFound == false)
  122. {
  123. Console.WriteLine("Такого сотрудника нетЮ.");
  124. }
  125. }
  126.  
  127. static void MenuDraw()
  128. {
  129. Console.WriteLine();
  130. Console.WriteLine("Здравствуйте, что вы хотите сделать?");
  131. Console.WriteLine("1 - добавить досье.");
  132. Console.WriteLine("2 - вывести все досье.");
  133. Console.WriteLine("3 - удалить досье.");
  134. Console.WriteLine("4 - найти работника по фамилии.");
  135. Console.WriteLine("5 - выход.");
  136. }
  137. }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement