Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <string>
  4. using namespace std;
  5.  
  6. class Worker
  7. {
  8. private:
  9. string surname;
  10. string name;
  11. string patronymic;
  12. int department = 0;
  13. string position;
  14. int experience = 0;
  15. public:
  16. Worker* change_worker(Worker* list, int amount)
  17. {
  18. int num;
  19. cout << "Введите номер сотрудника в списке: ";
  20. cin >> num;
  21. SetData(list, num - 1);
  22. system("cls");
  23. return list;
  24. }
  25.  
  26. void GetData(Worker* list, int amount)
  27. {
  28. cout << "№ " << "ФАМИЛИЯ\t\t" << "ИМЯ\t\t" << "ОТЧЕСТВО\t" << "НОМЕР ОТДЕЛА\t" << "ДОЛЖНОСТЬ\t\t" << "ОПЫТ РАБОТЫ" << endl;
  29. for (int i = 0; i < amount; i++)
  30. {
  31. cout << i + 1 << " " << list[i].surname << "\t\t" << list[i].name << "\t\t" << list[i].patronymic << '\t' << list[i].department << "\t\t" << list[i].position << "\t\t" << list[i].experience << endl;
  32. }
  33. cout << endl << endl;
  34. }
  35.  
  36. Worker* list_of_workers(int& amount)
  37. {
  38. int yes_or_not = 1;
  39. Worker* list = 0;
  40. while (yes_or_not == 1)
  41. {
  42. list = add_new(list, amount);
  43. SetData(list, amount);
  44. system("cls");
  45. amount++;
  46. cout << "Продолжить ввод(1 - да, 0 - нет): ";
  47. cin >> yes_or_not;
  48. system("cls");
  49. }
  50. return list;
  51. }
  52.  
  53. Worker* add_new(Worker* list, int amount)
  54. {
  55. if (amount == 0)
  56. {
  57. list = new Worker[amount + 1];
  58. return list;
  59. }
  60. else
  61. {
  62. Worker* templist = new Worker[amount + 1];
  63. for (int i = 0; i < amount; i++)
  64. {
  65. templist[i] = list[i];
  66. }
  67. delete[]list;
  68. return templist;
  69. }
  70. }
  71.  
  72. Worker* add_new_worker(Worker* list, int& amount)
  73. {
  74. list = add_new(list, amount);
  75. SetData(list, amount);
  76. amount++;
  77. system("cls");
  78. return list;
  79. }
  80.  
  81. void show_worker(Worker* list, int amount)
  82. {
  83. string charact, text;
  84. int num;
  85. cout << "Введите характеристику(Фамилия, Имя, Отчество, Номер отдела, Должность, Опыт работы): ";
  86. cin.get();
  87. getline(cin, charact);
  88. if (charact == "Фамилия" || charact == "Имя" || charact == "Отчество" || charact == "Должность")
  89. {
  90. cout << "Введите значение: ";
  91. getline(cin, text);
  92. system("cls");
  93. cout << "№ " << "ФАМИЛИЯ\t\t" << "ИМЯ\t\t" << "ОТЧЕСТВО\t" << "НОМЕР ОТДЕЛА\t" << "ДОЛЖНОСТЬ\t\t" << "ОПЫТ РАБОТЫ" << endl;
  94. for (int i = 0, j = 0; i < amount; i++)
  95. {
  96. if (text == list[i].surname || text == list[i].name || text == list[i].patronymic || text == list[i].position)
  97. {
  98. cout << j + 1 << " " << list[i].surname << "\t\t" << list[i].name << "\t\t" << list[i].patronymic << '\t' << list[i].department << "\t\t" << list[i].position << "\t\t" << list[i].experience << endl;
  99. j++;
  100. }
  101. }
  102. }
  103. else if (charact == "Номер отдела" || charact == "Опыт работы")
  104. {
  105. cout << "Введите значение: ";
  106. cin >> num;
  107. system("cls");
  108. cout << "№ " << "ФАМИЛИЯ\t\t" << "ИМЯ\t\t" << "ОТЧЕСТВО\t" << "НОМЕР ОТДЕЛА\t" << "ДОЛЖНОСТЬ\t\t" << "ОПЫТ РАБОТЫ" << endl;
  109. for (int i = 0, j = 0; i < amount; i++)
  110. {
  111. if (num == list[i].department || num == list[i].experience)
  112. {
  113. cout << j + 1 << " " << list[i].surname << "\t\t" << list[i].name << "\t\t" << list[i].patronymic << '\t' << list[i].department << "\t\t" << list[i].position << "\t\t" << list[i].experience << endl;
  114. j++;
  115. }
  116. }
  117. }
  118. cout << endl << endl;
  119. }
  120.  
  121. Worker* SetData(Worker* list, int amount)
  122. {
  123. cout << "Фамилия: ";
  124. cin >> list[amount].surname;
  125. cout << "Имя: ";
  126. cin >> list[amount].name;
  127. cout << "Отчество: ";
  128. cin >> list[amount].patronymic;
  129. cout << "Номер отдела: ";
  130. cin >> list[amount].department;
  131. cout << "Должность: ";
  132. cin.get();
  133. getline(cin, list[amount].position);
  134. cout << "Опыт работы: ";
  135. cin >> list[amount].experience;
  136. return list;
  137. }
  138.  
  139. Worker* delete_worker(Worker* list, int& amount)
  140. {
  141. int num;
  142. Worker* new_list = new Worker[amount - 1];
  143. cout << "Введите номер сотрудника, которого хотите удалить из списка: ";
  144. cin >> num;
  145. for (int i = 0, j = 0; i < amount; i++)
  146. {
  147. if (i == num - 1)
  148. {
  149. continue;
  150. }
  151. else
  152. {
  153. new_list[j] = list[i];
  154. j++;
  155. }
  156. }
  157. amount--;
  158. delete[]list;
  159. system("cls");
  160. return new_list;
  161. }
  162.  
  163. void ShakerSort(Worker* list, int amount)
  164. {
  165. int left = 0, right = amount - 1, flag = 1;
  166. while ((left < right) && flag > 0)
  167. {
  168. flag = 0;
  169. for (int i = left; i < right; i++)
  170. {
  171. if (list[i].experience > list[i + 1].experience)
  172. {
  173. Worker temp = list[i];
  174. list[i] = list[i + 1];
  175. list[i + 1] = temp;
  176. flag = 1;
  177. }
  178. }
  179. right--;
  180. for (int i = right; i > left; i--)
  181. {
  182. if (list[i - 1].experience > list[i].experience)
  183. {
  184. Worker temp = list[i];
  185. list[i] = list[i - 1];
  186. list[i - 1] = temp;
  187. flag = 1;
  188. }
  189. }
  190. left++;
  191. }
  192. GetData(list, amount);
  193. }
  194.  
  195. void main_task(Worker* list, int amount)
  196. {
  197. cout << "№ " << "ФАМИЛИЯ\t\t" << "ИМЯ\t\t" << "ОТЧЕСТВО\t" << "НОМЕР ОТДЕЛА\t" << "ДОЛЖНОСТЬ\t\t" << "ОПЫТ РАБОТЫ" << endl;
  198. for (int i = 0, j = 0; i < amount; i++)
  199. {
  200. if (list[i].experience > 20)
  201. {
  202. cout << j + 1 << " " << list[i].surname << "\t\t" << list[i].name << "\t\t" << list[i].patronymic << '\t' << list[i].department << "\t\t" << list[i].position << "\t\t" << list[i].experience << endl;
  203. j++;
  204. }
  205. }
  206. cout << endl << endl;
  207. }
  208. };
  209.  
  210. void menu(int& amount);
  211.  
  212. int main()
  213. {
  214. int amount = 0;
  215. SetConsoleCP(1251);
  216. SetConsoleOutputCP(1251);
  217. menu(amount);
  218. return 0;
  219. }
  220.  
  221. void menu(int& amount)
  222. {
  223. int n;
  224. Worker* list = 0;
  225. list = list->list_of_workers(amount);
  226. do {
  227. cout << "1 - Просмотреть список сотрудников" << endl;
  228. cout << "2 - Добавить сотрудников в список" << endl;
  229. cout << "3 - Показать сотрудника с заданным параметром" << endl;
  230. cout << "4 - Изменить данные о сотруднике с заданным параметром" << endl;
  231. cout << "5 - Удалить сотрудника из списка" << endl;
  232. cout << "6 - Отсортировать список сотрудников по опыту работы" << endl;
  233. cout << "7 - Вывести сотрудников, чей опыт работы превышает 20 лет" << endl;
  234. cout << "Введите команду: ";
  235. cin >> n;
  236. system("cls");
  237. switch (n)
  238. {
  239. case 1:
  240. list->GetData(list, amount);
  241. break;
  242. case 2:
  243. list = list->add_new_worker(list, amount);
  244. list->GetData(list, amount);
  245. break;
  246. case 3:
  247. list->show_worker(list, amount);
  248. break;
  249. case 4:
  250. list->GetData(list, amount);
  251. list = list->change_worker(list, amount);
  252. list->GetData(list, amount);
  253. break;
  254. case 5:
  255. list->GetData(list, amount);
  256. list = list->delete_worker(list, amount);
  257. list->GetData(list, amount);
  258. break;
  259. case 6:
  260. list->ShakerSort(list, amount);
  261. break;
  262. case 7:
  263. list->main_task(list, amount);
  264. break;
  265. default: break;
  266. }
  267. } while (n >= 1 && n <= 7);
  268. delete[]list;
  269. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement