Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include "Human.h"
  4. #include "Tourist.h"
  5. #include "Businessman.h"
  6. #include "Business.h"
  7. #include "MyFile.h"
  8.  
  9. bool compare1(Human first, Human second)
  10. {
  11. if (first.getSurname() < second.getSurname())
  12. return true;
  13. return false;
  14. }
  15.  
  16. bool compare2(Human first, Human second)
  17. {
  18. if (first.getName() < second.getName())
  19. return true;
  20. return false;
  21. }
  22.  
  23. bool compare3(Human first, Human second)
  24. {
  25. if (first.getYearBirth() < second.getYearBirth())
  26. return true;
  27. return false;
  28. }
  29.  
  30. bool compare4(Human first, string surname)
  31. {
  32. if (first.getSurname() == surname)
  33. return true;
  34. return false;
  35. }
  36.  
  37. bool compare5(Human first, string name)
  38. {
  39. if (first.getName() == name)
  40. return true;
  41. return false;
  42. }
  43.  
  44. bool compare6(Human first, int year)
  45. {
  46. if (first.getYearBirth() == year)
  47. return true;
  48. return false;
  49. }
  50.  
  51. using namespace std;
  52.  
  53. int main()
  54. {
  55.  
  56. SetConsoleCP(1251);
  57. SetConsoleOutputCP(1251);
  58.  
  59. MyFile f;
  60. f.open("file.txt", MyFile::Binary);
  61.  
  62.  
  63. int size = 2;
  64. Queue<Human> humans;
  65. Human tmp;
  66. while(1)
  67. {
  68. system("cls");
  69. cout << " 1 - Ввести элемент" << endl;
  70. cout << " 2 - Показать таблицу" << endl;
  71. cout << " 3 - Удалить элемент" << endl;
  72. cout << " 4 - Поиск" << endl;
  73. cout << " 5 - Отсортировать" << endl;
  74. cout << " 6 - Записать в файл" << endl;
  75. cout << " 0 - Выйти" << endl;
  76. cout << " Выберите команду:";
  77. cin.sync();
  78. switch(cin.get())
  79. {
  80. case '1' :
  81. {
  82. system("cls");
  83. do
  84. {
  85. cin >> tmp;
  86. humans.push(tmp);
  87. cout << "Введите любой символ, чтобы продолжить ввод?(0 - выйти)";
  88. getchar();
  89. if (cin.get() == '0') break;
  90. cin.sync();
  91. }while(1);
  92. break;
  93. }
  94. case '2' :
  95. {
  96. system("cls");
  97. if (!humans.begin())
  98. {
  99. cout << "нет информации" << endl;
  100. system("pause");
  101. continue;
  102. }
  103. humans[0].table();
  104. for (Queue<Human>::Iterator i = humans.begin(); i != humans.end(); i++)
  105. {
  106. Human temp = *i;
  107. cout << temp << endl;
  108. }
  109. system("pause");
  110. break;
  111. }
  112. case '3' :
  113. {
  114. system("cls");
  115. humans.node_delete();
  116. system("pause");
  117. break;
  118. }
  119. case '4':
  120. {
  121. system("cls");
  122. Queue<Human> tempQue;
  123. tempQue = humans;
  124. Node<Human> *tempNode;
  125. do
  126. {
  127. system("cls");
  128. cout << " 1 - Фамилия" << endl;
  129. cout << " 2 - Имя" << endl;
  130. cout << " 3 - Год рождения" << endl;
  131. cout << " 4 - Показать результат" << endl;
  132. int i;
  133. cin >> i;
  134. if (i == 1)
  135. {
  136. cout << " Введите фамилию: ";
  137. string surname;
  138. cin >> surname;
  139. Queue<Human> tempp;
  140. for (Queue<Human>::Iterator i = tempQue.begin(); i != tempQue.end(); i++)
  141. {
  142. tempNode = search(i, tempQue.end(), surname, &compare4);
  143. if (tempNode)
  144. tempp.push(tempNode->node);
  145. }
  146. tempQue = tempp;
  147. tempp.clean();
  148. //break;
  149. }
  150. else if (i == 2)
  151. {
  152. cout << " Введите имя: ";
  153. string name;
  154. cin >> name;
  155. Queue<Human> tempp;
  156. for (Queue<Human>::Iterator i = tempQue.begin(); i != tempQue.end(); i++)
  157. {
  158. tempNode = search(i, humans.end(), name, &compare5);
  159. if (tempNode)
  160. tempp.push(tempNode->node);
  161. }
  162. tempQue = tempp;
  163. tempp.clean();
  164. //break;
  165. }
  166. else if (i == 3)
  167. {
  168. cout << " Введите год рождения: ";
  169. int year;
  170. cin >> year;
  171. Queue<Human> tempp;
  172. for (Queue<Human>::Iterator i = tempQue.begin(); i != tempQue.end(); i++)
  173. {
  174. tempNode = search(i, humans.end(), year, &compare6);
  175. if (tempNode)
  176. tempp.push(tempNode->node);
  177. }
  178. tempQue = tempp;
  179. tempp.clean();
  180. //break;
  181. }
  182. else if (i == 4)
  183. {
  184. if (!tempQue.getSize())
  185. {
  186. cout << "элементы отсутствуют" << endl;
  187. system("pause");
  188. break;
  189. }
  190. else
  191. {
  192. for (int i = 0; i < tempQue.getSize(); i++)
  193. {
  194. Human asd = tempQue[i];
  195. cout << asd << endl;
  196. }
  197. system("pause");
  198. break;
  199. }
  200. }
  201. else continue;
  202. } while (1);
  203. system("pause");
  204. break;
  205. }
  206. case '5':
  207. {
  208. system("cls");
  209. cout << " 1 - Фамилия" << endl;
  210. cout << " 2 - Имя" << endl;
  211. cout << " 3 - Год рождения" << endl;
  212. int i;
  213. cin >> i;
  214. if (i == 1)
  215. sort(humans.begin(), humans.end(), &compare1);
  216. if (i == 2)
  217. sort(humans.begin(), humans.end(), &compare2);
  218. if(i == 3)
  219. sort(humans.begin(), humans.end(), &compare3);
  220. else continue;
  221. break;
  222. }
  223. case '6' :
  224. {
  225. system("cls");
  226. Queue<int> a;
  227. for (int i = 0; i < 10; i++)
  228. a.push(i + 1);
  229. f.write(a);
  230. cout << "Информация записана в файл" << endl;
  231. system("pause");
  232. break;
  233. }
  234. case '0' :
  235. {
  236. return 0;
  237. }
  238. }
  239. }
  240.  
  241. system("pause");
  242. return 0;
  243. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement