Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1.  
  2. #include <stdafx.h>
  3. #include <iostream>
  4. #include <fstream>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <iomanip>
  8. #include <conio.h>
  9. using namespace std;
  10. struct TUR
  11. {
  12. char NameTur[20];
  13. char NameCountry[20];
  14. int Duration;
  15. int Stand;
  16. int Thenumberofpermits;
  17. TUR *Next;
  18. };
  19. class List
  20. {
  21. TUR *Head;
  22. public:
  23. List() :Head(NULL) { };
  24. ~List();
  25. void ReadFormFile();
  26. void Add();
  27. void Show();
  28. void LoadToFile();
  29. void Delete();
  30. void Sort();
  31. void Search(); ;
  32. };
  33. List::~List()
  34. {
  35. while (Head != NULL)
  36. {
  37. TUR* temp = Head->Next;
  38. delete Head;
  39. Head = temp;
  40. }
  41. }
  42. void List::Add()
  43. {
  44. TUR st;
  45. TUR* temp = new TUR;
  46. temp->Next = Head;
  47. system("cls");
  48. cin.ignore();
  49. cout << "NameTUR:"; cin.getline(st.NameTur, 20);
  50. cout << "NameCountry:"; cin.getline(st.NameCountry, 20);
  51. cout << "Duration:"; cin >> st.Duration;
  52. cout << "Stand:"; cin >> st.Stand;
  53. cout << "Thenumberofperm:"; cin >> st.Thenumberofpermits;
  54. strcpy(temp->NameTur, st.NameTur);
  55. strcpy(temp->NameCountry, st.NameCountry);
  56. temp->Duration=st.Duration;
  57. temp->Stand= st.Stand;
  58. temp->Thenumberofpermits= st.Thenumberofpermits;
  59. Head = temp;
  60. }
  61. void List::ReadFromFile()
  62. {
  63. ifstream fin("TUR.txt");
  64. Vladelec *temp;
  65.  
  66. if (fin.is_open())
  67. {
  68. cout << "Файл открыт" << endl;
  69. while (!fin.eof())
  70. {
  71. temp = new Vladelec;
  72. fin >> temp->NameTUR >> temp->NameCountry>> temp->Duration >> temp->Stand >> temp->Thenumberofperm;
  73. temp->Next = Head;
  74. Head = temp;
  75. }
  76. cout << "Данные получены" << endl;
  77. fin.close();
  78. }
  79. else cout << "Файл не найден" << endl;
  80. }
  81. void List::LoadToFile()
  82. {
  83. char file_name[30];
  84. system("cls");
  85. cout<<"Input file name: ";
  86. cin >> file_name;
  87. ofstream fout(file_name);
  88. if (fout)
  89. {
  90. TUR *temp = Head;
  91. while (temp != NULL)
  92. {
  93. fout<< setw(20) << temp->NameTur << setw(20) <<temp->NameCountry<< setw(10)<< temp->Duration << setw(10) << temp->Stand << setw(10)<< temp->Thenumberofpermits << endl;
  94. temp = temp->Next;
  95. }
  96. cout << "File is completed" << endl;
  97. system ("pause");
  98. fout.close();
  99. }
  100. else cout << "File is not create";
  101. }
  102. void List::Show()
  103. {
  104. TUR*temp = Head;
  105. system("cls");
  106. cout << setw(20) << "Name" << setw(20) << "NameCountry" << setw(20) << "Duration" << setw(10) << "Stand" << setw(10) << "Thenumberofperm" << endl;
  107. cout<< "_____________________________________________________" << endl << endl;
  108. while (temp != NULL)
  109. {
  110. cout << setw(20) << temp->NameTur;
  111. cout << setw(20) << temp->NameCountry;
  112. cout << setw(20) << temp->Duration;
  113. cout << setw(10) << temp->Stand;
  114. cout << setw(10) << temp->Thenumberofpermits << endl;
  115. temp = temp->Next;
  116. }
  117. cout << "_____________________________________________________" << endl << endl;
  118. }
  119. void List::Delete()
  120. {
  121. {
  122. TUR* temp = Head->Next;
  123. delete Head;
  124. Head = temp;
  125. }
  126. }
  127. void List::Search()
  128.  
  129. {
  130. TUR *temp=Head;
  131. system("cls");
  132. char s1[20];
  133. cout << "Input NameTur:" << endl;
  134. cin >> s1;
  135.  
  136. while (temp != NULL)
  137. {
  138. if (!strcmp(temp->NameTur, s1))
  139. {
  140. cout << setw(20)<<temp->NameTur;
  141. cout << setw(20)<<temp->NameCountry;
  142. cout << setw(20)<<temp->Duration;
  143. cout << setw(10)<<temp->Stand << endl;
  144. }
  145. temp = temp->Next;
  146. }
  147. system("pause");
  148. }
  149. void List::Sort()
  150. {
  151. TUR *temp = Head;
  152. TUR *temp2;
  153. TUR *tempShow;
  154. char swap_NameTur[20];
  155. char swap_NameCountry[20];
  156. int swap_Duration;
  157. int swap_Stand;
  158. int swap_Thenumberofpermits;
  159. bool flag = 0;
  160.  
  161. while (flag == 0)
  162. {
  163. flag = 1;
  164. while (temp->Next != NULL)
  165. {
  166. tempShow = Head;
  167. temp2 = temp->Next;
  168. if (temp->Stand > temp2->Stand)
  169. {
  170. strcpy_s(swap_NameTur, temp->NameTur);
  171. strcpy_s(temp->NameTur,temp2->NameTur);
  172. strcpy_s(temp2->NameTur, swap_NameTur);
  173.  
  174. strcpy_s(swap_NameCountry, temp->NameCountry);
  175. strcpy_s(temp->NameCountry, temp2->NameCountry);
  176. strcpy_s(temp2->NameCountry, swap_NameCountry);
  177.  
  178.  
  179. strcpy_s(swap_Stand = temp->Stand);
  180. strcpy_s(temp->Stand = temp2->Stand);
  181. strcpy_s(temp2->Stand = swap_Stand);
  182.  
  183. strcpy_s(swap_Duration = temp->Duration);
  184. strcpy_s(temp->Duration = temp2->Duration);
  185. strcpy_s(temp2->Duration = swap_Duration);
  186.  
  187. strcpy_s(swap_Thenumberofpermits = temp->Thenumberofpermits);
  188. strcpy_s(temp->Thenumberofpermits = temp2->Thenumberofpermits);
  189. strcpy_s(temp2->Thenumberofpermits = swap_Thenumberofpermits);
  190.  
  191. flag = 0;
  192. }
  193. temp = temp->Next;
  194. }
  195. if (temp->Next == NULL)
  196. temp = Head;
  197. }
  198. cout << "Сортировка завершена\n";
  199. }
  200.  
  201.  
  202. int _tmain(int argc, _TCHAR* argv[])
  203. {
  204.  
  205. cout.setf(ios::left);
  206. bool flag = true;
  207. int choice;
  208. List spisok;
  209. while (flag)
  210. {
  211.  
  212. system("cls");
  213. cout<< endl << " MENU" << endl;
  214. cout << "____________________________" << endl << endl;
  215. cout << "| 1: Read from the file |"<< endl;
  216. cout << "| 2: Show list |" << endl;
  217. cout << "| 3: Add |" << endl;
  218. cout << "| 4: Save to the file |"<< endl;
  219. cout << "| 5: Delete the record |" << endl;
  220. cout << "| 6: Sort |" << endl;
  221. cout << "| 7: Search |" << endl;
  222. cout << "| 8: Exit |" << endl;
  223. cout << "____________________________" << endl << endl;
  224. cout << " Make your choice (1-8): ";
  225. cin >> choice;
  226. switch (choice)
  227. {
  228.  
  229. case 1: spisok.ReadFormFile();
  230. system("PAUSE"); break;
  231. case 2: spisok.Show(); system("PAUSE"); break;
  232. case 3: spisok.Add(); break;
  233. case 4: spisok.LoadToFile(); break;
  234. case 5: spisok.Delete(); break;
  235. case 6: spisok.Sort(); break;
  236. case 7: spisok.Search();break;
  237. case 8: flag = false; break;
  238. //default: cout << "You are wrong";
  239. }
  240. }
  241. system("PAUSE");
  242. return 0;
  243. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement