Advertisement
Guest User

efwe

a guest
Jun 1st, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.62 KB | None | 0 0
  1. #include <conio.h>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include <windows.h>
  6. #include "ShellAPI.h"
  7.  
  8. using namespace std;
  9.  
  10. struct QUEUE //структура очередь
  11. {
  12. string info;
  13. string street;
  14. string service;
  15. int timeH, timeM;
  16. int number;
  17. QUEUE *next;
  18. };
  19.  
  20. bool Empty(QUEUE *head)
  21. {
  22. if (head == NULL)
  23. return true;
  24. else
  25. return false;
  26.  
  27. }
  28. char menu()
  29. {
  30. char choice;
  31.  
  32. cout << "Menu\n";
  33. cout << "1. Add to list.\n";
  34. cout << "2. Remove from the list\n";
  35. cout << "3. Show list.\n";
  36. cout << "4. SaveFile.\n";
  37. cout << "5. ReadFile.\n";
  38. cout << "6. Exit.\n";
  39.  
  40. cin >> choice;
  41. system("cls");
  42. return choice;
  43. }
  44. void addElement(QUEUE *&head, QUEUE *&last, int number, string info, string street, string service, int timeH, int timeM)
  45. {
  46. QUEUE *temp = new QUEUE;
  47. temp->number = number;
  48. temp->info = info;
  49. temp->street = street;
  50. temp->service = service;
  51. temp->timeH = timeH;
  52. temp->timeM = timeM;
  53. temp->next = NULL;
  54. head = temp;
  55. last = temp;
  56.  
  57. }
  58. void insert(QUEUE *&head, QUEUE *&last, int number, string info, string street, string service, int timeH, int timeM)
  59. {
  60. if (Empty(head))
  61. addElement(head, last, number, info, street, service, timeH, timeM);
  62. else
  63. {
  64. QUEUE *temp = new QUEUE;
  65. temp->number = number;
  66. temp->info = info;
  67. temp->street = street;
  68. temp->service = service;
  69. temp->timeH = timeH;
  70. temp->timeM = timeM;
  71. temp->next = NULL;
  72. last->next = temp;
  73. last = temp;
  74.  
  75. }
  76. }
  77. void remove(QUEUE *&head, QUEUE *&last)
  78. {
  79. if (Empty(head))
  80. cout << "List was already empty.\n";
  81.  
  82. else if (head == last)
  83. {
  84. delete head;
  85. head = NULL;
  86. last = NULL;
  87. }
  88. else
  89. {
  90. QUEUE *temp = head;
  91. head = head->next;
  92. delete temp;
  93. }
  94.  
  95.  
  96. }
  97. void showList(QUEUE *current)
  98. {
  99.  
  100.  
  101. if (Empty(current))
  102.  
  103. cout << "List is empty.\n";
  104. else
  105. {
  106. cout << "List contains: \n";
  107. while (current != NULL)
  108. {
  109. cout <<"Coupon №"<< current->number << endl;
  110. cout << "Name: " << current->info << endl;
  111. cout << "Service: " << current->service << endl;
  112. cout << "Address of the terminal: " << current->street << endl;
  113. cout << "Time: " << current->timeH <<":"<< current->timeM << endl;
  114. cout << "\n";
  115. current = current->next;
  116.  
  117. }
  118. }
  119. }
  120.  
  121. void savefile(QUEUE *current)
  122. {
  123. ofstream fout("Queue.txt");
  124.  
  125. if (Empty(current))
  126.  
  127. cout << "File is empty.\n";
  128. else
  129. {
  130. while (current != NULL)
  131. {
  132. fout << "Coupon №" << current->number << endl;
  133. fout << "Name: " << current->info << endl;
  134. fout << "Service: " << current->service << endl;
  135. fout << "Address of the terminal: " << current->street << endl;
  136. fout << "Time: " << current->timeH << ":" << current->timeM << endl;
  137. fout << "\n";
  138. current = current->next;
  139.  
  140. }
  141. }
  142. }
  143.  
  144. int count()
  145. {
  146. ifstream fin("Queue.txt", ios_base::in);
  147. int count = 0;
  148. string s;
  149. while (!fin.eof())
  150. {
  151. getline(fin, s);
  152. count++;
  153. }
  154. return count;
  155. }
  156.  
  157.  
  158. int readfile (QUEUE *head, QUEUE *last)
  159. {
  160.  
  161. char ch;
  162. QUEUE *temp = new QUEUE;
  163. ifstream fin("Queue.txt");
  164. for (int i = 0; i < count(); i++)
  165. {
  166. //temp = new QUEUE;
  167. fin >> temp->number;
  168. getline(fin, temp->info);
  169. fin.ignore();
  170. getline(fin, temp->street);
  171. fin.ignore();
  172. getline(fin, temp->service);
  173. fin.ignore();
  174. fin >> temp->timeH;
  175. fin >> temp->timeM;
  176.  
  177. if (Empty(head))
  178. {
  179. head = temp;
  180. last = temp;
  181. temp -> next = NULL;
  182. }
  183. else
  184. {
  185. temp->next = NULL;
  186. last->next = temp;
  187. last = temp;
  188. }
  189. fin.close();
  190.  
  191. return 1;
  192.  
  193. }
  194. /*QUEUE *temp = new QUEUE;
  195. ifstream fin("Queue.txt");
  196. if (!fin.is_open())
  197. cout << "file cant open\n";
  198. else
  199. {
  200. while (fin.get(ch))
  201. cout << ch;
  202. getline(fin, temp->info);
  203. fin.ignore();
  204. getline(fin, temp->street);
  205. fin.ignore();
  206. getline(fin, temp->service);
  207. fin.ignore();
  208. fin >> temp->timeH;
  209. fin >> temp->timeM;
  210. //insert(head, QUEUE *&last, int number, string info, string street, string service, int timeH, int timeM);
  211. }
  212. fin.close();
  213. */
  214.  
  215. }
  216.  
  217.  
  218.  
  219. int main()
  220. {
  221. setlocale(LC_ALL, "Russian");
  222. QUEUE *current;
  223. QUEUE *head = NULL;
  224. QUEUE *last = NULL;
  225. int choose;
  226. char choice;
  227. int number = 0;
  228. string info;
  229. string street;
  230. string service;
  231. int timeH, timeM;
  232.  
  233. do
  234. {
  235.  
  236. choice = menu();
  237.  
  238. switch (choice)
  239. {
  240. case '1':
  241. system("cls");
  242. cout << "Enter the name: ";
  243. number = number;
  244. number++;
  245. street = "Vyazemskaya 12";
  246. cin.get();
  247. getline(cin, info);
  248. system("cls");
  249. cout << "Select a service:\n1. Card\n2. Payment \n";
  250. while ((!(cin >> choose)) || (choose < 1) || (choose > 2))
  251. {
  252. cin.clear();
  253. while (cin.get() != '\n')
  254. continue;
  255. cout << "Enter the number 1 or 2: ";
  256. }
  257. if (choose == 1)
  258. service = "Card";
  259. else
  260. service = "Payment";
  261. system("cls");
  262. cout << "Enter the time (hours): ";
  263. while ((!(cin >> timeH)) || (timeH < 0) || (timeH > 24))
  264. {
  265. cin.clear();
  266. while (cin.get() != '\n')
  267. continue;
  268. cout << "Enter the hours 0-24: ";
  269. }
  270. system("cls");
  271. cout << "Enter the time (minutes): ";
  272. while ((!(cin >> timeM)) || (timeM < 0) || (timeM > 60))
  273. {
  274. cin.clear();
  275. while (cin.get() != '\n')
  276. continue;
  277. cout << "Enter the hours 0-60: ";
  278. }
  279. system("cls");
  280.  
  281. insert(head, last, number, info, street, service, timeH, timeM);
  282. break;
  283.  
  284. case '2': remove(head, last);
  285. break;
  286. case '3': showList(head);
  287. break;
  288. case '4': savefile(head);
  289. break;
  290. case '5': readfile(head, last);
  291. break;
  292. case '6': cout << "Exit\n";
  293. }
  294. } while (choice != '6');
  295. _getch();
  296. return 0;
  297.  
  298. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement