Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <string>
  4. #include <iomanip>
  5. #include <conio.h>
  6. #include <fstream>
  7. #include <locale.h>
  8. #include <windows.h>
  9. #include <io.h>
  10. #include <fcntl.h>
  11. using namespace std;
  12. //----КОНСТАНТЫ----------
  13. const int up = 72,
  14. down = 80,
  15. right_btn = 77,
  16. left_btn = 75,
  17. enter = 13,
  18. esc = 27,
  19. del = 83,
  20. d_n = 20;
  21. const string items[10] =
  22. {
  23. "Создать список или добавить новый эл-т ",
  24. " Удаление всех элементов списка ",
  25. " Просмотр списка ",
  26. " Запись данных в файл ",
  27. " Чтение из файла ",
  28. " Изменить ",
  29. " Поиск ",
  30. " Сортировка по дате ",
  31. " Старые книги ",
  32. " Выход "
  33. };
  34. const string items2[4] =
  35. {
  36. "Поиск по автору книги ",
  37. "Поиск по названию книги",
  38. "Поиск по жанру книги",
  39. "Выход(esc)"
  40. };
  41. const string items3[3] =
  42. {
  43. "Запись в текстовый файл",
  44. "Запись в бинарный файл"
  45. "Выход(esc)"
  46. };
  47. const string items4[3] =
  48. {
  49. "Чтение из текстового файла",
  50. "Чтение из бинарного файла",
  51. "Выход(esc)"
  52. };
  53. //=======ГЛОБАЛЬНЫЕ ПЕРЕМЕННЫЕ===============
  54. string filename;
  55. int num_pages = 5, // Кол-во элементов на одной странице
  56. width = 0, // Ширина окна
  57. height = 0; // Высота окна
  58.  
  59. //-------------------------------------------
  60. struct info
  61. {
  62. string autor;
  63. string name;
  64. string izdatelstvo;
  65. string janr;
  66. string cost;
  67. int d = 0, m = 0, g = 0;
  68. };
  69. struct book
  70. {
  71. info inf;
  72. book* next = 0;
  73. book* pred = 0;
  74. };
  75. //-------------------------------------------
  76. book vvod_book();
  77. book* dob(book* end, const book& s);
  78. book* dob_first(const book& s);
  79. book* udal(book* beg);
  80. book* delete_el(book * beg, int num_del);
  81. void cls();
  82. void gotoxy(int xpos, int ypos);
  83. void print(const book& s);
  84. void prosmotr(book* beg);
  85. void old_book(book beg);
  86. void sort_cost(book** beg);
  87. void sort_data(book* beg);
  88. void searchname(book* beg);
  89. void searchautor(book* beg);
  90. void searchjanr(book* beg);
  91. wchar_t* UnicodeString(string input);
  92. int change(book* beg, string& user_autor, string& new_user_autor);
  93. int read_file(string filename, book** beg, book** end);
  94. int write_file(string filename, book* temp);
  95. int write_file_binary(string filename, book* beg);
  96. int read_file_binary(string filename, book** beg, book** end);
  97. int menu(int& active, const string items[], int num_el);
  98. void SetColor(int text, int bg);
  99.  
  100. //===========основная программа===================================================
  101. int main()
  102. {
  103. // меняем размер шрифта
  104. CONSOLE_FONT_INFOEX cfi;
  105. cfi.cbSize = sizeof(cfi);
  106. cfi.nFont = 0;
  107. cfi.dwFontSize.X = 0; // Width of each character in the font
  108. cfi.dwFontSize.Y = 24; // Height
  109. cfi.FontFamily = FF_DONTCARE;
  110. cfi.FontWeight = FW_NORMAL;
  111. SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
  112. //----------------------------------
  113. HANDLE hCon;
  114. // вытаскиваем ширину и высоту
  115. hCon = GetStdHandle(-12);
  116. CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
  117. if (GetConsoleScreenBufferInfo(hCon, &consoleInfo))
  118. {
  119. width = consoleInfo.srWindow.Right - consoleInfo.srWindow.Left + 1;
  120. height = consoleInfo.srWindow.Bottom - consoleInfo.srWindow.Top + 1;
  121. }
  122. //======================================================================
  123. system("cls");
  124. ShowWindow(GetConsoleWindow(), SW_MAXIMIZE); // полноэкранный режим
  125. setlocale(LC_ALL, "Rus");
  126. system("color 8F");
  127. book* beg = NULL,
  128. * end = NULL, input;
  129. string filename;
  130. int Num, current = 1;
  131. string user_autor, new_user_autor;
  132. int num_e = 0;
  133. while (1) {
  134. system("cls");
  135. switch (menu(current, items, 10))
  136. {
  137. case 1://создание списка или добовление нового эл-та в список
  138. system("cls");
  139. if (beg)
  140. end = dob(end, vvod_book());
  141. else
  142. {
  143. beg = dob_first(vvod_book());
  144. end = beg;
  145. }
  146. break;
  147. case 2://удаление всех элементов в списке
  148. system("cls");
  149. beg = udal(beg);//(beg,num_del);
  150. cout << "Нажмите любую клавишу" << endl;
  151. cin.get();
  152. break;
  153. case 3://просмотр
  154. system("cls");
  155. prosmotr(beg);
  156. break;
  157. case 4://запись в файл
  158. {
  159. system("cls");
  160. int current = 1;
  161. cout << "Выберите формат файла в который хотите записать:";
  162. switch (menu(current, items3, 4))
  163. {
  164. case 1://Запись в текстовый файл
  165. system("cls");
  166. write_file(filename, beg);
  167. break;
  168. case 2://Запись в бинарный файл
  169. write_file_binary(filename, beg);
  170. cin.get();
  171. break;
  172. case 27:break;
  173. }
  174. }
  175. break;
  176. case 5://чтение из файла
  177. {
  178. system("cls");
  179. int current = 1;
  180. cout << "Выберите формат файла в который хотите записать:";
  181. switch (menu(current, items4, 4))
  182. {
  183. case 1://Запись в текстовый файл
  184. system("cls");
  185. read_file(filename, &beg, &end);
  186. break;
  187. case 2://Запись в бинарный файл
  188. read_file_binary(filename, &beg, &end);
  189. cin.get();
  190. break;
  191. case 27:break;
  192. }
  193. }
  194.  
  195. break;
  196. case 6://редактирование списка
  197. system("cls");
  198. cout << "Введите автора, которого вы хотите изменить " << endl;
  199. cin >> user_autor;
  200. cout << "Введите нового атвора: " << endl;
  201. cin >> new_user_autor;
  202. Num = change(beg, user_autor, new_user_autor);
  203. if (Num == 1) cout << "Автор успешно перезаписан." << endl;
  204. else cout << "Автор не найден!" << endl;
  205. system("pause");
  206. change(beg, user_autor, new_user_autor);
  207. cin.get();
  208. break;
  209. case 7://поиск
  210. {
  211. system("cls");
  212. int current = 1;
  213. switch (menu(current, items2, 4))
  214. {
  215. case 1://поск по автору
  216. system("cls");
  217. searchautor(beg);
  218. cin.get();
  219. break;
  220. case 2:
  221. system("cls");
  222. searchname(beg);//поиск по названию книги
  223. cin.get();
  224. break;
  225. case 3:
  226. searchjanr(beg);
  227. break;
  228. case 27:break;
  229. }
  230. break;
  231. }
  232. case 8:
  233. if (!beg)
  234. {
  235. MessageBox(0, L"Список пуст", L"Уведомление", MB_ICONINFORMATION | MB_SETFOREGROUND);
  236. break;
  237. }
  238. old_book(*beg);
  239. break;
  240. case 9: return 0;
  241. }
  242. }
  243. return 0;
  244. }
  245.  
  246. //-----------------------------------------------------------------------------
  247. int change(book* beg, string& user_autor, string& new_user_autor)
  248. {
  249. book* temp = beg;
  250. while (temp != NULL)
  251. {
  252. if (temp->inf.autor == user_autor)
  253. {
  254. temp->inf.autor = new_user_autor;
  255. return 1;
  256. }
  257. else
  258. {
  259. temp = temp->next;
  260.  
  261. }
  262. }
  263. return 0;
  264. }
  265. //------------------------------------------------------------------------------
  266. void searchjanr(book* beg)
  267. {
  268. book* temp = beg;
  269. char fname[d_n];
  270. int fl = 0;
  271.  
  272. system("cls");
  273.  
  274. if (!beg)
  275. {
  276. MessageBox(0, L"Список пуст", L"Уведомление", MB_ICONINFORMATION | MB_SETFOREGROUND);
  277. return;
  278. }
  279.  
  280. cout << "Введите название жанра для поиска" << endl;
  281. cin >> fname;
  282. cout << "+———————————————————+————————————————————+——————————————————+————————————————+——————————————————+———————————————+" << endl;
  283. cout << "| Автор | Название | Издательство | Жанр | Дата поступления | Стоимость |" << endl;
  284. cout << "+———————————————————+————————————————————+——————————————————+————————————————+——————————————————+———————————————+" << endl;
  285. while (temp)
  286. {
  287. if (fname == temp->inf.janr)
  288. {
  289. print(*temp);
  290. fl = 1;
  291. }
  292. temp = temp->next;
  293. }
  294. if (fl != 1)
  295. {
  296. cout << "Книги с таким жанром не найдено" << endl;
  297. }
  298. system("pause");
  299. }
  300. //------------------------------------------------------------------------------
  301. void searchname(book* beg)
  302. {
  303. book* temp = beg;
  304. char fname[d_n];
  305. int fl = 0;
  306.  
  307. system("cls");
  308.  
  309. if (!beg)
  310. {
  311. MessageBox(0, L"Список пуст", L"Уведомление", MB_ICONINFORMATION | MB_SETFOREGROUND);
  312. return;
  313. }
  314.  
  315. cout << "Введите название книги для поиска" << endl;
  316. cin >> fname;
  317. cout << "+———————————————————+————————————————————+——————————————————+————————————————+——————————————————+———————————————+" << endl;
  318. cout << "| Автор | Название | Издательство | Жанр | Дата поступления | Стоимость |" << endl;
  319. cout << "+———————————————————+————————————————————+——————————————————+————————————————+——————————————————+———————————————+" << endl;
  320. while (temp)
  321. {
  322. if (fname == temp->inf.name)
  323. {
  324. print(*temp);
  325. fl = 1;
  326. }
  327. temp = temp->next;
  328. }
  329. if (fl != 1)
  330. {
  331. cout << "Книги с таким названием не найдено" << endl;
  332. }
  333. system("pause");
  334. }
  335. //-----------------------------------------------------------------------------
  336. void searchautor(book* beg)
  337. {
  338. book* temp = beg;
  339. int fl = 0;
  340. char fa[d_n];
  341. system("cls");
  342. if (!beg)
  343. {
  344. MessageBox(0, L"Список пуст", L"Уведомление", MB_ICONINFORMATION | MB_SETFOREGROUND);
  345. return;
  346. }
  347. cout << "Введите автора для поиска" << endl;
  348. cin >> fa;
  349.  
  350. cout << "+———————————————————+————————————————————+——————————————————+————————————————+——————————————————+———————————————+" << endl;
  351. cout << "| Автор | Название | Издательство | Жанр | Дата поступления | Стоимость |" << endl;
  352. cout << "+———————————————————+————————————————————+——————————————————+————————————————+——————————————————+———————————————+" << endl;
  353. while (temp)
  354. {
  355. if (fa == temp->inf.autor)
  356. {
  357. print(*temp);
  358. fl = 1;
  359. }
  360. temp = temp->next;
  361. }
  362. if (fl != 1) {
  363. cout << "Книги с таким автором не найдено" << endl;
  364. }
  365. system("pause");
  366. }
  367. //-----------------------------------------------------------------------------
  368. void old_book(book beg)
  369. {
  370. book* temp = &beg;
  371. sort_data(&beg);
  372. system("cls");
  373.  
  374. cout << "+———————————————————+————————————————————+——————————————————+————————————————+——————————————————+———————————————+" << endl;
  375. cout << "| Автор | Название | Издательство | Жанр | Дата поступления | Стоимость |" << endl;
  376. cout << "+———————————————————+————————————————————+——————————————————+————————————————+——————————————————+———————————————+" << endl;
  377. for (int i = 0; i < 5; i++) {
  378. print(*temp);
  379. temp = temp->next;
  380. }
  381.  
  382. system("pause");
  383. return;
  384.  
  385. cout << "+———————————————————+————————————————————+——————————————————+————————————————+——————————————————+———————————————+" << endl;
  386. cin.get();
  387. }
  388. //-----------------------------------------------------------------------------
  389. void prosmotr(book* beg)
  390. {
  391. int k = 1;
  392. if (!beg)
  393. {
  394. cout << "список пустой" << endl;
  395. cin.get();
  396. return;
  397. }
  398. book* temp = beg;
  399. cout << "+———————————————————+————————————————————+——————————————————+————————————————+——————————————————+———————————————+" << endl;
  400. cout << "| Автор | Название | Издательство | Жанр | Дата поступления | Стоимость |" << endl;
  401. cout << "+———————————————————+————————————————————+——————————————————+————————————————+——————————————————+———————————————+" << endl;
  402. while (temp)
  403. {
  404. print(*temp);
  405. temp = temp->next;
  406. cout<<k++;
  407. }
  408. cout << "+———————————————————+————————————————————+——————————————————+————————————————+——————————————————+———————————————+" << endl;
  409. cin.get();
  410. }
  411. //-----------------------------------------------------------------------------
  412. book vvod_book()
  413. {
  414. book s;
  415. cout << "Введите автора:" << endl;
  416. while (1)
  417. {
  418. cin >> s.inf.autor;
  419. //if (atoi(s.autor)==0)
  420. if((s.inf.autor[0] >= '0') && (s.inf.autor[0] <= '9' ) )
  421. break;
  422. cout << "Ошибка ввода!" << endl;
  423. }
  424. cout << "Введите название книги:" << endl;
  425. while (1)
  426. {
  427. cin >> s.inf.name;
  428. //if (atoi(s.name)==0)
  429. break;
  430. cout << "Ошибка ввода!" << endl;
  431. }
  432. cout << "Введите издательство:" << endl;
  433. while (1)
  434. {
  435. cin >> s.inf.izdatelstvo;
  436. //if (atoi(s.izdatelstvo) == 0)
  437. break;
  438. cout << "Ошибка ввода!" << endl;
  439. }
  440. cout << "Введите жанр:" << endl;
  441. while (1)
  442. {
  443. cin >> s.inf.janr;
  444. //if (atoi(s.janr) == 0)
  445. break;
  446. cout << "Ошибка ввода!" << endl;
  447. }
  448. cout << "Введите дату поступления:" << endl;
  449. cout << "Введите день:";
  450. while (1)
  451. {
  452. cin >> s.inf.d;
  453. if ((s.inf.d >= 1) && (s.inf.d <= 31))
  454. break;
  455. cout << "Ошибка ввода!Ведите правильную дату!" << endl;
  456. }
  457. cout << "Введите месяц:";
  458. while (1)
  459. {
  460. cin >> s.inf.m;
  461. if ((s.inf.m >= 1) && (s.inf.m <= 12))
  462. break;
  463. cout << "Ошибка ввода!Ведите правильную дату!" << endl;
  464. }
  465. cout << "Введите год:";
  466. while (1)
  467. {
  468. cin >> s.inf.g;
  469. if ((s.inf.g >= 1900) && (s.inf.g <= 2050))
  470. break;
  471. cout << "Ошибка ввода!Ведите правильную дату!" << endl;
  472. }
  473. cout << "Введите стоимость книги:" << endl;
  474. cin >> s.inf.cost;
  475. return s;
  476. }
  477. //-----------------------------------------------------------------------------
  478. void print(const book& s)
  479. {
  480. cout << "|" << s.inf.autor << setw(20 - (s.inf.autor).length()) << "|";
  481. cout << s.inf.name << setw(21 - (s.inf.name).length()) << "|";
  482. cout << s.inf.izdatelstvo << setw(19 - (s.inf.izdatelstvo).length()) << "|";
  483. cout << s.inf.janr << setw(17 - (s.inf.janr).length()) << "|";
  484. if (s.inf.d < 10) {
  485. cout << 0 << s.inf.d << ".";
  486. }
  487. else {
  488. cout << s.inf.d << ".";
  489. }
  490. if (s.inf.m < 10) {
  491. cout << 0 << s.inf.m << ".";
  492. }
  493. else {
  494. cout << s.inf.m << ".";
  495. }
  496. cout << s.inf.g << setw(9) << "|";
  497. cout << s.inf.cost<< setw(16-(s.inf.cost).length()) << "|"<<endl;
  498.  
  499. }
  500. //--------------ф-я добавления или создания эл-та-------------------------------
  501. book* dob(book* end, const book& s)
  502. {
  503. book* newE = new book;
  504. *newE = s;
  505. newE->next = 0;
  506. newE->pred = end;
  507. end->next = newE;
  508. end = newE;
  509. return end;
  510. }
  511. //--------------создание первого эл-та------------------------------
  512. book* dob_first(const book& s)
  513. {
  514. book* beg = new book;
  515. *beg = s;
  516. beg->next = 0;
  517. beg->pred = 0;
  518. return beg;
  519. }
  520. //-----------------------------------------------------------------------------
  521. int read_file(string filename, book** beg, book** end)
  522. {
  523. cout << "Введите название файла" << endl;
  524. cin >> filename;
  525. ifstream fin(filename, ios::in);
  526. if (!fin) {
  527.  
  528. MessageBox(0, L"Невозможно открыть файл!", L"Ошибка", MB_ICONERROR | MB_SETFOREGROUND);
  529. return 0;
  530.  
  531. }
  532. book s;
  533. *beg = 0;
  534. fin.seekg(0, ios::beg);
  535. while (fin >> s.inf.autor)
  536. {
  537. fin >> s.inf.name;
  538. fin >> s.inf.izdatelstvo;
  539. fin >> s.inf.janr;
  540. fin >> s.inf.d;
  541. fin >> s.inf.m;
  542. fin >> s.inf.g;
  543. fin >> s.inf.cost;
  544. if (*beg)
  545. *end = dob(*end, s);
  546. else
  547. {
  548. *beg = dob_first(s); *end = *beg;
  549. }
  550. }
  551. cout << "Считывание прошло успешно" << endl;
  552. cin.get();
  553. cin.get();
  554. return 0;
  555. }
  556. //-----------------------------------------------------------------------------
  557. int write_file(string filename, book* temp)
  558. {
  559. cout << "Введите название файла" << endl;
  560. cin >> filename;
  561. ofstream fout(filename, ios_base::app); // открытие файла
  562. if (!fout)
  563. {
  564. cout << "Не могу открыть файл для записи" << endl;
  565. return 1;
  566. }
  567. while (temp)// пока temp!=0 выводим эл-ты в файл
  568. {
  569. fout << temp->inf.autor << endl;
  570. fout << temp->inf.name << endl;
  571. fout << temp->inf.izdatelstvo << endl;
  572. fout << temp->inf.janr << endl;
  573. fout << temp->inf.d << endl;
  574. fout << temp->inf.m << endl;
  575. fout << temp->inf.g << endl;
  576. fout << temp->inf.cost << endl;
  577. temp = temp->next;
  578. }
  579. cout << "Данные сохранены в файле: " << filename << endl;
  580. cout << "==============================" << endl;
  581. cout << "Нажмите любую клавишу" << endl;
  582. cin.get();
  583. return 0;
  584. }
  585. //-----------------------------------------------------------------------------
  586. int write_file_binary(string filename, book* beg)
  587. {
  588. cout << "Введите название файла" << endl;
  589. cin >> filename;
  590. book* temp = beg;
  591. ofstream fout(filename + ".dat", ios::binary); // открытие файла
  592. if (!fout)
  593. {
  594. cout << "Не могу открыть файл для записи" << endl;
  595. return 1;
  596. }
  597. while (temp) {
  598. fout.write((char*)&temp->inf, sizeof temp->inf);
  599. temp = temp->next;
  600. }
  601. fout.close();
  602. cout << "Данные сохранены в файле: " << filename << endl;
  603. cout << "==============================" << endl;
  604. cout << "Нажмите любую клавишу" << endl;
  605. cin.get();
  606. return 0;
  607. }
  608.  
  609. // ==========ЧТЕНИЕ ИЗ БИНАРНОГО ФАЙЛА==========
  610. int read_file_binary(string filename, book** beg, book** end)
  611. {
  612. cout << "Введите название файла" << endl;
  613. cin >> filename;
  614. ifstream fin(filename + ".dat", ios::binary);
  615.  
  616. if (!fin) {
  617. MessageBox(0, L"Нет файла!", L"Ошибка", MB_ICONERROR | MB_SETFOREGROUND);
  618. return 1;
  619. }
  620.  
  621. fin.seekg(ios_base::beg);
  622. book* t = new book;
  623. t->next = NULL;
  624. t->pred = NULL;
  625. *beg = 0;
  626.  
  627. while (fin.read((char*)&t->inf, sizeof t->inf))
  628. {
  629. if (*beg)
  630. *end = dob(*end, *t);
  631. else {
  632. *beg = dob_first(*t);
  633. *end = *beg;
  634. }
  635. }
  636. fin.close();
  637. cout << "Чтене прошло успешно" << endl;
  638. cout << "==============================" << endl;
  639. cout << "Нажмите любую клавишу" << endl;
  640. return 0;
  641. }
  642.  
  643. //-----------------------------------------------------------------------------
  644. book* udal(book* beg)
  645. {
  646. book* temp;
  647. if (!beg)
  648. {
  649. cout << "список пустой" << endl;
  650. cin.get();
  651. return 0;
  652. }
  653. while (beg)
  654. {
  655. temp = beg;
  656. beg = beg->next;
  657. delete temp;
  658. }
  659. cout << "==============================" << endl;
  660. cout << "====удаление прошло успешно===" << endl;
  661. cout << "==============================" << endl;
  662. return beg;
  663. }
  664. //----------------------------------------------------------------
  665. void sort_data(book* beg)
  666. {
  667. book* temp_i = beg, * temp_j = beg;
  668. for (; temp_i; temp_i = temp_i->next)
  669. {
  670. for (temp_j = temp_i; temp_j; temp_j = temp_j->next)
  671. {
  672. if (temp_i->inf.g != temp_j->inf.g)
  673. {
  674. if (temp_i->inf.g > temp_j->inf.g)
  675. {
  676. swap(temp_i->inf, temp_j->inf);
  677. continue;
  678. }
  679. }
  680. else if (temp_i->inf.m != temp_j->inf.m)
  681. {
  682. if (temp_i->inf.m > temp_j->inf.m)
  683. {
  684. swap(temp_i->inf, temp_j->inf);
  685. continue;
  686. }
  687. }
  688. else if (temp_i->inf.d > temp_j->inf.d)
  689. {
  690. swap(temp_i->inf, temp_j->inf);
  691. continue;
  692. }
  693. }
  694. }
  695. cout << "Сортировка прошла успешно" << endl;
  696. system("pause");
  697. }
  698. //----------------------------------------
  699. void sort_cost(book** beg) {
  700. book* temp_i = *beg,
  701. * temp_j = *beg;
  702.  
  703. for (; temp_i; temp_i = temp_i->next) {
  704. for (temp_j = temp_i; temp_j; temp_j = temp_j->next) {
  705. if (stoi(temp_i->inf.cost) > stoi(temp_j->inf.cost)) {
  706. swap(temp_i->inf, temp_j->inf);
  707. }
  708. }
  709. }
  710.  
  711. cout << "Сортировка прошла успешно" << endl;
  712. system("pause");
  713. }
  714. // ==========ШАБЛОН ПЕЧАТИ МЕНЮ==========
  715. void print_menu(int sym, const string items[], const int N_ITEMS)
  716. {
  717. for (int i = 1; i <= N_ITEMS; i++)
  718. {
  719. SetColor(15, 8);
  720. gotoxy((width / 2) - 10, (height / 2) + i - 3); // ставим меню в центр
  721. if (i == sym)
  722. {
  723. SetColor(16, 3);
  724. }
  725. cout << items[i - 1] << endl;
  726. SetColor(15, 8);
  727. }
  728. }
  729. // ==========МЕНЮ==========
  730. int menu(int& active, const string items[], int num_el)
  731. {
  732. wint_t buf;
  733. while (1)
  734. {
  735. cls();
  736. print_menu(active, items, num_el);
  737.  
  738. buf = _getwch();
  739. switch (buf)
  740. {
  741. case up: // клавиша вверх
  742. if (active > 1) active--;
  743. break;
  744. case down: // клавиша вниз
  745. if (active < num_el) active++;
  746. break;
  747. case enter: // клавиша enter
  748. return active;
  749. case esc: // клавиша escape
  750. return -1;
  751. }
  752. }
  753. }
  754. // ==========УСТАНОВКА ЦВЕТА ТЕКСТА И ФОНА==========
  755. void SetColor(int text, int bg)
  756. {
  757. HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  758. SetConsoleTextAttribute(hStdOut, (WORD)((bg << 4) | text));
  759. }
  760. // ==========ПЕРЕМЕЩЕНИЕ КУРСОРА НА ВЫБРАННУЮ ПОЗИЦИЮ==========
  761.  
  762. void gotoxy(int xpos, int ypos)
  763. {
  764. COORD scrn;
  765. HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE);
  766. scrn.X = xpos; scrn.Y = ypos;
  767. SetConsoleCursorPosition(hOuput, scrn);
  768. }
  769. //=====================================
  770. wchar_t* UnicodeString(string input) {
  771. const char* orig = input.c_str();
  772. size_t origsize = strlen(orig) + 1;
  773. const size_t newsize = 100;
  774. size_t convertedChars = 0;
  775. wchar_t* wcstring = new wchar_t[newsize];
  776. mbstowcs_s(&convertedChars, wcstring, origsize, orig, _TRUNCATE);
  777. return wcstring;
  778. }
  779. // ==========ОЧИСТКА ЭКРАНА БЕЗ МЕРЦАНИЯ==========
  780. void cls() {
  781. HANDLE hd = GetStdHandle(STD_OUTPUT_HANDLE);
  782. COORD cd;
  783. cd.X = 0;
  784. cd.Y = 0;
  785. SetConsoleCursorPosition(hd, cd);
  786. }
  787. // ==========УДАЛЕНИЕ==========
  788. book* delete_el(book* beg,int k)
  789. {
  790. book* temp;
  791. book* buf;
  792. int c=1;
  793. if (!beg) {
  794. MessageBox(0, L"Список пуст", L"Уведомление", MB_ICONINFORMATION | MB_SETFOREGROUND);
  795. return 0;
  796. }
  797.  
  798. temp = beg;
  799.  
  800. // если один элемент в списке
  801. if (beg->next == 0) {
  802. delete temp;
  803. return 0;
  804. }
  805.  
  806. while (temp) {
  807. if (num_del == stoi(temp->inf.autor)) { // если введённый номер совпал с шифром задания
  808. buf = temp->next;
  809.  
  810. // если удаляется второй элемент
  811. if (temp->pred == 0) {
  812. buf->pred = 0;
  813. delete temp;
  814. return buf;
  815. }
  816.  
  817. if (buf != 0) buf->pred = temp->pred; // если следующий элемент не 0
  818.  
  819. buf = temp->pred;
  820. buf->next = temp->next;
  821. delete temp;
  822. return beg;
  823. }
  824. temp = temp->next;
  825. }
  826. MessageBox(0, L"Произошла ошибка!", L"Ошибка", MB_ICONERROR | MB_SETFOREGROUND);
  827. return beg;
  828.  
  829. }
  830. /*
  831. // ==========ОЧИСТКА СТРОКИ==========
  832.  
  833. void clearRow(int row)
  834.  
  835. {
  836.  
  837. DWORD a;
  838.  
  839. HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); // получаем хэндл окна консоли
  840.  
  841. COORD coord = { 0, row - 1 }; // получаем координаты строки для очистки
  842.  
  843. CONSOLE_SCREEN_BUFFER_INFO csbi;
  844.  
  845. GetConsoleScreenBufferInfo(hStdOut, &csbi); // получаем данные из буфера вывода консоли
  846.  
  847. FillConsoleOutputCharacter(hStdOut, ' ', 80, coord, &a); // заполняем строку пробелами
  848.  
  849. }
  850.  
  851. // ==========ПРОВЕРКИ НА СИМВОЛ И ДЛИНУ СТРОКИ==========
  852.  
  853. string check_num(string field, int row, int max_length) {
  854.  
  855. do {
  856.  
  857. int fl = 0;
  858.  
  859. getline(cin, field);
  860.  
  861.  
  862.  
  863. if (field.length() > max_length) {
  864.  
  865. MessageBox(0, L"Слишком много символов!", L"Предупреждение", MB_ICONWARNING | MB_SETFOREGROUND);
  866.  
  867. clearRow(row);
  868.  
  869. gotoxy(0, row - 1);
  870.  
  871. fl = 1;
  872.  
  873. }
  874.  
  875.  
  876.  
  877. // проверка на символ
  878.  
  879. for (int i = 0; i < field.length(); i++) {
  880.  
  881. if ( !(field[i] >= '0' && field[i] <= '9') ) {
  882.  
  883. MessageBox(0, L"Нельзя вводить символы!", L"Предупреждение", MB_ICONWARNING | MB_SETFOREGROUND);
  884.  
  885. clearRow(row);
  886.  
  887. gotoxy(0, row - 1);
  888.  
  889. fl = 1;
  890.  
  891. break;
  892.  
  893. }
  894.  
  895. }
  896.  
  897.  
  898.  
  899. if (fl == 0) break;
  900.  
  901. } while (1);
  902.  
  903.  
  904.  
  905. return field;
  906.  
  907. }
  908.  
  909.  
  910.  
  911. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement