Advertisement
AlexandrTalchuk

Untitled

May 16th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. // Вывести информацию для заданного пункта назначения в порядке возрастаняи времени вылета. Ключ: пункт назначения
  3. #include <iostream>
  4. #include <io.h>
  5. #include <conio.h>
  6. #include<cstdio>
  7.  
  8. using namespace std;
  9.  
  10. void Add();
  11. void Watching();
  12. void Searching();
  13. void Sorting();
  14.  
  15. struct Stack
  16. {
  17. int info;
  18. Stack* next;
  19. };
  20.  
  21. struct air
  22. {
  23. int number;
  24. char type[36];
  25. char area[36];
  26. double time;
  27. };
  28.  
  29.  
  30. int main()
  31. {
  32. setlocale(LC_ALL, "rus");
  33. int choice;
  34. while (true)
  35. {
  36. cout << "1. Добавление\n2. Просмотр\n3. Сортировка\n4. Поиск\n5. Выход" << endl;
  37. cin >> choice;
  38. switch (choice)
  39. {
  40. case 1:
  41. Add();
  42. cout << "Информация сохранена, нажмите любую кнопку" << endl;
  43. break;
  44. case 2:
  45. Watching();
  46. _getch();
  47. break;
  48. case 3:
  49. Sorting();
  50. break;
  51. case 4:
  52. //Searching();
  53. break;
  54. case 5:
  55. cout << "Программа завершена" << endl;
  56. return 0;
  57. break;
  58. default:
  59. cout<<"Повторите еще раз"<<endl;
  60. break;
  61. }
  62. system("cls");
  63.  
  64. }
  65. }
  66.  
  67. void Add()
  68. {
  69. FILE* f;
  70. air one;
  71. char filename[81];
  72. cout << "Введите имя файла" << endl;
  73. cin >>filename;
  74. f = fopen(filename, "a");
  75. if (f == NULL)
  76. {
  77. cout << "Данного файла не существует" << endl;
  78. return;
  79. }
  80. cout << "Введите номер рейса" << endl;
  81. cin >> one.number;
  82. cout << "Ведите тип самолета" << endl;
  83. cin >> one.type;
  84. cout << "Ведите пункт назначения" << endl;
  85. cin >> one.area;
  86. cout << "Ведите время вылета" << endl;
  87. cin >> one.time;
  88. fwrite(&one, sizeof(air), 1, f);
  89. fclose(f);
  90. }
  91.  
  92. void Watching()
  93. {
  94. FILE* f;
  95. air one;
  96. char filename[81];
  97. cout << "Введите имя файла" << endl;
  98. cin >> filename;
  99. f = fopen(filename, "r");
  100. if (f == NULL)
  101. {
  102. cout << "Данного файла не существует" << endl;
  103. return;
  104. }
  105. while (fread(&one, sizeof(air), 1, f) == 1)
  106. {
  107. cout << "Номер рейса "<<one.number << endl;
  108. cout << "Тип самолета "<<one.type << endl;
  109. cout << "Пункт назначения "<<one.area << endl;
  110. cout << "Время вылета " << one.time;
  111. }
  112. fclose(f);
  113. return;
  114. }
  115.  
  116. void Searching()
  117. {
  118. FILE* f;
  119. char filename[81];
  120. cout << "Введите имя файла" << endl;
  121. cin >> filename;
  122. f = fopen(filename, "r+");
  123. if (f == NULL)
  124. {
  125. cout << "Данного файла не существует" << endl;
  126. return;
  127. }
  128. fseek(f, 0, 0);
  129. int size = _filelength(_fileno(f));
  130. size /= sizeof(air);
  131. air* mas = new air[size];
  132. fread(mas, sizeof(air), size, f);
  133. int i, j, m, middle, choice;
  134. for (i = 0; i < size - 1; i++)
  135. {
  136. m = i;
  137. for (j = i + 1; j < size; j++)
  138. if (mas[i].time > mas[j].time) m = j;
  139. if (m != i)
  140. {
  141. air r = mas[m];
  142. mas[m] = mas[i];
  143. mas[i] = r;
  144. }
  145. }
  146. }
  147.  
  148. void Sorting()
  149. {
  150. FILE* f;
  151. char filename[81];
  152. char place[81];
  153. int choice,cnt;
  154. cout << "Введите имя файла" << endl;
  155. cin >> filename;
  156. f = fopen(filename, "r+");
  157. if (f == NULL)
  158. {
  159. cout << "Такого файла не обнаружено!" << endl;
  160. return;
  161. }
  162. fseek(f, 0, 0);
  163. int size = _filelength(_fileno(f));
  164. size /= sizeof(air);
  165. air* a1=new air[size];
  166. air* mas = new air[size];//количество записей в файле
  167. cout << "Введите ключ" << endl;
  168. cin >> place[81];
  169. for (int g = 0; g < size-1; g++)
  170. {
  171. fread(mas, sizeof(air), size, f);
  172. if (strcmp(place, a1[g].area) == 0)
  173. {
  174. cnt++;
  175. }
  176. }
  177. air* arr = new air[cnt];
  178. for (int i = 0; i < size; i++)
  179. {
  180.  
  181. }
  182.  
  183. /*cin >> choice;
  184. cout << "1.QuickSort\n" << "2.Сортировка прямым выбором\n" << endl;
  185. switch (choice)
  186. {
  187. case 1:
  188. break;
  189. case 2:
  190. break;
  191. default:
  192. cout << "Неверный ввод" << endl;
  193. return;
  194. break;
  195. }*/
  196. fseek(f, 0, 0);
  197. fwrite(mas, sizeof(air), size, f);
  198. fclose(f);
  199. delete[]mas;
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement