Advertisement
Courbe_Impliquee

list.struct

Dec 17th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.71 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <Windows.h>
  5. #include <clocale>
  6. #include <cstdlib>
  7. #include <iterator>
  8. #include <algorithm>
  9. #include <fstream>
  10. #include <iomanip>
  11. using namespace std;
  12. struct FIO {
  13. char name[20];
  14. char surname[20];
  15. char patronymic[20];
  16. };
  17. struct Student {
  18. FIO fio;
  19. int group;
  20. int exams;
  21. int mark[7];
  22. char disp[7][20];
  23. };
  24. struct stud {
  25. Student uch;
  26. stud* next;
  27. stud* prev;
  28. }*hbeg, *hend, *w, *h;
  29. void read_file(stud** hbeg, stud** hend) {
  30. ifstream fail;
  31. fail.open("students_info.txt", ios::in);
  32. int i = 0;
  33. while (fail) {
  34. w = new stud;
  35. fail >> w->uch.fio.surname;
  36. if (strlen(w->uch.fio.surname) < 2) {
  37. delete w;
  38. break;
  39. }
  40. fail >> w->uch.exams;
  41. for (int j = 0; j < w->uch.exams; j++) {
  42. fail >> w->uch.disp[j];
  43. }
  44. for (int j = w->uch.exams; j < 7; j++) {
  45. strcpy_s(w->uch.disp[j]," ");
  46. }
  47. fail >> w->uch.fio.name;
  48. fail >> w->uch.fio.patronymic;
  49. fail >> w->uch.group;
  50. for (int j = 0; j < w->uch.exams; j++) {
  51. fail >> w->uch.mark[j];
  52. }
  53.  
  54. if (i == 0) {
  55. w->next = 0;
  56. w->prev = 0;
  57. *hbeg = *hend = w;
  58. i++;
  59. }
  60. else {
  61. w->prev = *hend;
  62. w->next = 0;
  63. (*hend)->next = w;
  64. *hend = w;
  65. }
  66. }
  67. fail.close();
  68. }
  69. void print_info(stud* hbeg) {
  70. w = hbeg;
  71. while (w != 0) {
  72. cout << setw(25) << left << w->uch.fio.surname << " " << setw(4) << left << w->uch.exams;
  73. for (int j = 0; j < w->uch.exams; j++) {
  74. cout << w->uch.disp[j] << " ";
  75. }
  76. cout << endl;
  77. cout << setw(10) << left << w->uch.fio.name << " " << setw(15) << left << w->uch.fio.patronymic << setw(4) << left << w->uch.group << " ";
  78. for (int j = 0; j < w->uch.exams; j++) {
  79. cout << setw(4) << w->uch.mark[j] << " ";
  80. }
  81. cout << endl << endl;
  82. w = w->next;
  83. }
  84. }
  85. void add_info(stud** hend) {
  86. w = new stud;
  87. w->next = 0;
  88. cout << "Введите ФИО студента: ";
  89. cin >> w->uch.fio.surname;
  90. cin >> w->uch.fio.name;
  91. cin >> w->uch.fio.patronymic;
  92.  
  93. cout << "Введите число экзаменов: ";
  94. cin >> w->uch.exams;
  95.  
  96. cout << "Введите номер группы: ";
  97. cin >> w->uch.group;
  98.  
  99. cout << "Введите названия экзаменов: ";
  100. for (int j = 0; j < w->uch.exams; j++) {
  101. cin >> w->uch.disp[j];
  102. }
  103. for (int j = w->uch.exams; j < 7; j++) {
  104. strcpy_s(w->uch.disp[j], " ");
  105. }
  106.  
  107. cout << "Введите оценки студента по этим предметам: ";
  108. for (int j = 0; j < w->uch.exams; j++) {
  109. cin >> w->uch.mark[j];
  110. }
  111. w->prev = *hend;
  112. (*hend)->next = w;
  113. *hend = w;
  114. cout << endl;
  115. }
  116. void search_info(stud* hbeg) {
  117. w = hbeg;
  118. int ttt = 0;
  119. char key[20];
  120. cout<<"Введите слово для поиска: ";
  121. cin >> key;
  122. while (w != 0) {
  123. if (ttt == 0) {
  124. if (strcmp(key, w->uch.fio.name) == 0 || strcmp(key, w->uch.fio.surname) == 0 || strcmp(key, w->uch.fio.patronymic) == 0) {
  125. cout << setw(25) << left << w->uch.fio.surname << " " << setw(4) << left << w->uch.exams;
  126. for (int j = 0; j < w->uch.exams; j++) {
  127. cout << w->uch.disp[j] << " ";
  128. }
  129. cout << endl;
  130. cout << setw(10) << left << w->uch.fio.name << " " << setw(15) << left << w->uch.fio.patronymic << setw(4) << left << w->uch.group << " ";
  131. for (int j = 0; j < w->uch.exams; j++) {
  132. cout << setw(4) << w->uch.mark[j] << " ";
  133. }
  134. cout << endl << endl;
  135. }
  136. ttt++;
  137. }
  138. w = w->next;
  139. }
  140. if (ttt == 0) {
  141. printf_s("Не найдено!\n");
  142. }
  143. }
  144. void delete_info(stud** hbeg, stud **hend) {
  145. cout << "Введите ключ,по которому хотите удалить: ";
  146. char key[20];
  147. cin >> key;
  148. w = *hbeg;
  149. while (w != 0) {
  150. if (strcmp(key, w->uch.fio.name) == 0 || strcmp(key, w->uch.fio.surname) == 0 || strcmp(key, w->uch.fio.patronymic) == 0) {
  151. if (w == *hbeg) {
  152. *hbeg = w->next;
  153. (*hbeg)->prev = 0;
  154. }
  155. else if (w == *hend) {
  156. *hend = w->prev;
  157. (*hend)->next = 0;
  158.  
  159. }
  160. else {
  161. (w->prev)->next = w->next;
  162. (w->next)->prev = w->prev;
  163. }
  164. }
  165. w = w->next;
  166. }
  167. }
  168. void sort(stud* hbeg, stud* hend) {
  169. char help[20];
  170. int k;
  171. for (stud*h = hbeg; h != hend; h = h->next) {
  172. for (stud*w = h; w != hend; w = w->next) {
  173.  
  174. if (strcmp(w->uch.fio.surname, (w->next)->uch.fio.surname) > 0) {
  175.  
  176. strcpy_s(help, (w->next)->uch.fio.surname);
  177. strcpy_s((w->next)->uch.fio.surname, w->uch.fio.surname);
  178. strcpy_s(w->uch.fio.surname, help);
  179.  
  180. strcpy_s(help, (w->next)->uch.fio.name);
  181. strcpy_s((w->next)->uch.fio.name, w->uch.fio.name);
  182. strcpy_s(w->uch.fio.name, help);
  183.  
  184. strcpy_s(help, (w->next)->uch.fio.patronymic);
  185. strcpy_s((w->next)->uch.fio.patronymic, w->uch.fio.patronymic);
  186. strcpy_s(w->uch.fio.patronymic, help);
  187.  
  188. k = (w->next)->uch.exams;
  189. (w->next)->uch.exams = w->uch.exams;
  190. w->uch.exams = k;
  191.  
  192. k = (w->next)->uch.group;
  193. (w->next)->uch.group = w->uch.group;
  194. w->uch.group = k;
  195.  
  196. for (int i = 0; i < w->uch.exams; i++) {
  197. k = (w->next)->uch.mark[i];
  198. (w->next)->uch.mark[i] = w->uch.mark[i];
  199. w->uch.mark[i] = k;
  200. }
  201.  
  202. for (int i = 0; i < 7; i++) {
  203. strcpy_s(help, (w->next)->uch.disp[i]);
  204. strcpy_s((w->next)->uch.disp[i], w->uch.disp[i]);
  205. strcpy_s(w->uch.disp[i], help);
  206. }
  207.  
  208. }
  209. }
  210. }
  211. }
  212. void sort1(stud* hbeg, stud* hend) {
  213. char help[20];
  214. int k;
  215.  
  216. for (stud*h = hbeg; h != hend; h = h->next) {
  217. for (stud* w = h; w != hend; w = w->next) {
  218.  
  219. if (strcmp(w->uch.fio.surname, (w->next)->uch.fio.surname) > 0 || strcmp(w->uch.fio.surname, (w->next)->uch.fio.surname) == 0 && strcmp(w->uch.fio.name, (w->next)->uch.fio.name) > 0) {
  220.  
  221. strcpy_s(help, (w->next)->uch.fio.name);
  222. strcpy_s((w->next)->uch.fio.name, w->uch.fio.name);
  223. strcpy_s(w->uch.fio.name, help);
  224.  
  225. strcpy_s(help, (w->next)->uch.fio.surname);
  226. strcpy_s((w->next)->uch.fio.surname, w->uch.fio.surname);
  227. strcpy_s(w->uch.fio.surname, help);
  228.  
  229. strcpy_s(help, (w->next)->uch.fio.patronymic);
  230. strcpy_s((w->next)->uch.fio.patronymic, w->uch.fio.patronymic);
  231. strcpy_s(w->uch.fio.patronymic, help);
  232.  
  233. k = (w->next)->uch.exams;
  234. (w->next)->uch.exams = w->uch.exams;
  235. w->uch.exams = k;
  236.  
  237. k = (w->next)->uch.group;
  238. (w->next)->uch.group = w->uch.group;
  239. w->uch.group = k;
  240.  
  241. for (int i = 0; i < w->uch.exams; i++) {
  242. k = (w->next)->uch.mark[i];
  243. (w->next)->uch.mark[i] = w->uch.mark[i];
  244. w->uch.mark[i] = k;
  245. }
  246.  
  247. for (int j = 0; j < 7; j++) {
  248. strcpy_s(help, (w->next)->uch.disp[j]);
  249. strcpy_s((w->next)->uch.disp[j], w->uch.disp[j]);
  250. strcpy_s(w->uch.disp[j], help);
  251. }
  252.  
  253. }
  254. }
  255. }
  256. }
  257. void add_info1(stud** hbeg, stud** hend) {
  258. int k;
  259. cout<<"Введите номер ячейки, перед которой хотите вставить данные: ";
  260. cin >> k;
  261. w = new stud;
  262. h = *hbeg;
  263. cout << "Введите ФИО студента: ";
  264. cin >> w->uch.fio.surname;
  265. cin >> w->uch.fio.name;
  266. cin >> w->uch.fio.patronymic;
  267.  
  268. cout << "Введите число экзаменов: ";
  269. cin >> w->uch.exams;
  270.  
  271. cout << "Введите номер группы: ";
  272. cin >> w->uch.group;
  273.  
  274. cout << "Введите названия экзаменов: ";
  275. for (int j = 0; j < w->uch.exams; j++) {
  276. cin >> w->uch.disp[j];
  277. }
  278. for (int j = w->uch.exams; j < 7; j++) {
  279. strcpy_s(w->uch.disp[j], " ");
  280. }
  281.  
  282. cout << "Введите оценки студента по этим предметам: ";
  283. for (int j = 0; j < w->uch.exams; j++) {
  284. cin >> w->uch.mark[j];
  285. }
  286.  
  287. for (int i = 0; h != 0; i++, h = h->next) {
  288. if ((i == k) && h == *hbeg) {
  289. (*hbeg)->prev = w;
  290. w->next = *hbeg;
  291. *hbeg = w;
  292. (*hbeg)->prev = 0;
  293. }
  294. else if (i == k) {
  295. (h->prev)->next = w;
  296. w->prev = h->prev;
  297. h->prev = w;
  298. w->next = h;
  299. }
  300. }
  301. }
  302. void add_info2(stud** hbeg, stud** hend) {
  303. int k;
  304. cout<<"Введите номер ячейки, после которой хотите вставить данные: ";
  305. cin >> k;
  306. w = new stud;
  307. h = *hbeg;
  308.  
  309. cout << "Введите ФИО студента: ";
  310. cin >> w->uch.fio.surname;
  311. cin >> w->uch.fio.name;
  312. cin >> w->uch.fio.patronymic;
  313.  
  314. cout << "Введите число экзаменов: ";
  315. cin >> w->uch.exams;
  316.  
  317. cout << "Введите номер группы: ";
  318. cin >> w->uch.group;
  319.  
  320. cout << "Введите названия экзаменов: ";
  321. for (int j = 0; j < w->uch.exams; j++) {
  322. cin >> w->uch.disp[j];
  323. }
  324. for (int j = w->uch.exams; j < 7; j++) {
  325. strcpy_s(w->uch.disp[j], " ");
  326. }
  327.  
  328. cout << "Введите оценки студента по этим предметам: ";
  329. for (int j = 0; j < w->uch.exams; j++) {
  330. cin >> w->uch.mark[j];
  331. }
  332.  
  333. for (int i = 0; h != 0; i++, h = h->next) {
  334. if ((i == k) && h == *hend) {
  335. (*hend)->next = w;
  336. w->prev = *hend;
  337. w->next = 0;
  338. *hend = w;
  339. }
  340. else if (i == k) {
  341. (h->next)->prev = w;
  342. w->next = h->next;
  343. h->next = w;
  344. w->prev = h;
  345. }
  346. }
  347. }
  348. int main() {
  349. setlocale(LC_ALL, "rus");
  350. ifstream fail;
  351. fail.open("students_info.txt", ios::in);
  352. int k = -1;
  353. while (k != 10) {
  354. printf(" 1-формирование данных\n 2-добавить данные\n 3-поиск данных по ключу\n 4-удаление данных по ключу\n 5-вставка данных в массив перед i-ой записью\n 6-вставка данных в массив после i-ой записи\n 7-сортировка по фамилии\n 8-сортировка по имени и фамилии\n 9-сохранение данных в файл\n 0-вывод данных\n 10-выход\n");
  355. cin >> k;
  356. if (k == 1)
  357. read_file(&hbeg, &hend);
  358.  
  359. if (k == 2) {
  360. add_info(&hend);
  361. }
  362.  
  363. if (k == 3)
  364. search_info(hbeg);
  365.  
  366. if (k == 4) {
  367. delete_info(&hbeg, &hend);
  368. }
  369.  
  370. if (k == 5) {
  371. add_info1(&hbeg, &hend);
  372. }
  373. if (k == 6) {
  374.  
  375. add_info2(&hbeg, &hend);
  376. }
  377.  
  378. if (k == 7) {
  379. sort(hbeg, hend);
  380. }
  381.  
  382. if (k == 8) {
  383. sort1(hbeg, hend);
  384. }
  385. if (k == 9) {
  386. w = hbeg;
  387. ofstream fail;
  388. fail.open("students_info2.txt", ios::out);
  389. for (; w != 0; w = w->next) {
  390. fail << setw(25) << left << w->uch.fio.surname << " " << setw(4) << left << w->uch.exams;
  391. for (int j = 0; j < w->uch.exams; j++) {
  392. fail << w->uch.disp[j] << " ";
  393. }
  394. fail << endl;
  395. fail << setw(10) << left << w->uch.fio.name << " " << setw(15) << left << w->uch.fio.patronymic << setw(4) << left << w->uch.group << " ";
  396. for (int j = 0; j <w->uch.exams; j++) {
  397. fail << setw(4) << w->uch.mark[j] << " ";
  398. }
  399. fail << endl;
  400. }
  401. fail.close();
  402. }
  403.  
  404. if (k == 0)
  405. print_info(hbeg);
  406.  
  407. if (k == 10) {
  408. }
  409. }
  410. system("pause");
  411. return 0;
  412. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement