dariagalich

Untitled

Dec 15th, 2019
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.48 KB | None | 0 0
  1. #include <fstream>
  2. #include <stdlib.h>
  3. #include <iomanip>
  4. #include <conio.h>
  5. #include <iostream>
  6. #include <locale.h>
  7. #include <windows.h>
  8. #include <io.h>
  9. #include <fcntl.h>
  10. #include <string>
  11. using namespace std;
  12.  
  13. const string items[10] = {
  14. "Создать список или добавить новый эл-т",
  15. " Удаление элементов списка ",
  16. " Просмотр списка ",
  17. " Запись данных в файл ",
  18. " Чтение из файла ",
  19. " Изменить ",
  20. " Поиск ",
  21. " Сортировка ",
  22. " Выполнение ",
  23. " Выход "
  24. }
  25. ;
  26.  
  27. const string items2[10] =
  28. {
  29. "Сортировка по пропуску занятий(меньше) ",
  30. "Сортировка по пропуску занятий(больше)",
  31. "Выход"
  32. };
  33. const string items8[10] =
  34. {
  35. "Сортировка по пропуску лекций(меньше) ",
  36. "Сортировка по пропуску лекций(больше)",
  37. "Выход"
  38. };
  39. const string items9[10] =
  40. {
  41. "Сортировка по пропуску лекций ",
  42. "Сортировка по пропуску занятий",
  43. "Выход"
  44. };
  45.  
  46. const string items3[10] =
  47. {
  48. "Поиск по шифру группы",
  49. "Поиск среднего балла группы",
  50. "Выход"
  51. };
  52.  
  53. const string items4[10] =
  54. {
  55. "Входня таблица",
  56. "Выход"
  57. };
  58.  
  59. const string items5[10] =
  60. {
  61. "Изменить шифр группы",
  62. "Изменить шифр дисципилны",
  63. "Выход"
  64. };
  65.  
  66. const string items6[10] =
  67. {
  68. "Чтение файла ",
  69. "Чтение бинарного файла",
  70. "Выход"
  71. };
  72. const string items7[10] =
  73. {
  74. "Запись файла ",
  75. "Запись бинарного файла",
  76. "Выход"
  77. };
  78.  
  79. const int
  80. up = 72,
  81. down = 80,
  82. right_btn = 77,
  83. left_btn = 75,
  84. enter = 13,
  85. esc = 27,
  86. del = 83,
  87. dl = 20;
  88. //-------------------------------------------
  89. int height = 0, width = 0;
  90. int koli = 1;
  91. //-------------------------------------------
  92.  
  93. //-------------------------------------------
  94. struct tabl
  95. {
  96. string shg;
  97. string shd, ot, xoro, yd, noyd, prl, prz;
  98. float srb = 0;
  99.  
  100.  
  101. };
  102.  
  103. struct tabli
  104. {
  105. tabl t;
  106. tabli* next = 0;
  107. tabli* pred = 0;
  108. };
  109. //-------------------------------------------
  110.  
  111. tabli* dob(tabli* end, const tabli& z);
  112. tabli* dob_first(const tabli& z);
  113. tabli* udal(tabli* beg);
  114. void output(tabli* beg);
  115. //tabli* delete_el(tabli* beg);
  116. tabli vvod_tabli();
  117. void prosmotr_vh(tabli* beg);
  118. void prosmotr_vih(tabli* beg);
  119. void SetColor(int text, int bg);
  120. void poiskshd(tabli* beg);
  121. int read_file(string filename, tabli** beg, tabli** end);
  122. int write_file(string filename, tabli* temp);
  123. int read_bin_file(string filename, tabli** beg, tabli** end);
  124. int write_file_binary(string filename, tabli* beg);
  125. void cls();
  126. int changeshg(tabli* beg, string& user_shg, string& new_user_shg);
  127. int changeshd(tabli* beg, string& user_shd, string& new_user_shd);
  128. void poiskshg(tabli* beg);
  129. void sortirovka_prz(tabli** beg);
  130. void sortirovka_prz1(tabli** beg);
  131. void sortirovka_prl(tabli** beg);
  132. void sortirovka_prl1(tabli** beg);
  133. void print_vih(const tabli& z);
  134. void print_vh(const tabli& z);
  135. void gotoxy(int xpos, int ypos);
  136. int menu(int& active, const string items[], int num_el);
  137. int menu2(int& active, const string items[], int num_el);
  138. //-------------------------------------------------------------------------
  139.  
  140.  
  141. //-------------------------------------------------------------------------
  142. int main()
  143. {
  144.  
  145. // меняем размер шрифта
  146. CONSOLE_FONT_INFOEX cfi;
  147. cfi.cbSize = sizeof(cfi);
  148. cfi.nFont = 0;
  149. cfi.dwFontSize.X = 0;
  150. cfi.dwFontSize.Y = 19; //шрифт
  151. cfi.FontFamily = FF_DONTCARE;
  152. cfi.FontWeight = FW_NORMAL;
  153. SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
  154. //-------------------------------------------------------------------------
  155.  
  156.  
  157. //-------------------------------------------------------------------------
  158.  
  159. HANDLE hCon;
  160.  
  161. // ширина и высоат
  162. hCon = GetStdHandle(-12);
  163. CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
  164. if (GetConsoleScreenBufferInfo(hCon, &consoleInfo))
  165. {
  166. width = consoleInfo.srWindow.Right - consoleInfo.srWindow.Left + 1;
  167. height = consoleInfo.srWindow.Bottom - consoleInfo.srWindow.Top + 1;
  168. }
  169. //-------------------------------------------------------------------------
  170.  
  171.  
  172. //-------------------------------------------------------------------------
  173. system("cls");
  174. ShowWindow(GetConsoleWindow(), SW_MAXIMIZE); // полноэкранный режим
  175. setlocale(LC_ALL, "Rus");
  176. system("color 2B");
  177. tabli* beg = NULL,
  178. * end = NULL, input;
  179. string filename;
  180. int n = 0;
  181.  
  182. int current = 1;
  183. string user_shg, new_user_shg;
  184. string user_shd, new_user_shd;
  185. while (1)
  186. {
  187. system("cls");
  188. switch (menu(current, items, 10))
  189. {
  190. case 1://создание списка или добовление нового эл-та в список
  191. system("cls");
  192. if (beg)
  193. end = dob(end, vvod_tabli());
  194. else
  195. {
  196. beg = dob_first(vvod_tabli());
  197. end = beg;
  198. }
  199. koli++;
  200. break;
  201. case 2:
  202. system("cls");//удаление всех элементов в списке
  203. //beg = delete_el(beg);
  204. cout << "Нажмите любую клавишу" << endl;
  205. cin.get();
  206. break;
  207. case 3:
  208.  
  209. //просмотр
  210. current = 1;
  211. switch (menu2(current, items4, 2))
  212. {
  213.  
  214. case 1:
  215. system("cls");
  216. //prosmotr_vh(beg);
  217. output(beg);
  218.  
  219. break;
  220.  
  221. case 2:
  222. system("cls");
  223. break;
  224. }
  225.  
  226. break;
  227.  
  228. case 4://запись
  229. current = 1;
  230. switch (menu2(current, items7, 3))
  231. {
  232. case 1:
  233. system("cls");
  234. write_file(filename, beg);
  235. break;
  236. case 2:
  237. system("cls");
  238. write_file_binary(filename, beg);
  239. break;
  240.  
  241. case 3:
  242. system("cls");
  243. break;
  244. }
  245. break;
  246. case 5://чтение
  247. current = 1;
  248. switch (menu2(current, items6, 3))
  249. {
  250. case 1:
  251. system("cls");
  252. //чтение из файла
  253. read_file(filename, &beg, &end);
  254. break;
  255. case 2:
  256. system("cls");
  257. read_bin_file(filename, &beg, &end);
  258. break;
  259. case 3:
  260. break;
  261. }
  262. break;
  263. case 6://изменение
  264. system("cls");
  265.  
  266. {
  267. int Num, current = 1;
  268. switch (menu2(current, items5, 3))
  269. {
  270. case 1:
  271. system("cls");
  272.  
  273. cout << "Введите шифр группы, которую вы хотите изменить: " << endl;
  274. cin >> user_shg;
  275. cout << "Введите новый шифр: " << endl;
  276. cin >> new_user_shg;
  277. Num = changeshg(beg, user_shg, new_user_shg);
  278. if (Num == 1) cout << "шифр перезаписан." << endl;
  279. else cout << "шифр не найден!" << endl;
  280. system("pause");
  281. changeshg(beg, user_shg, new_user_shg);
  282. cin.get();
  283. break;
  284. case 2:
  285. system("cls");
  286.  
  287. cout << "Введите шифр дисциплины, которую вы хотите изменить: " << endl;
  288. cin >> user_shd;
  289. cout << "Введите новый шифр: " << endl;
  290. cin >> new_user_shd;
  291. Num = changeshd(beg, user_shd, new_user_shd);
  292. if (Num == 1) cout << "шифр перезаписан." << endl;
  293. else cout << "шифр не найден!" << endl;
  294. system("pause");
  295. changeshd(beg, user_shd, new_user_shd);
  296. cin.get();
  297. break;
  298. case 3:
  299. system("cls");
  300.  
  301. break;
  302. }
  303. break;
  304. }
  305.  
  306. case 7:
  307. system("cls");
  308. //поиск
  309. {
  310. int current = 1;
  311. switch (menu2(current, items3, 3))
  312. {
  313. case 1:
  314. system("cls");
  315.  
  316. poiskshg(beg);
  317. cin.get();
  318. break;
  319. case 2:
  320. system("cls");
  321.  
  322. poiskshd(beg);
  323. cin.get();
  324. break;
  325. case 3:
  326. break;
  327. }
  328. break;
  329. }
  330. case 8://ростировка
  331. system("cls");
  332.  
  333. {
  334. int current = 1;
  335. switch (menu2(current, items9, 3))
  336. {
  337. case 1:
  338. {
  339. system("cls");
  340.  
  341.  
  342. switch (menu2(current, items8, 3))
  343. {
  344. case 1:
  345.  
  346. system("cls");
  347. sortirovka_prl(&beg);
  348. prosmotr_vh(beg);
  349. cin.get();
  350. break;
  351.  
  352.  
  353.  
  354. case 2:
  355.  
  356.  
  357. system("cls");
  358. sortirovka_prl1(&beg);
  359. prosmotr_vh(beg);
  360. cin.get();
  361. break;
  362.  
  363. case 3:
  364.  
  365. break;
  366. }
  367. break;
  368. }
  369. case 2:
  370. {
  371. system("cls");
  372. switch (menu2(current, items2, 3))
  373. {
  374. case 1:
  375. system("cls");
  376. sortirovka_prz(&beg);
  377. prosmotr_vh(beg);
  378. cin.get();
  379. break;
  380. case 2:
  381. system("cls");
  382. sortirovka_prz1(&beg);
  383. prosmotr_vh(beg);
  384. cin.get();
  385. break;
  386. case 3:
  387. break;
  388. }
  389. break;
  390. }
  391.  
  392.  
  393. case 3:
  394. break;
  395.  
  396. }
  397. break;
  398. }
  399. case 9://выполнение
  400. system("cls");
  401.  
  402. {
  403. prosmotr_vih(beg);
  404. break;
  405. }
  406. case 10://выход
  407. system("cls");
  408.  
  409. return 0;
  410. }
  411.  
  412. }
  413. int saved = 0;
  414. return 0;
  415. }
  416.  
  417.  
  418.  
  419.  
  420. //-----------------------------------------------------------------------------
  421. tabli* dob(tabli* end, const tabli& z)
  422. {
  423. tabli* newE = new tabli;
  424. *newE = z;
  425. newE->next = 0;
  426. end->next = newE;
  427. end = newE;
  428. return end;
  429. }
  430. //-----------------------------------------------------------------------------
  431.  
  432. //-----------------------------------------------------------------------------
  433. tabli* dob_first(const tabli& z)
  434. {
  435. tabli* beg = new tabli;
  436. *beg = z;
  437. beg->next = 0;
  438. return beg;
  439. }
  440. //-----------------------------------------------------------------------------
  441.  
  442. //-----------------------------------------------------------------------------
  443. tabli* udal(tabli* beg)
  444. {
  445. tabli* temp;
  446. if (!beg)
  447. {
  448. cout << "список пустой" << endl;
  449. cin.get();
  450. return 0;
  451. }
  452. while (beg)
  453. {
  454. temp = beg;
  455. beg = beg->next;
  456. delete temp;
  457. }
  458.  
  459. cout << "удаление прошло успешно" << endl;
  460.  
  461. return beg;
  462. }
  463. //-----------------------------------------------------------------------------
  464.  
  465. //-----------------------------------------------------------------------------
  466. tabli vvod_tabli()
  467. {
  468.  
  469. tabli z;
  470. cout << "Введите шифр группы:" << endl;
  471. while (1)
  472. {
  473. cin >> z.t.shg;
  474. if ((z.t.shg).length() == 6)
  475. break;
  476. cout << "Ошибка ввода!" << endl;
  477. }
  478. cout << "Введите шифр дисциплины:" << endl;
  479. while (1)
  480. {
  481. cin >> z.t.shd;
  482. if ((z.t.shd).length() == 6)
  483. break;
  484. cout << "Ошибка ввода!" << endl;
  485. }
  486. cout << "Введите количество оценок отлично:" << endl;
  487. while (1)
  488. {
  489. cin >> z.t.ot;
  490. if (!cin) {
  491. cin.clear();
  492. cin.ignore(INT_MAX, '\n');
  493. }
  494. else if (stoi((z.t.ot)) >= 0)
  495. break;
  496. cout << "Ошибка ввода, введена буква !" << endl;
  497. }
  498. cout << "Введите количество оценок хорошо:" << endl;
  499.  
  500. while (1)
  501. {
  502. cin >> z.t.xoro;
  503. if (!cin) {
  504. cin.clear();
  505. cin.ignore(INT_MAX, '\n');
  506. }
  507. else if (stoi((z.t.xoro)) >= 0)
  508. break;
  509. cout << "Ошибка ввода, введена буква !" << endl;
  510. }
  511. cout << "Введите количество оценок удовлетворительно:" << endl;
  512. while (1)
  513. {
  514. cin >> z.t.yd;
  515. if (!cin) {
  516. cin.clear();
  517. cin.ignore(INT_MAX, '\n');
  518. }
  519. else if (stoi((z.t.yd)) >= 0)
  520. break;
  521. cout << "Ошибка ввода, введена буква !!" << endl;
  522. }
  523. cout << "Введите количество оценок неудовлетворительно:" << endl;
  524. while (1)
  525. {
  526. cin >> z.t.noyd;
  527. if (!cin) {
  528. cin.clear();
  529. cin.ignore(INT_MAX, '\n');
  530. }
  531. else if (stoi((z.t.noyd)) >= 0)
  532. break;
  533. cout << "Ошибка ввода, введена буква !!" << endl;
  534. }
  535. cout << "Введите количество пропущеныйх лекций:" << endl;
  536. while (1)
  537. {
  538. cin >> z.t.prl;
  539. if (!cin) {
  540. cin.clear();
  541. cin.ignore(INT_MAX, '\n');
  542. }
  543. else if (stoi((z.t.prl)) >= 0)
  544. break;
  545. cout << "Ошибка ввода, введена буква !!" << endl;
  546. }
  547. cout << "Введите количество пропущеныйх практических заданй:" << endl;
  548. while (1)
  549. {
  550. cin >> z.t.prz;
  551. if (!cin) {
  552. cin.clear();
  553. cin.ignore(INT_MAX, '\n');
  554. }
  555. else if (stoi((z.t.prz)) >= 0)
  556. break;
  557. cout << "Ошибка ввода, введена буква !" << endl;
  558. }
  559. z.t.srb = (((5 * stoi(z.t.ot)) + (4 * stoi(z.t.xoro)) + (3 * stoi(z.t.yd)) + (2 * stoi(z.t.noyd))) / (stoi(z.t.ot) + stoi(z.t.xoro) + stoi(z.t.yd) + stoi(z.t.noyd)));
  560. koli++;
  561. return z;
  562.  
  563. }
  564. //-----------------------------------------------------------------------------
  565.  
  566. //-----------------------------------------------------------------------------
  567. void prosmotr_vih(tabli* beg)
  568. {
  569. if (!beg)
  570. {
  571. cout << "список пустой" << endl;
  572. cin.get();
  573. return;
  574. }
  575. tabli* temp = beg;
  576.  
  577. cout << "+———————————————————+————————————————————+———————————————————+———————————————————+ " << endl;
  578. cout << "| | | Количество Количество | " << endl;
  579. cout << "| Шифр группы | Средний бал +——————————+—————————+———————+————————— | " << endl;
  580. cout << "| | | Отл. | Хор. |Удовл. | Неуд. | " << endl;
  581. cout << "+———————————————————+————————————————————+——————————+—————————+———————+————————— + " << endl;
  582. while (temp)
  583. {
  584.  
  585. print_vih(*temp);
  586.  
  587. temp = temp->next;
  588. }
  589.  
  590. cout << "+———————————————————+————————————————————+——————————+—————————+———————+——————————+ " << endl;
  591.  
  592. cin.get();
  593.  
  594. }//-------------------------------------------------------------------------
  595.  
  596.  
  597. //-----------------------------------------------------------------------------
  598. void prosmotr_vh(tabli* beg)
  599. {
  600. int l=0;
  601. if (!beg)
  602. {
  603. cout << "список пустой" << endl;
  604. cin.get();
  605. return;
  606. }
  607. tabli* temp = beg;
  608.  
  609. cout << "+—+———————————————————+————————————————————+—————————————————————————————————————— +————————————————————————————————+—————————————————————————————————+ " << endl;
  610. cout << "| | | | Количество Количество | | | " << endl;
  611. cout << "|№| Шифр группы | Шифр дисциплины |——————————+—————————+———————+————————— | пропущено лекций | пропущено практических занятий + " << endl;
  612. cout << "| | | | Отл. | Хор. |Удовл. | Неуд. | | | " << endl;
  613. cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
  614. while (temp)
  615. {
  616. cout << "|" << ++l << "|";
  617. print_vh(*temp);
  618. temp = temp->next;
  619. }
  620.  
  621. cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
  622.  
  623. cin.get();
  624. }
  625. //-----------------------------------------------------------------------------
  626.  
  627.  
  628. //-----------------------------------------------------------------------------
  629. void print_vih(const tabli& z)
  630. {
  631.  
  632. cout << "|" << z.t.shg << setw(20 - (z.t.shg).length()) << "|";
  633. cout << z.t.srb << setw(20);
  634. cout << z.t.ot << setw(10 - (z.t.ot).length()) << "|";
  635. cout << z.t.xoro << setw(9 - (z.t.xoro).length()) << "|";
  636. cout << z.t.yd << setw(7 - (z.t.yd).length()) << "|";
  637. cout << z.t.noyd << setw(10 - (z.t.noyd).length()) << "|" << endl;
  638. }
  639. //-----------------------------------------------------------------------------
  640.  
  641.  
  642. //-----------------------------------------------------------------------------
  643. void print_vh(const tabli& z)
  644. {
  645.  
  646. cout << z.t.shg << setw(20 - (z.t.shg).length()) << "|";
  647. cout << z.t.shd << setw(21 - (z.t.shd).length()) << "|";
  648. cout << z.t.ot << setw(11 - (z.t.ot).length()) << "|";
  649. cout << z.t.xoro << setw(10 - (z.t.xoro).length()) << "|";
  650. cout << z.t.yd << setw(8 - (z.t.yd).length()) << "|";
  651. cout << z.t.noyd << setw(11 - (z.t.noyd).length()) << "|";
  652. cout << z.t.prl << setw(33 - (z.t.prl).length()) << "|";
  653. cout << z.t.prz << setw(34 - (z.t.prz).length()) << "|" << endl;
  654. }
  655. //-----------------------------------------------------------------------------
  656.  
  657.  
  658. //-----------------------------------------------------------------------------
  659. void poiskshd(tabli* beg)
  660. {
  661. int k = 0;
  662. tabli* temp = beg;
  663. int fl = 0;
  664. char fa[dl];
  665. system("cls");
  666. if (!beg)
  667. {
  668. MessageBox(0, L"Список пуст", L"Уведомление", MB_ICONINFORMATION | MB_SETFOREGROUND);
  669. return;
  670. }
  671. cout << "Введите шифр дисциплины для поиска " << endl;
  672. cin >> fa;
  673.  
  674. cout << "+—+———————————————————+————————————————————+—————————————————————————————————————— +————————————————————————————————+—————————————————————————————————+ " << endl;
  675. cout << "| | | | Количество Количество | | | " << endl;
  676. cout << "|№| Шифр группы | Шифр дисциплины |——————————+—————————+———————+————————— | пропущено лекций | пропущено практических занятий + " << endl;
  677. cout << "| | | | Отл. | Хор. |Удовл. | Неуд. | | | " << endl;
  678. cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
  679. while (temp)
  680. {
  681. if (fa == temp->t.shd)
  682. {
  683. cout << "|" << ++k << "|";
  684. print_vh(*temp);
  685. fl = 1;
  686. }
  687. temp = temp->next;
  688. }
  689. cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
  690.  
  691. if (fl != 1) {
  692. cout << "Дисципоина с таким шифром не найдена" << endl;
  693. }
  694. system("pause");
  695. }
  696. //-----------------------------------------------------------------------------
  697.  
  698.  
  699. //-----------------------------------------------------------------------------
  700. int read_file(string filename, tabli** beg, tabli** end)
  701. {
  702. cout << "Введите название файла" << endl;
  703. cin >> filename;
  704. ifstream fin(filename, ios::in);
  705. if (!fin)
  706. {
  707. cout << "Нет файла" << filename << endl;
  708. return 1;
  709. }
  710. tabli z;
  711. *beg = 0;
  712. fin.seekg(0, ios::beg);
  713. while (fin >> z.t.shg)
  714. {
  715. fin >> z.t.shd;
  716. fin >> z.t.ot;
  717. fin >> z.t.xoro;
  718. fin >> z.t.yd;
  719. fin >> z.t.noyd;
  720. fin >> z.t.prl;
  721. fin >> z.t.prz;
  722. fin >> z.t.srb;
  723. if (*beg)
  724. *end = dob(*end, z);
  725. else
  726. {
  727. *beg = dob_first(z); *end = *beg;
  728. }
  729. koli++;
  730. }
  731. cout << "Считывание прошло успешно" << endl;
  732. cin.get();
  733. cin.get();
  734. return 0;
  735. }
  736. //-----------------------------------------------------------------------------
  737.  
  738.  
  739. //-----------------------------------------------------------------------------
  740. int write_file(string filename, tabli* temp)
  741. {
  742. cout << "Введите название файла" << endl;
  743. cin >> filename;
  744. ofstream fout(filename, ios_base::app); // открытие файла
  745. if (!fout)
  746. {
  747. cout << "Не могу открыть файл для записи" << endl;
  748. return 1;
  749. }
  750. while (temp)// пока temp!=0 выводим эл-ты в файл
  751. {
  752. fout << temp->t.shg << endl;
  753. fout << temp->t.shd << endl;
  754. fout << temp->t.ot << endl;
  755. fout << temp->t.xoro << endl;
  756. fout << temp->t.yd << endl;
  757. fout << temp->t.noyd << endl;
  758. fout << temp->t.prl << endl;
  759. fout << temp->t.prz << endl;
  760. temp = temp->next;
  761. }
  762. cout << "Данные сохранены в файле: " << filename << endl;
  763. cout << "==============================" << endl;
  764. cout << "Нажмите любую клавишу" << endl;
  765. cin.get();
  766. return 0;
  767. }
  768. //-----------------------------------------------------------------------------
  769.  
  770.  
  771. //-----------------------------------------------------------------------------
  772. void print_menu(int sym, const string items[], const int N_ITEMS)
  773. {
  774.  
  775. for (int i = 1; i <= N_ITEMS; i++)
  776. {
  777. SetColor(14, 2);
  778. gotoxy((width / 2) - 10, (height / 2) + i - 3);// ставим меню в центр
  779. if (i == sym)
  780. {
  781. SetColor(3, 15);
  782. }
  783. cout << items[i - 1] << endl;
  784. SetColor(14, 2);
  785. }
  786. }
  787. void print_menu2(int sym, const string items[], const int N_ITEMS)
  788. {
  789.  
  790. for (int i = 1; i <= N_ITEMS; i++)
  791. {
  792. SetColor(14, 2);
  793.  
  794. if (i == sym)
  795. {
  796. SetColor(3, 15);
  797. }
  798. cout << items[i - 1] << endl;
  799. SetColor(14, 2);
  800. }
  801. }
  802. //-----------------------------------------------------------------------------
  803.  
  804.  
  805. //-----------------------------------------------------------------------------
  806.  
  807. int menu(int& active, const string items[], int num_el) {
  808. wint_t buf;
  809.  
  810. while (1)
  811. {
  812.  
  813. cls();
  814. print_menu(active, items, num_el);
  815.  
  816. buf = _getwch();
  817. switch (buf)
  818. {
  819. case up: // клавиша вверх
  820. if (active > 1) active--;
  821. break;
  822. case down: // клавиша вниз
  823. if (active < num_el) active++;
  824. break;
  825. case enter: // клавиша enter
  826. return active;
  827. case esc: // клавиша escape
  828. return -1;
  829. }
  830. }
  831. }
  832. //-----------------------------------------------------------------------------
  833.  
  834. //-----------------------------------------------------------------------------
  835. int menu2(int& active, const string items[], int num_el)
  836. {
  837. wint_t buf;
  838.  
  839. do
  840. {
  841.  
  842. system("cls");
  843. print_menu2(active, items, num_el);
  844.  
  845. buf = _getwch();
  846. switch (buf)
  847. {
  848. case up: // клавиша вверх
  849. if (active > 1) active--;
  850. break;
  851. case down: // клавиша вниз
  852. if (active < num_el) active++;
  853. break;
  854. case enter: // клавиша enter
  855. return active;
  856. case esc: // клавиша escape
  857. return -1;
  858. }
  859. } while (1);
  860. }
  861. //-----------------------------------------------------------------------------
  862.  
  863.  
  864. //-----------------------------------------------------------------------------
  865. int changeshd(tabli* beg, string& user_shd, string& new_user_shd)
  866. {
  867. tabli* temp = beg;
  868. while (temp != NULL)
  869. {
  870. if (temp->t.shd == user_shd)
  871. {
  872. temp->t.shd = new_user_shd;
  873. return 1;
  874. }
  875. else
  876. {
  877. temp = temp->next;
  878.  
  879. }
  880. }
  881.  
  882. return 0;
  883. }
  884. //-----------------------------------------------------------------------------
  885.  
  886.  
  887. //-----------------------------------------------------------------------------
  888. int changeshg(tabli* beg, string& user_shg, string& new_user_shg)
  889. {
  890. tabli* temp = beg;
  891.  
  892. while (temp != NULL)
  893. {
  894. if (temp->t.shg == user_shg)
  895. {
  896. temp->t.shg = new_user_shg;
  897. return 1;
  898. }
  899.  
  900. else
  901. {
  902. temp = temp->next;
  903.  
  904. }
  905. }
  906.  
  907. return 0;
  908. }
  909. //-----------------------------------------------------------------------------
  910.  
  911.  
  912. //-----------------------------------------------------------------------------
  913. void poiskshg(tabli* beg)
  914. {
  915. tabli* temp = beg;
  916. int k = 0;
  917. int fl = 0;
  918. char fa[dl];
  919. system("cls");
  920. if (!beg)
  921. {
  922. MessageBox(0, L"Список пуст", L"Уведомление", MB_ICONINFORMATION | MB_SETFOREGROUND);
  923. return;
  924. }
  925. cout << "Введите шифр для поиска группы" << endl;
  926. cin >> fa;
  927. cout << "+—+———————————————————+————————————————————+—————————————————————————————————————— +————————————————————————————————+—————————————————————————————————+ " << endl;
  928. cout << "| | | | Количество Количество | | | " << endl;
  929. cout << "|№| Шифр группы | Шифр дисциплины |——————————+—————————+———————+————————— | пропущено лекций | пропущено практических занятий + " << endl;
  930. cout << "| | | | Отл. | Хор. |Удовл. | Неуд. | | | " << endl;
  931. cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
  932. while (temp)
  933. {
  934. if (fa == temp->t.shg)
  935. {
  936. cout << "|" << ++k << "|";
  937. print_vh(*temp);
  938. fl = 1;
  939. }
  940. temp = temp->next;
  941. }
  942. cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
  943.  
  944. if (fl != 1) {
  945. cout << "Группа с таким шифром не найдена" << endl;
  946. }
  947. system("pause");
  948. }
  949. //-----------------------------------------------------------------------------
  950.  
  951. //-----------------------------------------------------------------------------
  952. void SetColor(int text, int bg) {
  953. HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  954. SetConsoleTextAttribute(hStdOut, (WORD)((bg << 4) | text));
  955. }
  956. void schetsrb(tabli* beg)
  957. {
  958. if (!beg)
  959. {
  960. cout << "список пустой" << endl;
  961. cin.get();
  962. return;
  963. }
  964.  
  965. tabli* temp = beg;
  966. while (temp)
  967. {
  968. temp->t.srb = (5 * stoi(temp->t.ot) + 4 * stoi(temp->t.xoro) + 3 * stoi(temp->t.yd) + 2 * stoi(temp->t.noyd)) / (stoi(temp->t.ot) + stoi(temp->t.xoro) + stoi(temp->t.yd) + stoi(temp->t.noyd));
  969. }
  970. }
  971. //-----------------------------------------------------------------------------
  972.  
  973. //-----------------------------------------------------------------------------
  974. void sortirovka_prz(tabli** beg)
  975. {
  976. tabli* temp_i = *beg,
  977. * temp_j = *beg;
  978.  
  979. for (; temp_i; temp_i = temp_i->next)
  980. {
  981. for (temp_j = temp_i; temp_j; temp_j = temp_j->next)
  982. {
  983. if (temp_i->t.prz < temp_j->t.prz)
  984. {
  985. swap(temp_i->t, temp_j->t);
  986. }
  987. }
  988. }
  989.  
  990.  
  991. cout << "Сортировка прошла успешно" << endl;
  992.  
  993. }
  994. //-----------------------------------------------------------------------------
  995.  
  996.  
  997. //-----------------------------------------------------------------------------
  998. void sortirovka_prz1(tabli** beg)
  999. {
  1000. tabli* temp_i = *beg,
  1001. * temp_j = *beg;
  1002.  
  1003. for (; temp_i; temp_i = temp_i->next)
  1004. {
  1005. for (temp_j = temp_i; temp_j; temp_j = temp_j->next)
  1006. {
  1007. if (temp_i->t.prz > temp_j->t.prz)
  1008. {
  1009. swap(temp_i->t, temp_j->t);
  1010. }
  1011. }
  1012. }
  1013.  
  1014.  
  1015. cout << "Сортировка прошла успешно" << endl;
  1016.  
  1017. }
  1018. //-----------------------------------------------------------------------------
  1019.  
  1020.  
  1021. //-----------------------------------------------------------------------------
  1022. void sortirovka_prl(tabli** beg)
  1023. {
  1024. tabli* temp_i = *beg,
  1025. * temp_j = *beg;
  1026.  
  1027. for (; temp_i; temp_i = temp_i->next)
  1028. {
  1029. for (temp_j = temp_i; temp_j; temp_j = temp_j->next)
  1030. {
  1031. if (temp_i->t.prl < temp_j->t.prl)
  1032. {
  1033. swap(temp_i->t, temp_j->t);
  1034. }
  1035. }
  1036. }
  1037. cout << "Сортировка прошла успешно" << endl;
  1038. }
  1039.  
  1040. //-----------------------------------------------------------------------------
  1041.  
  1042.  
  1043. //-----------------------------------------------------------------------------
  1044. void sortirovka_prl1(tabli** beg)
  1045. {
  1046. tabli* temp_i = *beg,
  1047. * temp_j = *beg;
  1048.  
  1049. for (; temp_i; temp_i = temp_i->next)
  1050. {
  1051. for (temp_j = temp_i; temp_j; temp_j = temp_j->next)
  1052. {
  1053. if (temp_i->t.prl > temp_j->t.prl)
  1054. {
  1055. swap(temp_i->t, temp_j->t);
  1056. }
  1057. }
  1058. }
  1059. cout << "Сортировка прошла успешно" << endl;
  1060. }
  1061. //-----------------------------------------------------------------------------
  1062.  
  1063.  
  1064. //-----------------------------------------------------------------------------
  1065.  
  1066. void gotoxy(int xpos, int ypos)
  1067. {
  1068.  
  1069. COORD scrn;
  1070.  
  1071. HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE);
  1072.  
  1073. scrn.X = xpos; scrn.Y = ypos;
  1074.  
  1075. SetConsoleCursorPosition(hOuput, scrn);
  1076.  
  1077. }
  1078. //-----------------------------------------------------------------------------
  1079.  
  1080.  
  1081. //-----------------------------------------------------------------------------
  1082. void cls()
  1083. {
  1084. HANDLE hd = GetStdHandle(STD_OUTPUT_HANDLE);
  1085. COORD cd;
  1086. cd.X = 0;
  1087. cd.Y = 0;
  1088. SetConsoleCursorPosition(hd, cd);
  1089. }
  1090.  
  1091.  
  1092. int write_file_binary(string filename, tabli* beg)
  1093. {
  1094. cout << "Введите название файла" << endl;
  1095. cin >> filename;
  1096. tabli* temp = beg;
  1097. ofstream fout(filename + ".dat", ios::binary); // открытие файла
  1098. if (!fout)
  1099. {
  1100. cout << "Не могу открыть файл для записи" << endl;
  1101. return 1;
  1102. }
  1103. while (temp) {
  1104. fout.write((char*)&temp->t, sizeof temp->t);
  1105. temp = temp->next;
  1106. }
  1107. fout.close();
  1108. cout << "Данные сохранены в файле: " << filename << endl;
  1109. cout << "==============================" << endl;
  1110. cout << "Нажмите любую клавишу" << endl;
  1111. cin.get();
  1112. return 0;
  1113. }
  1114.  
  1115. // ==========ЧТЕНИЕ ИЗ БИНАРНОГО ФАЙЛА==========
  1116. int read_bin_file(string filename, tabli** beg, tabli** end)
  1117. {
  1118. cout << "Введите название файла" << endl;
  1119. cin >> filename;
  1120. ifstream fin(filename + ".dat", ios::binary);
  1121.  
  1122. if (!fin) {
  1123. MessageBox(0, L"Нет файла!", L"Ошибка", MB_ICONERROR | MB_SETFOREGROUND);
  1124. return 1;
  1125. }
  1126.  
  1127. fin.seekg(ios_base::beg);
  1128. tabli* t = new tabli;
  1129. t->next = NULL;
  1130. t->pred = NULL;
  1131. *beg = 0;
  1132.  
  1133. while (fin.read((char*)&t->t, sizeof t->t))
  1134. {
  1135. if (*beg)
  1136. *end = dob(*end, *t);
  1137. else {
  1138. *beg = dob_first(*t);
  1139. *end = *beg;
  1140. }
  1141. }
  1142.  
  1143. fin.close();
  1144. return 0;
  1145. }
  1146. //=========================================================
  1147. void output(tabli* beg)
  1148. {
  1149. tabli* temp = beg;
  1150. int i = 0;
  1151. int k = 0;
  1152. int temp_k;
  1153. int temp_i;
  1154. int key;
  1155. if (!beg) {
  1156. cout << L"Ошибка! Список пуст." << endl;
  1157. system("pause");
  1158. return;
  1159. }
  1160. while (temp) {
  1161. i++;
  1162. temp = temp->next;
  1163. }
  1164.  
  1165. if (i % 8 == 0)
  1166. temp_k = i / 8;
  1167. else
  1168. temp_k = i / 8 + 1;
  1169. cout << "+—+———————————————————+————————————————————+—————————————————————————————————————— +————————————————————————————————+—————————————————————————————————+ " << endl;
  1170. cout << "| | | | Количество Количество | | | " << endl;
  1171. cout << "|№| Шифр группы | Шифр дисциплины |——————————+—————————+———————+————————— | пропущено лекций | пропущено практических занятий + " << endl;
  1172. cout << "| | | | Отл. | Хор. |Удовл. | Неуд. | | | " << endl;
  1173. cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
  1174. temp = beg;
  1175. if (i > 7)
  1176. temp_i = 8;
  1177. else temp_i = i;
  1178. for (i = 0; i != temp_i; i++) {
  1179. cout << "|" << ++k << "|";
  1180. print_vh(*temp);
  1181. temp = temp->next;
  1182. if (i == temp_i - 1)
  1183. cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
  1184. }
  1185.  
  1186. while (1) {
  1187. key = _getch();
  1188. switch (key) {
  1189. case 73:
  1190.  
  1191. if (k == 0)
  1192. break;
  1193. system ("cls");
  1194. cout << "+—+———————————————————+————————————————————+—————————————————————————————————————— +————————————————————————————————+—————————————————————————————————+ " << endl;
  1195. cout << "| | | | Количество Количество | | | " << endl;
  1196. cout << "|№| Шифр группы | Шифр дисциплины |——————————+—————————+———————+————————— | пропущено лекций | пропущено практических занятий + " << endl;
  1197. cout << "| | | | Отл. | Хор. |Удовл. | Неуд. | | | " << endl;
  1198. cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
  1199. --k;
  1200. temp = beg;
  1201. i = 0;
  1202. while (((k - 1) * 8 != i) && (temp)) {
  1203. i++;
  1204. temp = temp->next;
  1205. }
  1206. while (((i % 8 != 0) || ((k - 1) * 8 == i)) && (temp)) {
  1207. i++;
  1208. print_vh(*temp);
  1209. temp = temp->next;
  1210. cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
  1211. }
  1212. if ((i % 8 == 0) || (!temp))
  1213. gotoxy(0, 3 + 2 * (i - (k - 1) * 8));
  1214. cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
  1215. break;
  1216. case 81:
  1217.  
  1218. if (k == temp_k)
  1219. break;
  1220. system("cls");
  1221. cout << "+—+———————————————————+————————————————————+—————————————————————————————————————— +————————————————————————————————+—————————————————————————————————+ " << endl;
  1222. cout << "| | | | Количество Количество | | | " << endl;
  1223. cout << "|№| Шифр группы | Шифр дисциплины |——————————+—————————+———————+————————— | пропущено лекций | пропущено практических занятий + " << endl;
  1224. cout << "| | | | Отл. | Хор. |Удовл. | Неуд. | | | " << endl;
  1225. cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
  1226.  
  1227. ++k;
  1228. temp = beg;
  1229. i = 0;
  1230. while (temp) {
  1231. i++;
  1232. temp = temp->next;
  1233. }
  1234.  
  1235. if (i % 8 == 0)
  1236. temp_k = i / 8;
  1237. else
  1238. temp_k = i / 8 + 1;
  1239.  
  1240. temp = beg;
  1241. if (i > 7)
  1242. temp_i = 8;
  1243. else temp_i = i;
  1244. for (i = 0; i != temp_i; i++) {
  1245. cout << "|" << ++k << "|";
  1246. print_vh(*temp);
  1247. temp = temp->next;
  1248. if (i == temp_i - 1)
  1249. cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
  1250. }
  1251. if ((i % 8 == 0) || (!temp))
  1252. cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
  1253. break;
  1254. case 27:
  1255. return;
  1256. default:
  1257. break;
  1258. }
  1259. }
  1260. }
  1261. /*tabli* list(tabli* beg, int active, int page, int k)
  1262. {
  1263. tabli* temp = beg,
  1264. * buf_temp = beg,
  1265. * buf_el = beg,
  1266. * first_temp = beg;
  1267.  
  1268. int c = 0,
  1269. key = 0,
  1270. extreme_page = 2,// переменная для первой страницы, если это первая страница, тогда 1, в остальных случаях = 2
  1271. first_k = 0,
  1272. k_this_page = 0;
  1273.  
  1274. int num_del = 0; // номер для удаления
  1275. k = 0;
  1276. page = 1;
  1277. active = 1;
  1278.  
  1279. while (1)
  1280. {
  1281. if (!beg)
  1282. {
  1283. MessageBox(0, L"Список пуст", L"Уведомление", MB_ICONINFORMATION | MB_SETFOREGROUND);
  1284. return beg;
  1285. }
  1286.  
  1287. if (k != koli + 1 && extreme_page != 1)
  1288. {
  1289. k_this_page = 0;
  1290. cout << "+—+———————————————————+————————————————————+—————————————————————————————————————— +————————————————————————————————+—————————————————————————————————+ " << endl;
  1291. cout << "| | | | Количество Количество | | | " << endl;
  1292. cout << "|№| Шифр группы | Шифр дисциплины |——————————+—————————+———————+————————— | пропущено лекций | пропущено практических занятий + " << endl;
  1293. cout << "| | | | Отл. | Хор. |Удовл. | Неуд. | | | " << endl;
  1294. cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
  1295. do {
  1296. k_this_page++;
  1297. // вытаскиваем первый элемент текущей страницы
  1298. if (k % 5 == 0) {
  1299. first_k = k;
  1300. first_temp = temp;
  1301. }
  1302. // находим первый элемент с предыдущей страницы
  1303. if (k % 5 == 0 && page != 1) {
  1304. buf_el = temp;
  1305.  
  1306. for (int j = 0; j < 5; j++, temp = temp->pred) {
  1307. buf_temp = temp->pred;
  1308. }
  1309. temp = buf_el;
  1310. }
  1311.  
  1312. cout << "|" << ++k << "|";
  1313. print_vh(*temp);
  1314. temp = temp->next;
  1315. } while (temp && k % 5 != 0);
  1316.  
  1317. cout << "+———————————————————+————————————————————+——————————————————+————————————————+——————————————————+———————————————+" << endl;
  1318. cout << "Страница " << page << " из " << ceil(koli / 5);
  1319. }
  1320.  
  1321. c = _getwch();
  1322. if (c == esc) return 0;
  1323. key = _getwch();
  1324.  
  1325. switch (key) {
  1326. case right_btn:
  1327. extreme_page = 2;
  1328. if (k + 1 != koli) {
  1329. page++;
  1330. }
  1331. else {
  1332. k = first_k;
  1333. temp = first_temp;
  1334. }
  1335. system("cls");
  1336. break;
  1337. case left_btn:
  1338. if (page != 1) {
  1339. system("cls");
  1340. k -= k_this_page + 5;
  1341. page--;
  1342. temp = buf_temp;
  1343. }
  1344. else extreme_page = 1;
  1345. break;
  1346. }
  1347. }
  1348. }*
  1349. //-----------------------------------------------------------------------------------------------------
  1350. /*tabli* delete_el(tabli* beg)
  1351. {
  1352. tabli* temp;
  1353. tabli* buf;
  1354. int num_del = 0,
  1355. count = 0;
  1356.  
  1357. if (!beg) {
  1358. MessageBox(0, L"Список пуст", L"Уведомление", MB_ICONINFORMATION | MB_SETFOREGROUND);
  1359. return 0;
  1360. }
  1361.  
  1362. temp = beg;
  1363.  
  1364. cout << "Введите номер элемента,который хотите удалить" << endl;
  1365. cin >> num_del;
  1366.  
  1367. // если один элемент в списке
  1368. if (beg->next == 0) {
  1369. delete temp;
  1370. return 0;
  1371. }
  1372.  
  1373. while (temp) {
  1374. if (num_del == ++count) { // если введённый номер совпал с шифром задания
  1375. buf = temp->next;
  1376.  
  1377. // если удаляется второй элемент
  1378. if (temp->pred == 0) {
  1379. buf->pred = 0;
  1380. delete temp;
  1381. return buf;
  1382. }
  1383.  
  1384. if (buf != 0) buf->pred = temp->pred; // если следующий элемент не 0
  1385.  
  1386. buf = temp->pred;
  1387. buf->next = temp->next;
  1388. delete temp;
  1389. return beg;
  1390. }
  1391. temp = temp->next;
  1392. }
  1393. MessageBox(0, L"Произошла ошибка!", L"Ошибка", MB_ICONERROR | MB_SETFOREGROUND);
  1394. return beg;
  1395.  
  1396. }*/
Advertisement
Add Comment
Please, Sign In to add comment