Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const string right_login = "3151020";
  6. const string right_password = "1e9a228F15";
  7. const string retiree_age = "21.04.1959";
  8.  
  9. // 21.04.2019
  10.  
  11. class Worker
  12. {
  13. string name;
  14. string date_of_birth;
  15. string department_name;
  16. string position;
  17. string beginning_date;
  18. public:
  19. Worker(string name, string date_of_birth, string department_name, string position, string beginning_date)
  20. {
  21. this->name = name;
  22. this->date_of_birth = date_of_birth;
  23. this->department_name = department_name;
  24. this->position = position;
  25. this->beginning_date = beginning_date;
  26. }
  27. //Getters
  28. string GetName()
  29. {
  30. return this->name;
  31. }
  32. string GetDateOfBirth()
  33. {
  34. return this->date_of_birth;
  35. }
  36. string GetDepartmentName()
  37. {
  38. return this->department_name;
  39. }
  40. string GetPosition()
  41. {
  42. return this->position;
  43. }
  44. string GetBeginningDate()
  45. {
  46. return this->beginning_date;
  47. }
  48. //Setters
  49. void SetName(string new_name)
  50. {
  51. this->name = new_name;
  52. }
  53. void SetDateOfBirth(string new_date_of_birth)
  54. {
  55. this->date_of_birth = new_date_of_birth;
  56. }
  57. void SetDepartmentName(string new_department_name)
  58. {
  59. this->department_name = new_department_name;
  60. }
  61. void SetPosition(string new_position)
  62. {
  63. this->position = new_position;
  64. }
  65. void SetBeginningDate(string new_beginning_date)
  66. {
  67. this->beginning_date = new_beginning_date;
  68. }
  69. };
  70.  
  71. vector<Worker> workers;
  72. bool role;
  73.  
  74. string GetString(string current, int position, int symbols)
  75. {
  76. return current.substr(position, symbols);
  77. }
  78.  
  79. bool CompareWorkersByDate(Worker first_worker, Worker second_worker)
  80. {
  81. string first_worker_date = first_worker.GetBeginningDate();
  82. string second_worker_date = second_worker.GetBeginningDate();
  83. string first_worker_year = GetString(first_worker_date, 6, 4);
  84. string second_worker_year = GetString(second_worker_date, 6, 4);
  85. string first_worker_month = GetString(first_worker_date, 3, 2);
  86. string second_worker_month = GetString(second_worker_date, 3, 2);
  87. string first_worker_day = GetString(first_worker_date, 0, 2);
  88. string second_worker_day = GetString(second_worker_date, 0, 2);
  89. if (first_worker_year != second_worker_year) return first_worker_year < second_worker_year;
  90. if (first_worker_month != second_worker_month) return first_worker_month < second_worker_month;
  91. return first_worker_day < second_worker_day;
  92. }
  93.  
  94. bool CompareWorkersByName(Worker first_worker, Worker second_worker)
  95. {
  96. return first_worker.GetName() < second_worker.GetName();
  97. }
  98.  
  99. void PrintWorker(Worker current_worker)
  100. {
  101. cout << current_worker.GetName() << ' ' << current_worker.GetDateOfBirth() << ' ' << current_worker.GetDepartmentName() << ' '
  102. << current_worker.GetPosition() << ' ' << current_worker.GetBeginningDate() << "\n";
  103. }
  104.  
  105. void AddWorker()
  106. {
  107. cout << "Enter new worker's new name, date of birth, department name, position and beginning date : " << "\n";
  108. string name;
  109. string date_of_birth;
  110. string department_name;
  111. string position;
  112. string beginning_date;
  113. cin >> name >> date_of_birth >> department_name >> position >> beginning_date;
  114. Worker current_worker(name, date_of_birth, department_name, position, beginning_date);
  115. workers.push_back(current_worker);
  116. }
  117.  
  118. void ChooseItem()
  119. {
  120. cout << "1. Name" << "\n";
  121. cout << "2. Date of birth" << "\n";
  122. cout << "3. Department name" << "\n";
  123. cout << "4. Position" << "\n";
  124. cout << "5. Beginning date" << "\n";
  125. }
  126.  
  127. void EditWorker()
  128. {
  129. int edited_worker_number;
  130. int action;
  131. cout << "Enter edited worker number : " << "\n";
  132. cin >> edited_worker_number;
  133. cout << "What do you want to edit? " << "\n";
  134. ChooseItem();
  135. cin >> action;
  136. edited_worker_number--;
  137. switch(action)
  138. {
  139. case 1:
  140. {
  141. string new_name;
  142. cout << "Enter his new name : " << "\n";
  143. cin >> new_name;
  144. workers[edited_worker_number].SetName(new_name);
  145. break;
  146. }
  147. case 2:
  148. {
  149. string new_date_of_birth;
  150. cout << "Enter his new date of birth : " << "\n";
  151. cin >> new_date_of_birth;
  152. workers[edited_worker_number].SetDateOfBirth(new_date_of_birth);
  153. break;
  154. }
  155. case 3:
  156. {
  157. string new_department_name;
  158. cout << "Enter his new department name : " << "\n";
  159. cin >> new_department_name;
  160. workers[edited_worker_number].SetDepartmentName(new_department_name);
  161. break;
  162. }
  163. case 4:
  164. {
  165. string new_position;
  166. cout << "Enter his new position : " << "\n";
  167. cin >> new_position;
  168. workers[edited_worker_number].SetPosition(new_position);
  169. break;
  170. }
  171. case 5:
  172. {
  173. string new_beginning_date;
  174. cout << "Enter his new beginning date : " << "\n";
  175. cin >> new_beginning_date;
  176. workers[edited_worker_number].SetBeginningDate(new_beginning_date);
  177. break;
  178. }
  179. }
  180. }
  181.  
  182. void DeleteWorker()
  183. {
  184. int deleted_worker_number;
  185. cout << "Enter deleted worker number: " << "\n";
  186. cin >> deleted_worker_number;
  187. deleted_worker_number--;
  188. workers.erase(workers.begin() + deleted_worker_number);
  189. }
  190.  
  191. bool IsRetiree(string age)
  192. {
  193. if (age.substr(6, 4) != retiree_age.substr(6, 4)) return age.substr(6, 4) <= retiree_age.substr(6, 4);
  194. if (age.substr(3, 2) != retiree_age.substr(3, 2)) return age.substr(3, 2) <= retiree_age.substr(3, 2);
  195. return age.substr(0, 2) <= retiree_age.substr(0, 2);
  196. }
  197.  
  198. void IndividualTask()
  199. {
  200. cout << "Retiree list : " << "\n";
  201. for (int i = 0; i < (int) workers.size(); i++)
  202. if (IsRetiree(workers[i].GetDateOfBirth()))
  203. cout << workers[i].GetName() << "\n";
  204. cout << "Experience decreasing list of workers : " << "\n";
  205. vector<Worker> sorted_workers = workers;
  206. sort(sorted_workers.begin(), sorted_workers.end(), CompareWorkersByDate);
  207. for (int i = 0; i < (int) sorted_workers.size(); i++)
  208. PrintWorker(sorted_workers[i]);
  209. }
  210.  
  211. void FindWorker()
  212. {
  213. cout << "Enter what item do you want to find ?" << "\n";
  214. ChooseItem();
  215. int action;
  216. cin >> action;
  217. cout << "List of suitable people : " << "\n";
  218. switch(action)
  219. {
  220. case 1:
  221. {
  222. string name;
  223. cin >> name;
  224. for (int i = 0; i < (int) workers.size(); i++)
  225. if (workers[i].GetName() == name) PrintWorker(workers[i]);
  226. break;
  227. }
  228. case 2:
  229. {
  230. string date_of_birth;
  231. cin >> date_of_birth;
  232. for (int i = 0; i < (int) workers.size(); i++)
  233. if (workers[i].GetDateOfBirth() == date_of_birth) PrintWorker(workers[i]);
  234. break;
  235. }
  236. case 3:
  237. {
  238. string department_name;
  239. cin >> department_name;
  240. for (int i = 0; i < (int) workers.size(); i++)
  241. if (workers[i].GetDepartmentName() == department_name) PrintWorker(workers[i]);
  242. break;
  243. }
  244. case 4:
  245. {
  246. string position;
  247. cin >> position;
  248. for (int i = 0; i < (int) workers.size(); i++)
  249. if (workers[i].GetPosition() == position) PrintWorker(workers[i]);
  250. break;
  251. }
  252. case 5:
  253. {
  254. string beginning_date;
  255. cin >> beginning_date;
  256. for (int i = 0; i < (int) workers.size(); i++)
  257. if (workers[i].GetBeginningDate() == beginning_date) PrintWorker(workers[i]);
  258. break;
  259. }
  260. }
  261. }
  262.  
  263. void SortWorkers()
  264. {
  265. cout << "Choose item : " << "\n";
  266. cout << "1. Sort workers by name" << "\n";
  267. cout << "2. Sort workers by date of birth" << "\n";
  268. cout << "3. Sort workers by beginning date" << "\n";
  269. int action;
  270. cin >> action;
  271. cout << "Sorted list of people : " << "\n";
  272. vector<Worker> sorted_workers = workers;
  273. if (action == 1) sort(sorted_workers.begin(), sorted_workers.end(), CompareWorkersByName);
  274. else sort(sorted_workers.rbegin(), sorted_workers.rend(), CompareWorkersByDate);
  275. for (int i = 0; i < (int) sorted_workers.size(); i++)
  276. PrintWorker(workers[i]);
  277. }
  278.  
  279. void AdministratorMenu()
  280. {
  281. cout << "\t\tADMINISTRATOR MENU : " << "\n";
  282.  
  283. cout << "1. Show workers" << "\n";
  284. cout << "2. Add worker" << "\n";
  285. cout << "3. Edit worker" << "\n";
  286. cout << "4. Delete worker" << "\n";
  287. }
  288.  
  289. void UserMenu()
  290. {
  291. cout << "\t\tUSER MENU : " << "\n";
  292. cout << "1. Show workers" << "\n";
  293. cout << "2. Individual wask" << "\n";
  294. cout << "3. Find worker" << "\n";
  295. cout << "4. Sort workers" << "\n";
  296. }
  297.  
  298. bool Authorize()
  299. {
  300. string login;
  301. string password;
  302. cout << "Enter login : " << "\n";
  303. cin >> login;
  304. cout << "Enter password : " << "\n";
  305. cin >> password;
  306. cout << "You are ";
  307. if (password == right_password && login == right_login) role = true;
  308. else role = false;
  309. if (role) cout << "Administrator" << "\n";
  310. else cout << "User" << "\n";
  311. if (role) AdministratorMenu();
  312. else UserMenu();
  313. }
  314.  
  315. void ChooseAction()
  316. {
  317. cout << "Choose action : " << "\n";
  318. cout << "0. Authorize" << "\n";
  319. int action;
  320. if (role)
  321. {
  322. cout << "-1. Break" << "\n";
  323. cout << "1. Show workers (is not working) " << "\n";
  324. cout << "2. Add worker" << "\n";
  325. cout << "3. Edit worker" << "\n";
  326. cout << "4. Delete worker" << "\n";
  327. cin >> action;
  328. switch (action)
  329. {
  330. case -1:
  331. cout << "Wonderful work ! (NET) ";
  332. exit(0);
  333. case 0:
  334. {
  335. Authorize();
  336. return;
  337. break;
  338. }
  339. case 1:
  340. //ShowWorkers();
  341. case 2:
  342. AddWorker();
  343. break;
  344. case 3:
  345. EditWorker();
  346. break;
  347. case 4:
  348. DeleteWorker();
  349. break;
  350. }
  351. }
  352. else
  353. {
  354. cout << "-1. Break";
  355. cout << "1. Show workers (is not working) " << "\n";
  356. cout << "2. Individual task" << "\n";
  357. cout << "3. Find worker" << "\n";
  358. cout << "4. Sort workers" << "\n";
  359. cin >> action;
  360. switch (action)
  361. {
  362. case -1:
  363. cout << "Wonderful work ! (NET) ";
  364. exit(0);
  365. case 0:
  366. Authorize();
  367. return;
  368. break;
  369. case 1:
  370. //ShowWorkers();
  371. case 2:
  372. IndividualTask();
  373. break;
  374. case 3:
  375. FindWorker();
  376. break;
  377. case 4:
  378. SortWorkers();
  379. break;
  380. }
  381. }
  382. }
  383.  
  384. void Solve()
  385. {
  386. Authorize();
  387. cout << "\n" "Dear Stanislav, enter everything that you wish -(^-^)- " << "\n\n";
  388. while (true)
  389. {
  390. cout << "\n";
  391. ChooseAction();
  392. cout << "\n";
  393. }
  394. }
  395.  
  396. int main()
  397. {
  398. Solve();
  399. return 0;
  400. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement