Advertisement
Guest User

Untitled

a guest
May 26th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 57.31 KB | None | 0 0
  1. #pragma once
  2. #include "Protection.h"
  3. using namespace std;
  4.  
  5. /*шифрование. MODE 1 - шифрование, MODE 0 - дешифрование*/
  6. string Shifr(string shifr, bool mod)
  7. {
  8. for (int i = 0; i < shifr.size(); i++) {
  9. if (mod) {
  10. shifr[i] += 5;
  11. }
  12. else {
  13. shifr[i] -= 5;
  14. }
  15. }
  16. return shifr;
  17. }
  18.  
  19. void family_filtr() {
  20. static vector<string> family;
  21. int VectorSize = 0;
  22. cout << "Фильтрация по фамилии" << endl;
  23. cout << "Список всех фамилий:" << endl;
  24. ifstream file1("info.txt", ios_base::app);
  25. while (file1 >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  26. if (VectorSize == 0) {
  27. family.push_back(info.participant.family);
  28. VectorSize++;
  29. }
  30. else {
  31. int Check = 0;
  32. for (int i = 0; i < VectorSize; i++) {
  33. if (family[i] == info.participant.family) {
  34. Check++;
  35. }
  36. }
  37. if (Check == 0) {
  38. family.push_back(info.participant.family);
  39. VectorSize++;
  40. }
  41. }
  42. }
  43. for (int i = 0; i < VectorSize; i++) {
  44. cout << family[i] << endl;
  45. }
  46. bool exit = true;
  47. while (exit) {
  48. cout << "Введите фамилию из данного списка для поиска" << endl;
  49. string search;
  50. search = add_protect();
  51. int Check = 0;
  52. for (int i = 0; i < VectorSize; i++) {
  53. if (family[i] == search) {
  54. Check++;
  55. }
  56. }
  57. if (Check == 0) {
  58. cout << "Фамилия введена не верно, повторите ввод" << endl;
  59. }
  60.  
  61. else {
  62. exit = false;
  63. char c;
  64. ifstream file("info.txt"); // открыли файл с текстом
  65. string s;
  66. int amount = 0;
  67. while (!file.eof()) { // прочитали его и заполнили им строку
  68. file.get(c);
  69. s.push_back(c);
  70. amount++;
  71. }
  72. file.close();
  73. string t;
  74. t = search;
  75. int i, j, k, x, size = t.size(), string = 1;
  76. bool check = false;
  77. for (i = 0; i <= amount - size - 1; i++) {
  78. if (s[i] == '\n') {
  79. string += 1;
  80. }
  81. if (s[i] == t[0]) {
  82. k = i;
  83. x = 0;
  84. for (j = 1; j < size + 1; j++) {
  85. if (s[k + j] != t[j]) {
  86. break;
  87. }
  88. else x++;
  89. }
  90. if (x + 1 == size) {
  91.  
  92. ifstream f("info.txt", ios_base::app);
  93. if (f.peek() == EOF)
  94. {
  95. cout << "Файл пустой." << endl;
  96. }
  97. else {
  98. if (check == false) {
  99. cout << setw(84) << " " << "Дата выступления" << endl;
  100. cout << setw(12) << left << "Имя" << setw(12) << left << "Фамилия" << setw(12) << left << "Отчество" << setw(12) << left << "ID" << setw(12) << left << "Песня" << setw(12) << left << "Инструмент" << setw(12) << left << "Рейтинг" << setw(12) << left << "День" << setw(12) << left << "Месяц" << setw(12) << left << "Год" << endl;
  101. check = true;
  102. }
  103. while (f >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  104. if (string == info.participant.ID) {
  105. cout << "_______________________________________________________________________________________________________________________" << endl;
  106. cout << setw(12) << info.participant.name << setw(12) << info.participant.family << setw(12) << info.participant.patronymic << setw(12) << info.participant.ID << setw(12) << info.participant.kategory.song << setw(12) << info.participant.kategory.tool << setw(12) << left << info.rating << setw(12) << left << info.day << setw(12) << left << info.month << setw(12) << left << info.year << endl;
  107. cout << "_______________________________________________________________________________________________________________________" << endl;
  108. }
  109. }
  110. while (s[i + 1] != '\n') {
  111. i++;
  112. }
  113. }
  114. f.close();
  115. }
  116.  
  117. }
  118. }
  119. }
  120. system("pause");
  121. system("cls");
  122. }
  123. file1.close();
  124. }
  125.  
  126. void filtr_menu() {
  127. int input;
  128. bool hod = true;
  129. while (hod) {
  130. cout << "Меню фильтрации" << endl;
  131. cout << "1. Фильтрация по фамилии" << endl;
  132. cout << "2. Фильтрация по дате" << endl;
  133. cout << "3. Фильтрация по id" << endl;
  134. cout << "4. Вывести информацию" << endl;
  135. cin >> input;
  136. proverka_na_chislo(input);
  137. system("cls");
  138. switch (input) {
  139. case 1: {
  140. family_filtr();
  141. system("cls");
  142. break;
  143. }
  144. case 2: {
  145. system("cls");
  146. break;
  147. }
  148. case 4: {
  149. hod = false;
  150. }
  151. default: {
  152. cout << "Неверный ввод повторите попытку" << endl;
  153. }
  154. }
  155. }
  156. }
  157.  
  158.  
  159.  
  160.  
  161. void files() {
  162. ifstream jury("jury.txt");
  163. if (!jury.is_open()) {
  164. ofstream jury("jury.txt");
  165. jury.close();
  166. }
  167. else jury.close();
  168.  
  169. ifstream jury2("jury2.txt");
  170. if (!jury2.is_open()) {
  171. ofstream jury("jury2.txt");
  172. jury2.close();
  173. }
  174. else jury2.close();
  175.  
  176. ifstream info("info.txt");
  177. if (!info.is_open()) {
  178. ofstream info("info.txt");
  179. info.close();
  180. }
  181. else info.close();
  182.  
  183. ifstream info2("info2.txt");
  184. if (!info2.is_open()) {
  185. ofstream info2("info2.txt");
  186. info2.close();
  187. }
  188. else info2.close();
  189.  
  190. ifstream users("users.txt");
  191. if (!users.is_open()) {
  192. ofstream users("users.txt");
  193. users.close();
  194. }
  195. else users.close();
  196.  
  197. ifstream admin("admin.txt");
  198. if (!admin.is_open()) {
  199. ofstream admin("admin.txt");
  200. admin.close();
  201. }
  202. else admin.close();
  203. }
  204.  
  205. void QuickSort(int *mass, int size, int left, int right) {
  206. int i = left;
  207. int j = right;
  208. int test = mass[(left + right) / 2];
  209. do {
  210. while (mass[i] < test)i++;
  211. while (mass[j] > test)j--;
  212.  
  213. if (i <= j) {
  214. swap(mass[i++], mass[j--]);
  215. }
  216. } while (i <= j);
  217.  
  218. if (i < right) {
  219. QuickSort(mass, size, i, right);
  220. }
  221. if (j > left) {
  222. QuickSort(mass, size, left, j);
  223. }
  224. }
  225.  
  226. void sort_full_info_id() {
  227. ifstream f("info.txt", ios_base::app);
  228.  
  229. if (f.peek() == EOF)
  230. {
  231. cout << "Файл пустой." << endl;
  232. f.close();
  233. }
  234. else {
  235. f.close();
  236. int count = 0;
  237. ifstream f1("info.txt", ios_base::app);
  238. while (f1 >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  239. count++;
  240. }
  241. f1.close();
  242. ifstream p("info.txt", ios_base::app);
  243. int *mass = new int[count];
  244. int i = 0;
  245. while (p >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  246. mass[i] = info.participant.ID;
  247. i++;
  248. }
  249. p.close();
  250.  
  251. QuickSort(mass, count, 0, count - 1);
  252.  
  253. ofstream copy("info2.txt", ios_base::ate);
  254. for (int j = 0; j < count; j++) {
  255. ifstream file("info.txt", ios_base::app);
  256. while (file >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  257. if (mass[j] == info.participant.ID) {
  258. copy << info.participant.name << ' ' << info.participant.family << ' ' << info.participant.patronymic << ' ' << info.participant.ID << ' ' << info.participant.kategory.song <<
  259. ' ' << info.participant.kategory.tool << ' ' << info.rating << ' ' << info.day << ' ' << info.month << ' ' << info.year << endl;
  260. }
  261. }
  262. file.close();
  263. }
  264. copy.close();
  265. ofstream f11("info.txt", ios_base::ate);
  266. ifstream f12("info2.txt", ios_base::app);
  267. while (f12 >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  268. f11 << info.participant.name << ' ' << info.participant.family << ' ' << info.participant.patronymic << ' ' << info.participant.ID << ' ' << info.participant.kategory.song <<
  269. ' ' << info.participant.kategory.tool << ' ' << info.rating << ' ' << info.day << ' ' << info.month << ' ' << info.year << endl;
  270. }
  271. f11.close();
  272. f12.close();
  273. }
  274. }
  275.  
  276. void sort_full_info_family() {
  277. ifstream f("info.txt", ios_base::app);
  278.  
  279. if (f.peek() == EOF)
  280. {
  281. cout << "Файл пустой." << endl;
  282. f.close();
  283. }
  284. else {
  285. f.close();
  286. int count = 0;
  287. ifstream f1("info.txt", ios_base::app);
  288. while (f1 >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  289. count++;
  290. }
  291. f1.close();
  292. ifstream p("info.txt", ios_base::app);
  293. int *mass = new int[count];
  294. string *family = new string[count];
  295. int i = 0;
  296. while (p >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  297. mass[i] = info.participant.ID;
  298. family[i] = info.participant.family;
  299. i++;
  300. }
  301. p.close();
  302.  
  303. for (int i = 0; i < count - 1; i++)
  304. {
  305. for (int j = 0; j < count - i - 1; j++)
  306. {
  307. if (family[j] > family[j+1])
  308. {
  309. swap(family[j], family[j + 1]);
  310. swap(mass[j], mass[j + 1]);
  311. }
  312. }
  313. }
  314.  
  315. ofstream copy("info2.txt", ios_base::ate);
  316. for (int j = 0; j < count; j++) {
  317. ifstream file("info.txt", ios_base::app);
  318. while (file >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  319. if (mass[j] == info.participant.ID) {
  320. copy << info.participant.name << ' ' << info.participant.family << ' ' << info.participant.patronymic << ' ' << info.participant.ID << ' ' << info.participant.kategory.song <<
  321. ' ' << info.participant.kategory.tool << ' ' << info.rating << ' ' << info.day << ' ' << info.month << ' ' << info.year << endl;
  322. }
  323. }
  324. file.close();
  325. }
  326. copy.close();
  327. ofstream f11("info.txt", ios_base::ate);
  328. ifstream f12("info2.txt", ios_base::app);
  329. while (f12 >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  330. f11 << info.participant.name << ' ' << info.participant.family << ' ' << info.participant.patronymic << ' ' << info.participant.ID << ' ' << info.participant.kategory.song <<
  331. ' ' << info.participant.kategory.tool << ' ' << info.rating << ' ' << info.day << ' ' << info.month << ' ' << info.year << endl;
  332. }
  333. f11.close();
  334. f12.close();
  335. }
  336. }
  337.  
  338. void sort_full_info_date() {
  339. ifstream f("info.txt", ios_base::app);
  340.  
  341. if (f.peek() == EOF)
  342. {
  343. cout << "Файл пустой." << endl;
  344. f.close();
  345. }
  346. else {
  347. f.close();
  348. int count = 0;
  349. ifstream f1("info.txt", ios_base::app);
  350. while (f1 >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  351. count++;
  352. }
  353. f1.close();
  354. ifstream p("info.txt", ios_base::app);
  355. int *mass = new int[count];
  356. int *day = new int[count];
  357. int *month = new int[count];
  358. int *year = new int[count];
  359. int i = 0;
  360. while (p >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  361. mass[i] = info.participant.ID;
  362. day[i] = info.day;
  363. month[i] = info.month;
  364. year[i] = info.year;
  365. i++;
  366. }
  367. p.close();
  368.  
  369. for (int i = 0; i < count - 1; i++)
  370. {
  371. for (int j = 0; j < count - i - 1; j++)
  372. {
  373. if (year[j] > year[j + 1] || (year[j] == year[j + 1] && (month[j] > month[j + 1] || (month[j] == month[j + 1] && day[j] > day[j + 1]))))
  374. {
  375. swap(year[j], year[j + 1]);
  376. swap(month[j], month[j + 1]);
  377. swap(day[j], day[j + 1]);
  378. swap(mass[j], mass[j + 1]);
  379. }
  380. }
  381. }
  382.  
  383. ofstream copy("info2.txt", ios_base::ate);
  384. for (int j = 0; j < count; j++) {
  385. ifstream file("info.txt", ios_base::app);
  386. while (file >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  387. if (mass[j] == info.participant.ID) {
  388. copy << info.participant.name << ' ' << info.participant.family << ' ' << info.participant.patronymic << ' ' << info.participant.ID << ' ' << info.participant.kategory.song <<
  389. ' ' << info.participant.kategory.tool << ' ' << info.rating << ' ' << info.day << ' ' << info.month << ' ' << info.year << endl;
  390. }
  391. }
  392. file.close();
  393. }
  394. copy.close();
  395. ofstream f11("info.txt", ios_base::ate);
  396. ifstream f12("info2.txt", ios_base::app);
  397. while (f12 >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  398. f11 << info.participant.name << ' ' << info.participant.family << ' ' << info.participant.patronymic << ' ' << info.participant.ID << ' ' << info.participant.kategory.song <<
  399. ' ' << info.participant.kategory.tool << ' ' << info.rating << ' ' << info.day << ' ' << info.month << ' ' << info.year << endl;
  400. }
  401. f11.close();
  402. f12.close();
  403. }
  404. }
  405.  
  406.  
  407. int admin_menu() {
  408. int input;
  409. do {
  410. fflush(stdin);
  411. cout << "МЕНЮ АДМИНИСТРАТОРА" << endl;
  412. cout << "=========================================" << endl;
  413. cout << "Сделайте выбор" << endl;
  414. cout << "1. Создание/открытие файла с данными" << endl;
  415. cout << "2. Добавление записи" << endl;
  416. cout << "3. Редактирование записи" << endl;
  417. cout << "4. Удаление записи" << endl;
  418. cout << "5. Просмотр всех данных в табличной форме" << endl;
  419. cout << "6. Поиск и фильтрация данных" << endl;
  420. cout << "7. Управление пользователями" << endl;
  421. cout << "8. Выход в меню 1-ого уровня" << endl;
  422. cin >> input;
  423. proverka_na_chislo(input);
  424. system("cls");
  425. } while (input > 8 || input < 1);
  426. return input;
  427. }
  428.  
  429. int user_menu() {
  430. int input;
  431. do {
  432. fflush(stdin);
  433. cout << "МЕНЮ ПОЛЬЗОВАТЕЛЯ" << endl;
  434. cout << "=========================================" << endl;
  435. cout << "Сделайте выбор" << endl;
  436. cout << "1. Открытие файла с данными" << endl;
  437. cout << "2. Просмотр всех данных в табличной форме" << endl;
  438. cout << "3. Выполение задачи" << endl;
  439. cout << "4. Поиск и фильтрация данных" << endl;
  440. cout << "5. Выход в меню 1-ого уровня" << endl;
  441. cin >> input;
  442. proverka_na_chislo(input);
  443. system("cls");
  444. } while (input > 5 || input < 1);
  445. return input;
  446. }
  447.  
  448. int sravnenie_s_tekushey_datoy(int day, int month, int year) {
  449. int check = 1;
  450. time_t seconds = time(NULL); //из интернета
  451. tm *timeinfo = localtime(&seconds);
  452. if (year > timeinfo->tm_year + 1900) {
  453. check = 0;
  454. }
  455. if (year == timeinfo->tm_year + 1900 && month > timeinfo->tm_mon + 1) {
  456. check = 0;
  457. }
  458. if (year == timeinfo->tm_year + 1900 && month == timeinfo->tm_mon + 1 && day > timeinfo->tm_mday) {
  459. check = 0;
  460. }
  461. return check;
  462. }
  463.  
  464. int check_date(int day, int month, int year) {
  465. int check;
  466. bool visokosni_god = false;
  467. bool korrekt_data = true;
  468. check = sravnenie_s_tekushey_datoy(day, month, year);
  469. if (check == 0) {
  470. cout << "Будущая дата" << endl;
  471. cout << "Повторите ввод" << endl;
  472. return true;
  473. }
  474. else {
  475. if (year % 4 == 0) {
  476. visokosni_god = true;
  477. }
  478. if (year < 1900 || year > 2019) {
  479. korrekt_data = false;
  480. }
  481. if (day < 1 || day > 31) {
  482. korrekt_data = false;
  483. }
  484. if (month < 1 || month > 12) {
  485. korrekt_data = false;
  486. }
  487. if (month == 2 && day > 29 && visokosni_god == true) {
  488. korrekt_data = false;
  489. }
  490. if (month == 2 && day > 28 && visokosni_god == false) {
  491. korrekt_data = false;
  492. }
  493. if (month == 4 || month == 6 || month == 9 || month == 11) {
  494. if (day > 30) {
  495. korrekt_data = false;
  496. }
  497. }
  498. if (korrekt_data == true) {
  499. return false;
  500. }
  501. else {
  502. cout << "Неверный формат/такая дата не существует! Введите данные заново!" << endl;
  503. return true;
  504. }
  505. }
  506. }
  507.  
  508. void add_jury() {
  509. ofstream file2("jury.txt", ios_base::app);
  510. if (!file2) {
  511. cout << "Невозможно открыть файл." << endl;
  512. system("pause");
  513. }
  514.  
  515. cout << "Введите фамилию председателя жюри :";
  516. jury.surname = add_protect();
  517.  
  518. cout << "Введите номер телефона председателя жюри :";
  519. cin >> jury.phone;
  520. ifstream check("jury.txt", ios_base::app);
  521. int ID = 1;
  522. while (check >> jury.surname >> jury.phone >> jury.id_jury) {
  523. ID++;
  524. }
  525. check.close();
  526.  
  527. jury.id_jury = ID;
  528.  
  529. file2 << jury.surname << ' ' << jury.phone << ' ' << jury.id_jury << endl;
  530. file2.close();
  531. }
  532.  
  533. void read_jury() {
  534. ifstream file1("jury.txt", ios_base::app);
  535. cout << setw(12) << left << "Фамилия" << setw(12) << left << "Телефон" << setw(12) << left << "ID" << endl;
  536. while (file1 >> jury.surname >> jury.phone >> jury.id_jury) {
  537. cout << "___________________________________" << endl;
  538. cout << setw(12) << jury.surname << setw(12) << jury.phone << setw(12) << jury.id_jury << endl;
  539.  
  540. }
  541. file1.close();
  542. }
  543.  
  544. int kol_jury() {
  545. int kol = 0;
  546. ifstream file("jury.txt", ios_base::app);
  547. while (file >> jury.surname >> jury.phone >> jury.id_jury) {
  548. kol++;
  549. }
  550. file.close();
  551. return kol;
  552. }
  553.  
  554. int add_participant() {
  555. ofstream f("info.txt", ios_base::app);
  556. if (!f) {
  557. cout << "Невозможно открыть файл." << endl;
  558. system("pause");
  559. }
  560. cout << "Введите имя :";
  561. info.participant.name = add_protect();
  562. cout << "Введите фамилию :";
  563. info.participant.family = add_protect();
  564. cout << "Введите отчество :";
  565. info.participant.patronymic = add_protect();
  566. ifstream check("info.txt", ios_base::app);
  567. int ID = 1;
  568. while (check >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  569. ID++;
  570. }
  571. check.close();
  572. info.participant.ID = ID;
  573. cout << "Введите название песни :";
  574. info.participant.kategory.song = add_protect();
  575. cout << "Введите инструмент :";
  576. info.participant.kategory.tool = add_protect();
  577. float sum = 0, grade, kol;
  578. kol = kol_jury();
  579. if (kol == 0) {
  580. system("cls");
  581. cout << "Не существует ни одного председателя жюри! Добавьте хотя бы одного" << endl;
  582. system("pause");
  583. return 0;
  584. }
  585. else {
  586. cout << "Необходимо расставить оценки жюри" << endl;
  587. read_jury();
  588. ifstream file("jury.txt", ios_base::app);
  589. while (file >> jury.surname >> jury.phone >> jury.id_jury) {
  590. cout << "Введите оценку члена жюри с индиф. номером " << jury.id_jury << ": ";
  591. cin >> grade;
  592. sum = sum + grade;
  593. }
  594. file.close();
  595. info.rating = sum / kol;
  596. cout << "Введите дату выступления" << endl;
  597. bool check = true;
  598. int day, month, year;
  599. while (check) {
  600. cout << "Введите день выступления" << endl;
  601. rewind(stdin);
  602. cin >> day;
  603. proverka_na_chislo(day);
  604. cout << "Введите месяц выступления" << endl;
  605. rewind(stdin);
  606. cin >> month;
  607. proverka_na_chislo(month);
  608. cout << "Введите год выступления" << endl;
  609. rewind(stdin);
  610. cin >> year;
  611. proverka_na_chislo(year);
  612. check = check_date(day, month, year);
  613. }
  614. info.day = day;
  615. info.month = month;
  616. info.year = year;
  617.  
  618.  
  619.  
  620. f << info.participant.name << ' ' << info.participant.family << ' ' << info.participant.patronymic << ' ' << info.participant.ID << ' ' << info.participant.kategory.song <<
  621. ' ' << info.participant.kategory.tool << ' ' << info.rating << ' ' << info.day << ' ' << info.month << ' ' << info.year << endl;
  622. }
  623. f.close();
  624. return 0;
  625. system("cls");
  626. }
  627.  
  628.  
  629.  
  630. void read_participant() {
  631. ifstream file1("info.txt", ios_base::app);
  632. if (!file1) {
  633. cout << "Невозможно открыть файл." << endl;
  634. system("pause");
  635. }
  636. cout << setw(12) << left << "Имя" << setw(12) << left << "Фамилия" << setw(12) << left << "Отчество" << setw(12) << left << "ID" << setw(12) << left << "Песня" << setw(12) << left << "Инструмент" << endl;
  637. while (file1 >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  638. cout << "______________________________________________________________________" << endl;
  639. cout << setw(12) << info.participant.name << setw(12) << info.participant.family << setw(12) << info.participant.patronymic << setw(12) << info.participant.ID << setw(12) << info.participant.kategory.song << setw(12) << info.participant.kategory.tool << endl;
  640.  
  641. }
  642. file1.close();
  643. }
  644.  
  645. void redakt_participant()
  646. {
  647. ifstream red_f1("info.txt", ios_base::app);
  648. ofstream red_f2("info2.txt", ios_base::ate);
  649. int id_redakt;
  650. read_participant();
  651. cout << endl << endl;
  652. cout << "Введите ID участника, данные которого нужно изменить" << endl;
  653. cin >> id_redakt;
  654. proverka_na_chislo(id_redakt);
  655. while (red_f1 >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year)
  656. {
  657. if (info.participant.ID != id_redakt)
  658. {
  659. red_f2 << info.participant.name << ' ' << info.participant.family << ' ' << info.participant.patronymic << ' ' << info.participant.ID << ' ' << info.participant.kategory.song << ' ' << info.participant.kategory.tool << ' ' << info.rating << ' ' << info.day << ' ' << info.month << ' ' << info.year << endl;
  660. }
  661. else if (info.participant.ID == id_redakt) {
  662. cout << "Введите имя :";
  663. info.participant.name = add_protect();
  664. cout << "Введите фамилию :";
  665. info.participant.family = add_protect();
  666. cout << "Введите отчество :";
  667. info.participant.patronymic = add_protect();
  668.  
  669. info.participant.ID = id_redakt;
  670. cout << "Введите название песни :";
  671. info.participant.kategory.song = add_protect();
  672. cout << "Введите инструмент(если таков имеется) :";
  673. info.participant.kategory.tool = add_protect();
  674. float sum = 0, grade, kol;
  675. kol = kol_jury();
  676. cout << "Необходимо расставить оценки жюри" << endl;
  677. read_jury();
  678. ifstream file("jury.txt", ios_base::app);
  679. while (file >> jury.surname >> jury.phone >> jury.id_jury) {
  680. cout << "Введите оценку члена жюри с индиф. номером " << jury.id_jury << ": ";
  681. cin >> grade;
  682. proverka_na_chislo(grade);
  683. sum = sum + grade;
  684. }
  685. file.close();
  686. info.rating = sum / kol;
  687. cout << "Введите дату выступления" << endl;
  688. bool check = true;
  689. int day, month, year;
  690. while (check) {
  691. cout << "Введите день" << endl;
  692. rewind(stdin);
  693. cin >> day;
  694. proverka_na_chislo(day);
  695. cout << "Введите месяц" << endl;
  696. rewind(stdin);
  697. cin >> month;
  698. proverka_na_chislo(month);
  699. cout << "Введите год" << endl;
  700. rewind(stdin);
  701. cin >> year;
  702. proverka_na_chislo(year);
  703. check = check_date(day, month, year);
  704. }
  705. info.day = day;
  706. info.month = month;
  707. info.year = year;
  708.  
  709.  
  710.  
  711. red_f2 << info.participant.name << ' ' << info.participant.family << ' ' << info.participant.patronymic << ' ' << info.participant.ID << ' ' << info.participant.kategory.song <<
  712. ' ' << info.participant.kategory.tool << ' ' << info.rating << ' ' << info.day << ' ' << info.month << ' ' << info.year << endl;
  713.  
  714. }
  715. }
  716. red_f1.close();
  717. red_f2.close();
  718. ofstream red_f3("info.txt", ios_base::ate);
  719. ifstream red_f4("info2.txt", ios_base::app);
  720. while (red_f4 >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  721. red_f3 << info.participant.name << ' ' << info.participant.family << ' ' << info.participant.patronymic << ' ' << info.participant.ID << ' ' << info.participant.kategory.song <<
  722. ' ' << info.participant.kategory.tool << ' ' << info.rating << ' ' << info.day << ' ' << info.month << ' ' << info.year << endl;
  723. }
  724. red_f3.close();
  725. red_f4.close();
  726. system("pause");
  727. }
  728. void redakt_jury()
  729. {
  730. ifstream red_f1("jury.txt", ios_base::app);
  731. ofstream red_f2("jury2.txt", ios_base::ate);
  732. int id_redakt;
  733. read_jury();
  734. cout << endl << endl;
  735. cout << "Введите ID председателя жюри, данные которого нужно изменить" << endl;
  736. cin >> id_redakt;
  737. proverka_na_chislo(id_redakt);
  738. while (red_f1 >> jury.surname >> jury.phone >> jury.id_jury)
  739. {
  740. if (jury.id_jury != id_redakt)
  741. {
  742. red_f2 << jury.surname << ' ' << jury.phone << ' ' << jury.id_jury << endl;
  743. }
  744. else if (jury.id_jury == id_redakt) {
  745. cout << "Введите фамилию :";
  746. jury.surname = add_protect();
  747. cout << "Введите номер телефона :";
  748. cin >> jury.phone;
  749. jury.id_jury = id_redakt;
  750. red_f2 << jury.surname << ' ' << jury.phone << ' ' << jury.id_jury << endl;
  751.  
  752. }
  753. }
  754. red_f1.close();
  755. red_f2.close();
  756. ofstream red_f3("jury.txt", ios_base::ate);
  757. ifstream red_f4("jury2.txt", ios_base::app);
  758. while (red_f4 >> jury.surname >> jury.phone >> jury.id_jury)
  759. {
  760. red_f3 << jury.surname << ' ' << jury.phone << ' ' << jury.id_jury << endl;
  761. }
  762. red_f3.close();
  763. red_f4.close();
  764. system("pause");
  765. }
  766.  
  767. void full_poisk() {
  768. char c;
  769. ifstream file("info.txt"); // открыли файл с текстом
  770. string s;
  771. int amount = 0;
  772. while (!file.eof()) { // прочитали его и заполнили им строку
  773. file.get(c);
  774. s.push_back(c);
  775. amount++;
  776. }
  777. file.close();
  778. string t;
  779. cout << "Общий файл" << endl;
  780. cout << "Введите запрос" << endl;
  781. cin >> t;
  782. int i, j, k, x, size = t.size(), string = 1;
  783. bool check = false;
  784. for (i = 0; i <= amount - size - 1; i++) {
  785. if (s[i] == '\n') {
  786. string += 1;
  787. }
  788. if (s[i] == t[0]) {
  789. k = i;
  790. x = 0;
  791. for (j = 1; j < size + 1; j++) {
  792. if (s[k + j] != t[j]) {
  793. break;
  794. }
  795. else x++;
  796. }
  797. if (x + 1 == size) {
  798.  
  799. ifstream f("info.txt", ios_base::app);
  800. if (f.peek() == EOF)
  801. {
  802. cout << "Файл пустой." << endl;
  803. }
  804. else {
  805. if (check == false) {
  806. cout << setw(84) << " " << "Дата выступления" << endl;
  807. cout << setw(12) << left << "Имя" << setw(12) << left << "Фамилия" << setw(12) << left << "Отчество" << setw(12) << left << "ID" << setw(12) << left << "Песня" << setw(12) << left << "Инструмент" << setw(12) << left << "Рейтинг" << setw(12) << left << "День" << setw(12) << left << "Месяц" << setw(12) << left << "Год" << endl;
  808. check = true;
  809. }
  810. while (f >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  811. if (string == info.participant.ID) {
  812. cout << "_______________________________________________________________________________________________________________________" << endl;
  813. cout << setw(12) << info.participant.name << setw(12) << info.participant.family << setw(12) << info.participant.patronymic << setw(12) << info.participant.ID << setw(12) << info.participant.kategory.song << setw(12) << info.participant.kategory.tool << setw(12) << left << info.rating << setw(12) << left << info.day << setw(12) << left << info.month << setw(12) << left << info.year << endl;
  814. cout << "_______________________________________________________________________________________________________________________" << endl;
  815. }
  816. }
  817. while (s[i + 1] != '\n') {
  818. i++;
  819. }
  820. }
  821. f.close();
  822. }
  823.  
  824. }
  825. }
  826. if (check == false) {
  827. system("cls");
  828. cout << "Информация не найдена!" << endl;
  829. }
  830. system("pause");
  831. system("cls");
  832. }
  833.  
  834. void jury_poisk() {
  835. char c;
  836. ifstream file("jury.txt"); // открыли файл с текстом
  837. string s;
  838. int amount = 0;
  839. while (!file.eof()) { // прочитали его и заполнили им строку
  840. file.get(c);
  841. s.push_back(c);
  842. amount++;
  843. }
  844. file.close();
  845. string t;
  846. cout << "Общий файл" << endl;
  847. cout << "Введите запрос" << endl;
  848. cin >> t;
  849. int i, j, k, x, size = t.size(), string = 1;
  850. bool check = false;
  851. for (i = 0; i <= amount - size - 1; i++) {
  852. if (s[i] == '\n') {
  853. string += 1;
  854. }
  855. if (s[i] == t[0]) {
  856. k = i;
  857. x = 0;
  858. for (j = 1; j < size + 1; j++) {
  859. if (s[k + j] != t[j]) {
  860. break;
  861. }
  862. else x++;
  863. }
  864. if (x + 1 == size) {
  865.  
  866. ifstream f("jury.txt", ios_base::app);
  867. if (f.peek() == EOF)
  868. {
  869. cout << "Файл пустой." << endl;
  870. }
  871. else {
  872. if (check == false) {
  873. cout << setw(12) << left << "Фамилия" << setw(12) << left << "Телефон" << setw(12) << left << "ID" << endl;
  874.  
  875. check = true;
  876. }
  877. while (f >> jury.surname >> jury.phone >> jury.id_jury) {
  878. if (string == jury.id_jury) {
  879. cout << "___________________________________" << endl;
  880. cout << setw(12) << jury.surname << setw(12) << jury.phone << setw(12) << jury.id_jury << endl;
  881. cout << "___________________________________" << endl;
  882. }
  883. }
  884. while (s[i + 1] != '\n') {
  885. i++;
  886. }
  887. }
  888. f.close();
  889. }
  890.  
  891. }
  892. }
  893. if (check == false) {
  894. system("cls");
  895. cout << "Информация не найдена!" << endl;
  896. }
  897. system("pause");
  898. system("cls");
  899. }
  900.  
  901. void poisk_menu() {
  902. int input;
  903. bool hod = true;
  904. while (hod) {
  905. cout << "Меню поиска" << endl;
  906. cout << "1. Поиск по файлу с полной информацией об участнике музыкального конкурса" << endl;
  907. cout << "2. Поиск по файлу с жюри" << endl;
  908. cout << "3. Шаг назад" << endl;
  909. cin >> input;
  910. proverka_na_chislo(input);
  911. system("cls");
  912. switch (input) {
  913. case 1: {
  914. full_poisk();
  915. system("cls");
  916. break;
  917. }
  918. case 2: {
  919. jury_poisk();
  920. system("cls");
  921. break;
  922. }
  923. case 3: {
  924. hod = false;
  925. }
  926. default: {
  927. cout << "Неверный ввод повторите попытку" << endl;
  928. }
  929. }
  930. }
  931. }
  932.  
  933. void delete_participant() {
  934. ifstream del_f1("info.txt", ios_base::app);
  935. ofstream del_f2("info2.txt", ios_base::ate);
  936.  
  937. int id_delete;
  938. read_participant();
  939. cout << endl << endl;
  940. cout << "Введите ID участника, которого нужно удалить" << endl;
  941. cin >> id_delete;
  942. proverka_na_chislo(id_delete);
  943. while (del_f1 >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  944. if (info.participant.ID != id_delete) {
  945. del_f2 << info.participant.name << ' ' << info.participant.family << ' ' << info.participant.patronymic << ' ' << info.participant.ID << ' ' << info.participant.kategory.song <<
  946. ' ' << info.participant.kategory.tool << ' ' << info.rating << ' ' << info.day << ' ' << info.month << ' ' << info.year << endl;
  947. }
  948. }
  949.  
  950. del_f1.close();
  951. del_f2.close();
  952. ofstream del_f3("info.txt", ios_base::ate);
  953. ifstream del_f4("info2.txt", ios_base::app);
  954. int ID = 1;
  955. while (del_f4 >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  956. info.participant.ID = ID;
  957. ID++;
  958. del_f3 << info.participant.name << ' ' << info.participant.family << ' ' << info.participant.patronymic << ' ' << info.participant.ID << ' ' << info.participant.kategory.song <<
  959. ' ' << info.participant.kategory.tool << ' ' << info.rating << ' ' << info.day << ' ' << info.month << ' ' << info.year << endl;
  960. }
  961. del_f3.close();
  962. del_f4.close();
  963. system("pause");
  964. }
  965.  
  966. void delete_jury()
  967. {
  968. ifstream del_f1("jury.txt", ios_base::app);
  969. ofstream del_f2("jury2.txt", ios_base::ate);
  970. int id_delete;
  971. read_jury();
  972. cout << endl << endl;
  973. cout << "Введите ID председателя жюри, которого нужно удалить" << endl;
  974. cin >> id_delete;
  975. proverka_na_chislo(id_delete);
  976. int ID = 1;
  977. while (del_f1 >> jury.surname >> jury.phone >> jury.id_jury) {
  978. if (jury.id_jury != id_delete) {
  979. jury.id_jury = ID;
  980. ID++;
  981. del_f2 << jury.surname << ' ' << jury.phone << ' ' << jury.id_jury << endl;
  982. }
  983. }
  984.  
  985. del_f1.close();
  986. del_f2.close();
  987. ofstream del_f3("jury.txt", ios_base::ate);
  988. ifstream del_f4("jury2.txt", ios_base::app);
  989. while (del_f4 >> jury.surname >> jury.phone >> jury.id_jury) {
  990. del_f3 << jury.surname << ' ' << jury.phone << ' ' << jury.id_jury << endl;
  991. }
  992. del_f3.close();
  993. del_f4.close();
  994. }
  995.  
  996. void read_full_info() {
  997. ifstream file1("info.txt", ios_base::app);
  998. cout << setw(84) << " " << "Дата выступления" << endl;
  999. cout << setw(12) << left << "Имя" << setw(12) << left << "Фамилия" << setw(12) << left << "Отчество" << setw(12) << left << "ID" << setw(12) << left << "Песня" << setw(12) << left << "Инструмент" << setw(12) << left << "Рейтинг" << setw(12) << left << "День" << setw(12) << left << "Месяц" << setw(12) << left << "Год" << endl;
  1000. while (file1 >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  1001. cout << "_______________________________________________________________________________________________________________________" << endl;
  1002. cout << setw(12) << info.participant.name << setw(12) << info.participant.family << setw(12) << info.participant.patronymic << setw(12) << info.participant.ID << setw(12) << info.participant.kategory.song << setw(12) << info.participant.kategory.tool << setw(12) << left << info.rating << setw(12) << left << info.day << setw(12) << left << info.month << setw(12) << left << info.year << endl;
  1003. }
  1004. file1.close();
  1005. }
  1006.  
  1007. void read_ocenki() {
  1008. ifstream file1("info.txt", ios_base::app);
  1009. if (!file1) {
  1010. cout << "Невозможно открыть файл." << endl;
  1011. system("pause");
  1012. }
  1013. cout << setw(12) << left << "Имя" << setw(12) << left << "Фамилия" << setw(12) << left << "Отчество" << setw(12) << left << "ID" << setw(12) << left << "Рейтинг" << endl;
  1014. while (file1 >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  1015. cout << "______________________________________________________________________" << endl;
  1016. cout << setw(12) << info.participant.name << setw(12) << info.participant.family << setw(12) << info.participant.patronymic << setw(12) << info.participant.ID << setw(12) << info.rating << endl;
  1017.  
  1018. }
  1019. file1.close();
  1020. }
  1021.  
  1022. void read_users() {
  1023.  
  1024. ifstream file1("users.txt", ios_base::app);
  1025. if (file1.peek() == EOF) {
  1026. cout << "Зарегистрированных пользователей не существует!" << endl;
  1027. }
  1028. else {
  1029. cout << setw(20) << left << "Логин" << setw(20) << "Пароль" << endl;
  1030. while (file1 >> user.log >> user.pass) {
  1031. cout << "___________________________________" << endl;
  1032. user.log = Shifr(user.log, 0);
  1033. user.pass = Shifr(user.pass, 0);
  1034. cout << setw(20) << user.log << setw(20) << user.pass << endl;
  1035.  
  1036. }
  1037. }
  1038. file1.close();
  1039. }
  1040.  
  1041.  
  1042. void delete_user() {
  1043. bool check = false;
  1044. read_users();
  1045. ifstream file1("users.txt", ios_base::app);
  1046. if (!file1.peek() == EOF) {
  1047.  
  1048. cout << "Введите логин пользователя, которого вы хотите удалить" << endl;
  1049. string login;
  1050. cin >> login;
  1051. login = Shifr(login, 1);
  1052. while (file1 >> user.log >> user.pass) {
  1053. if (user.log == login) {
  1054. check = true;
  1055. break;
  1056. }
  1057. }
  1058. file1.close();
  1059. if (check == false) {
  1060. cout << "Пользователь с данным логином не найдем" << endl;
  1061. }
  1062. else {
  1063. ifstream del_f1("users.txt", ios_base::app);
  1064. ofstream del_f2("users2.txt", ios_base::ate);
  1065.  
  1066. while (del_f1 >> user.log >> user.pass) {
  1067. if (login != user.log) {
  1068. del_f2 << user.log << ' ' << user.pass << endl;
  1069. }
  1070. }
  1071.  
  1072. del_f1.close();
  1073. del_f2.close();
  1074. ofstream del_f3("users.txt", ios_base::ate);
  1075. ifstream del_f4("users2.txt", ios_base::app);
  1076. while (del_f4 >> user.log >> user.pass) {
  1077. del_f3 << user.log << ' ' << user.pass << endl;
  1078. }
  1079. del_f3.close();
  1080. del_f4.close();
  1081. system("pause");
  1082. }
  1083. }
  1084. }
  1085.  
  1086. void sort_menu();
  1087.  
  1088. int check_admin() {
  1089. bool result = false;
  1090. char new_login[20], new_password[20], new_password_2[20];
  1091. FILE *f = fopen("admin.txt", "rb");
  1092. char a;
  1093. size_t readed = fread(&a, 1, 1, f);
  1094. if (!readed) {
  1095. cout << "Вы первый администратор! Зарегистрируйтесь" << endl;
  1096. cout << "Введите новый логин: " << endl;
  1097. fflush(stdin);
  1098. cin >> new_login;
  1099. while (strcmp(new_password, new_password_2)) {
  1100. cout << "Введите новый пароль: " << endl;
  1101. fflush(stdin);
  1102. cin >> new_password;
  1103.  
  1104. cout << "Введите новый пароль еще раз для подтвержения: " << endl;
  1105. fflush(stdin);
  1106. cin >> new_password_2;
  1107.  
  1108. if (strcmp(new_password, new_password_2)) {
  1109. cout << "Пароли не совпадают!" << endl;
  1110. }
  1111. }
  1112. string new_log, new_pass;
  1113. new_log = new_login;
  1114. new_pass = new_password;
  1115. new_log = Shifr(new_log, 1);
  1116. new_pass = Shifr(new_pass, 1);
  1117. ofstream fout("admin.txt"); // создаём объект класса ofstream для записи и связываем его с файлом admin.txt
  1118. fout << new_log << " " << new_pass; // запись строки в файл
  1119. fout.close();
  1120. }
  1121. else {
  1122. char login[20], password[20], true_login[20], true_password[20];
  1123. FILE *f;
  1124. f = fopen("admin.txt", "rt"); //переписать эту муть через fstream
  1125. fscanf(f, "%s%s", &true_login, &true_password);
  1126. fclose(f);
  1127. fflush(stdin);
  1128. cout << "Введите логин и пароль для входа в учетную запись администратора" << endl;
  1129. while (result == false) {
  1130.  
  1131. cout << "Логин: " << endl;
  1132. fflush(stdin); //убрать все вот эти штуки
  1133. cin >> login;
  1134. cout << "Пароль: " << endl;
  1135.  
  1136. int i = 0;
  1137. while (i < 20)
  1138. {
  1139. char c;
  1140. if (!(c = _getch())) {
  1141. c = _getch();
  1142. if (c == 8) {
  1143. system("cls");
  1144. cout << "Введите логин и пароль для входа в учетную запись администратора" << endl;
  1145. cout << "Логин: " << endl;
  1146. cout << login << endl;
  1147. cout << "Пароль: " << endl;
  1148. i = -1;
  1149. }
  1150. if (c == 13)
  1151. break;
  1152. }
  1153. if (i != -1) {
  1154. password[i] = c;
  1155. }
  1156. i++;
  1157. if (c != 8) {
  1158. _putch('*');
  1159. }
  1160. }
  1161. password[i] = '\0';
  1162. string pass = password, log = login;
  1163. pass = Shifr(pass, 1);
  1164. log = Shifr(log, 1);
  1165. fflush(stdin);
  1166. if ((log == true_login) && (pass == true_password)) {
  1167. result = true;
  1168. }
  1169. else {
  1170. cout << "\nНеверный логин и/или пароль!" << endl;
  1171. system("pause");
  1172. system("cls");
  1173. return 0;
  1174. }
  1175.  
  1176. }
  1177. }
  1178. if (result == true) {
  1179. while (1) {
  1180. system("cls");
  1181. switch (admin_menu())
  1182. {
  1183. case 1: {
  1184. cout << "1. Создание/открытие файла с данными" << endl;
  1185. cout << "1 - Файл с участниками и оценками " << endl << "2 - Файл с председателями жюри." << endl << "3 - Назад в меню." << endl;
  1186. int flag;
  1187. cout << "Выберите действие :";
  1188. cin >> flag;
  1189. proverka_na_chislo(flag);
  1190. rewind(stdin);
  1191. switch (flag) {
  1192. case 1: {
  1193. ifstream person_file("info.txt");
  1194. if (!person_file) {
  1195. cout << "Создан новый файл!" << endl;
  1196. }
  1197. person_file.close();
  1198. ofstream person_file_out("info.txt", ios_base::app);
  1199. person_file_out.close();
  1200. system("info.txt");
  1201. break;
  1202. }
  1203. case 2:
  1204. {
  1205. ifstream jur_file("jury.txt");
  1206. if (!jur_file) {
  1207. cout << "Создан новый файл!" << endl;
  1208. }
  1209. jur_file.close();
  1210. ofstream jur_file_out("jury.txt", ios_base::app);
  1211. jur_file_out.close();
  1212. system("jury.txt");
  1213. break;
  1214. }
  1215. case 3:
  1216. {
  1217. break;
  1218. }
  1219.  
  1220. }
  1221. break;
  1222. }
  1223. case 2: {
  1224. cout << "2. Добавление записи" << endl;
  1225. cout << "1 - Файл с участниками и оценками." << endl << "2 - Файл с председателями жюри." << endl << "3 - Назад в меню." << endl;
  1226. int flag;
  1227. cout << "Выберите действие :";
  1228. cin >> flag;
  1229. proverka_na_chislo(flag);
  1230. switch (flag) {
  1231. case 1: {
  1232. add_participant();
  1233. break;
  1234. }
  1235. case 2: {
  1236. add_jury();
  1237. break;
  1238. }
  1239.  
  1240. case 3: {
  1241. break;
  1242. }
  1243. default: {
  1244. cout << "Вы неверно выбрали действие, повторите попытку!" << endl;
  1245. cin.clear();
  1246. cin.sync();
  1247. rewind(stdin);
  1248. system("pause");
  1249. break;
  1250. }
  1251. }
  1252. break;
  1253. }
  1254. case 3: {
  1255. cout << "3. Редактирование записи" << endl;
  1256. cout << "1 - Файл с участниками и оценками." << endl << "2 - Файл с председателями жюри." << endl << "3 - Назад в меню." << endl;
  1257. int flag;
  1258. cout << "Выберите действие :";
  1259. cin >> flag;
  1260. proverka_na_chislo(flag);
  1261. switch (flag) {
  1262. case 1: {
  1263. redakt_participant();
  1264. break;
  1265. }
  1266. case 2: {
  1267. redakt_jury();
  1268. break;
  1269. }
  1270.  
  1271. case 3: {
  1272. break;
  1273. }
  1274. default: {
  1275. cout << "Вы неверно выбрали действие, повторите попытку!" << endl;
  1276. cin.clear();
  1277. cin.sync();
  1278. rewind(stdin);
  1279. system("pause");
  1280. break;
  1281. }
  1282. }
  1283. break;
  1284. }
  1285.  
  1286. case 4: {
  1287. cout << "4. Удаление записи" << endl;
  1288. cout << "1 - Файл с участниками и оценками." << endl << "2 - Файл с председателями жюри." << endl << "3 - Назад в меню." << endl;
  1289. int flag;
  1290. cout << "Выберите действие :";
  1291. cin >> flag;
  1292. proverka_na_chislo(flag);
  1293. switch (flag) {
  1294. case 1: {
  1295. delete_participant();
  1296. break;
  1297. }
  1298. case 2: {
  1299. delete_jury();
  1300. break;
  1301. }
  1302.  
  1303. case 3: {
  1304. break;
  1305. }
  1306. default: {
  1307. cout << "Вы неверно выбрали действие, повторите попытку!" << endl;
  1308. cin.clear();
  1309. cin.sync();
  1310. rewind(stdin);
  1311. system("pause");
  1312. break;
  1313. }
  1314. }
  1315. break;
  1316. }
  1317.  
  1318.  
  1319. case 5: {
  1320. cout << "5. Просмотр всех данных в табличной форме" << endl;
  1321. cout << "1 - Файл с участниками." << endl << "2 - Файл с председателями жюри." << endl << "3 - Файл с оценками" << endl << "4 - Файл с полной информацией" << endl << "5 - Назад в меню." << endl;
  1322. int flag;
  1323. cout << "Выберите действие :";
  1324. cin >> flag;
  1325. proverka_na_chislo(flag);
  1326. switch (flag) {
  1327. case 1: {
  1328. read_participant();
  1329. system("pause");
  1330. system("cls");
  1331. break;
  1332. }
  1333. case 2: {
  1334. read_jury();
  1335. system("pause");
  1336. system("cls");
  1337. break;
  1338. }
  1339.  
  1340. case 3: read_ocenki();
  1341. system("pause");
  1342. system("cls");
  1343. break;
  1344.  
  1345. case 4: {
  1346. read_full_info();
  1347. system("pause");
  1348. system("cls");
  1349. break;
  1350. }
  1351. case 5: {
  1352. break;
  1353. }
  1354. default: {
  1355. cout << "Вы неверно выбрали действие, повторите попытку!" << endl;
  1356. cin.clear();
  1357. cin.sync();
  1358. rewind(stdin);
  1359. system("pause");
  1360. break;
  1361. }
  1362. }
  1363. break;
  1364. }
  1365. case 6: {
  1366. cout << "6. Поиск и фильтрация данных" << endl;
  1367. cout << "1. Поиск данных" << endl;
  1368. cout << "2. Фильтрация данных" << endl;
  1369. cout << "3. Сортировка данных" << endl;
  1370. cout << "4. Назад" << endl;
  1371. cout << "Выберите действие :";
  1372. int result;
  1373. cin >> result;
  1374. proverka_na_chislo(result);
  1375. switch (result) {
  1376. case 1: {
  1377. poisk_menu();
  1378. system("cls");
  1379. break;
  1380. }
  1381. case 2: {
  1382. filtr_menu();
  1383. break;
  1384. }
  1385. case 3: {
  1386. sort_menu();
  1387. system("cls");
  1388. break;
  1389. }
  1390. case 4: {
  1391. break;
  1392. }
  1393. default: {
  1394. cout << "Вы неверно выбрали действие, повторите попытку!" << endl;
  1395. cin.clear();
  1396. cin.sync();
  1397. rewind(stdin);
  1398. system("pause");
  1399. break;
  1400. }
  1401. }
  1402. break;
  1403. }
  1404. case 7: {
  1405. cout << "7. Управление пользователями" << endl;
  1406. cout << "1. Просмотр списка логинов и паролей учетных записей" << endl << "2. Удаление пользователя" << endl << "3. Шаг назад" << endl;
  1407. int flag;
  1408. cout << "Выберите действие :";
  1409. cin >> flag;
  1410. proverka_na_chislo(flag);
  1411. switch (flag) {
  1412. case 1: {
  1413. read_users();
  1414. system("pause");
  1415. system("cls");
  1416. break;
  1417. }
  1418. case 2: {
  1419. delete_user();
  1420. system("pause");
  1421. system("cls");
  1422. break;
  1423. }
  1424. case 3: {
  1425. break;
  1426. }
  1427. default: {
  1428. cout << "Вы неверно выбрали действие, повторите попытку!" << endl;
  1429. cin.clear();
  1430. cin.sync();
  1431. rewind(stdin);
  1432. system("pause");
  1433. break;
  1434. }
  1435. }
  1436. break;
  1437. }
  1438. case 8: {
  1439. return 0;
  1440. }
  1441. }
  1442. }
  1443. }
  1444. system("cls");
  1445. return 0;
  1446. }
  1447.  
  1448.  
  1449. void user_registr() {
  1450. string new_log, new_pass;
  1451. bool flag = true;
  1452. cout << "Регистрация нового пользователя" << endl;
  1453. while (flag == true) {
  1454. bool check = false;
  1455. cout << "Введите новый логин для регистрации" << endl;
  1456. rewind(stdin);
  1457. cin >> new_log;
  1458. cout << "Введите новый пароль для регистрации" << endl;
  1459. rewind(stdin);
  1460. cin >> new_pass;
  1461. ifstream u("users.txt", ios_base::app);
  1462. if (!u) {
  1463. cout << "Файл не существует!" << endl;
  1464. system("pause");
  1465. }
  1466. while (u >> user.log >> user.pass) {
  1467. if (user.log == new_log) {
  1468. check = true;
  1469. break;
  1470. }
  1471. }
  1472. u.close();
  1473. if (check == true) {
  1474. cout << "Пользователь с данным логином уже существует!" << endl;
  1475. }
  1476. else flag = false;
  1477. }
  1478. user.log = Shifr(new_log, 1);
  1479. user.pass = Shifr(new_pass, 1);
  1480. ofstream fout("users.txt", ios_base::app);
  1481. fout << user.log << " " << user.pass << endl;
  1482. fout.close();
  1483. system("cls");
  1484. cout << "Вы зарегистрированы." << endl;
  1485. }
  1486. void zadanie() {
  1487. int max_day, max_month, max_year;
  1488. ifstream f("info.txt", ios_base::app);
  1489. if (f.peek() == EOF) {
  1490. cout << "Участников нет" << endl;
  1491. }
  1492. else {
  1493. while (f >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  1494. max_day = info.day;
  1495. max_month = info.month;
  1496. max_year = info.year;
  1497. break;
  1498. }
  1499. f.close();
  1500. ifstream f1("info.txt", ios_base::app);
  1501. while (f1 >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  1502. if (info.year > max_year) {
  1503. max_year = info.year;
  1504. }
  1505. if (max_year == info.year && max_month < info.month) {
  1506. max_month = info.month;
  1507. }
  1508. if (max_year == info.year && max_month == info.month && max_day < info.day) {
  1509. max_day = info.day;
  1510. }
  1511. }
  1512. f1.close();
  1513. ifstream f2("info.txt", ios_base::app);
  1514. float rating = 0, count = 0;
  1515. while (f2 >> info.participant.name >> info.participant.family >> info.participant.patronymic >> info.participant.ID >> info.participant.kategory.song >> info.participant.kategory.tool >> info.rating >> info.day >> info.month >> info.year) {
  1516. if (info.day == max_day && info.month == max_month && info.year == max_year) {
  1517. count = count + 1;
  1518. rating = rating + info.rating;
  1519. }
  1520. }
  1521. f2.close();
  1522. cout << "Средний балл участников за последнее выступление равен: " << rating / count << endl;
  1523. }
  1524. }
  1525.  
  1526. int user_login() {
  1527. int check = 0;
  1528. ifstream u("users.txt", ios_base::app);
  1529. if (u.peek() == EOF) {
  1530. cout << "Зарегистрированных пользователей не существует!" << endl;
  1531. return 0;
  1532. }
  1533. else {
  1534. string login;
  1535. char password[20];
  1536. cout << "Авторизация" << endl;
  1537. cout << "Введите логин" << endl;
  1538. rewind(stdin);
  1539. cin >> login;
  1540. cout << "Введите пароль" << endl;
  1541. rewind(stdin);
  1542. int i = 0;
  1543. while (i < 20)
  1544. {
  1545. char c;
  1546. if (!(c = _getch())) {
  1547. c = _getch();
  1548. if (c == 8) {
  1549. system("cls");
  1550. cout << "Авторизация" << endl;
  1551. cout << "Введите логин" << endl;
  1552. cout << login << endl;
  1553. cout << "Введите пароль " << endl;
  1554. i = -1;
  1555. }
  1556. if (c == 13)
  1557. break;
  1558. }
  1559. if (i != -1) {
  1560. password[i] = c;
  1561. }
  1562. i++;
  1563. if (c != 8) {
  1564. _putch('*');
  1565. }
  1566. }
  1567. password[i] = '\0';
  1568. string str_password;
  1569. str_password = password;
  1570. str_password = Shifr(str_password, 1);
  1571. login = Shifr(login, 1);
  1572. cout << endl;
  1573. while (u >> user.log >> user.pass) {
  1574. if (user.log == login && user.pass == str_password) {
  1575. check = 1;
  1576. system("cls");
  1577. break;
  1578. }
  1579. }
  1580. u.close();
  1581. if (check == 0) {
  1582. system("cls");
  1583. cout << "Данного пользователя не существует, либо неправильный пароль" << endl;
  1584. return 0;
  1585. }
  1586. else
  1587. {
  1588. switch (user_menu())
  1589. {
  1590. case 1:
  1591. {
  1592. cout << "1. Создание/открытие файла с данными" << endl;
  1593. cout << "1 - Файл с участниками и оценками " << endl << "2 - Файл с председателями жюри." << endl << "3 - Назад в меню." << endl;
  1594. int flag;
  1595. cout << "Выберите действие :";
  1596. cin >> flag;
  1597. proverka_na_chislo(flag);
  1598. rewind(stdin);
  1599. switch (flag) {
  1600. case 1: {
  1601. ifstream person_file("info.txt");
  1602. if (!person_file) {
  1603. cout << "Создан новый файл!" << endl;
  1604. }
  1605. person_file.close();
  1606. ofstream person_file_out("info.txt", ios_base::app);
  1607. person_file_out.close();
  1608. system("info.txt");
  1609. break;
  1610. }
  1611. case 2:
  1612. {
  1613. ifstream jur_file("jury.txt");
  1614. if (!jur_file) {
  1615. cout << "Создан новый файл!" << endl;
  1616. }
  1617. jur_file.close();
  1618. ofstream jur_file_out("jury.txt", ios_base::app);
  1619. jur_file_out.close();
  1620. system("jury.txt");
  1621. break;
  1622. }
  1623. case 3:
  1624. {
  1625. break;
  1626. }
  1627.  
  1628. }
  1629. break;
  1630. }
  1631.  
  1632. case 2:
  1633. {
  1634. cout << "2. Просмотр всех данных в табличной форме" << endl;
  1635. cout << "1 - Файл с участниками." << endl << "2 - Файл с председателями жюри." << endl << "3 - Файл с рейтингом участника" << endl << "4 - Файл с полной информацией " << endl << "5 - Назад в меню." << endl;
  1636. int flag;
  1637. cout << "Выберите действие :";
  1638. cin >> flag;
  1639. proverka_na_chislo(flag);
  1640. switch (flag) {
  1641. case 1: {
  1642. read_participant();
  1643. system("pause");
  1644. system("cls");
  1645. break;
  1646. }
  1647. case 2: {
  1648. read_jury();
  1649. system("pause");
  1650. system("cls");
  1651. break;
  1652. }
  1653.  
  1654. case 3: read_ocenki();
  1655. system("pause");
  1656. system("cls");
  1657. break;
  1658.  
  1659. case 4: {
  1660. read_full_info();
  1661. system("pause");
  1662. system("cls");
  1663. break;
  1664. }
  1665. case 5: {
  1666. user_menu();
  1667. break;
  1668. }
  1669. default: {
  1670. cout << "Вы неверно выбрали действие, повторите попытку!" << endl;
  1671. cin.clear();
  1672. cin.sync();
  1673. rewind(stdin);
  1674. system("pause");
  1675. break;
  1676. }
  1677. }
  1678. break;
  1679. system("cls");
  1680.  
  1681. }
  1682. case 3: {
  1683. cout << "3. Выполнение задания" << endl;
  1684. zadanie();
  1685. system("pause");
  1686. system("cls");
  1687. break;
  1688. }
  1689. case 4: {
  1690. cout << "4. Поиск и фильтрация данных" << endl;
  1691. cout << "1. Поиск данных" << endl;
  1692. cout << "2. Фильтрация данных" << endl;
  1693. cout << "3. Сортировка данных" << endl;
  1694. cout << "4. Назад" << endl;
  1695. cout << "Выберите действие :";
  1696. int result;
  1697. cin >> result;
  1698. system("cls");
  1699. proverka_na_chislo(result);
  1700. switch (result) {
  1701. case 1: {
  1702. poisk_menu();
  1703. break;
  1704. }
  1705. case 2: {
  1706. filtr_menu();
  1707. break;
  1708. }
  1709. case 3: {
  1710. sort_menu();
  1711. break;
  1712. }
  1713. case 4: {
  1714. break;
  1715. }
  1716. default: {
  1717. cout << "Вы неверно выбрали действие, повторите попытку!" << endl;
  1718. cin.clear();
  1719. cin.sync();
  1720. rewind(stdin);
  1721. system("pause");
  1722. break;
  1723. }
  1724. }
  1725. break;
  1726. }
  1727. case 8:
  1728. {
  1729. return 0;
  1730. }
  1731.  
  1732.  
  1733. }
  1734. }
  1735. }
  1736. }
  1737.  
  1738. void pre_user_menu() {
  1739. int kol;
  1740. do {
  1741. fflush(stdin);
  1742. cout << "1. Авторизация" << endl;
  1743. cout << "2. Регистрация" << endl;
  1744. cout << "3. Выход в меню 1-уровня" << endl;
  1745. cin >> kol;
  1746. proverka_na_chislo(kol);
  1747. system("cls");
  1748. switch (kol) {
  1749. case 1: {
  1750. user_login();
  1751. break;
  1752. }
  1753. case 2: {
  1754. user_registr();
  1755. break;
  1756. }
  1757. }
  1758. } while (kol != 3);
  1759. }
  1760.  
  1761.  
  1762.  
  1763. void sort_menu() {
  1764. int res;
  1765. bool exit = true;
  1766. while (exit) {
  1767. cout << "Меню сортировки информации" << endl;
  1768. cout << "1. Вывести полную информацию" << endl;
  1769. cout << "2. Сортировать по номеру записи" << endl;
  1770. cout << "3. Сортировать по дате" << endl;
  1771. cout << "4. Сортировка по фамилии" << endl;
  1772. cout << "4. Шаг назад" << endl;
  1773. cin >> res;
  1774. proverka_na_chislo(res);
  1775. system("cls");
  1776. switch (res) {
  1777. case 1: {
  1778. read_full_info();
  1779. system("pause");
  1780. system("cls");
  1781. break;
  1782. }
  1783. case 2: {
  1784. sort_full_info_id();
  1785. system("pause");
  1786. system("cls");
  1787. break;
  1788. }
  1789. case 3: {
  1790. sort_full_info_date();
  1791. system("pause");
  1792. system("cls");
  1793. break;
  1794. }case 4: {
  1795. sort_full_info_family();
  1796. system("pause");
  1797. system("cls");
  1798. break;
  1799. }
  1800. case 5: {
  1801. exit = false;
  1802. break;
  1803. }
  1804. default: {
  1805. cout << "Такого пункта меню не существует! Повторите ввод" << endl;
  1806. }
  1807. }
  1808. }
  1809. }
  1810.  
  1811. //язык, красивые таблицы
  1812. //редактирование файла с оценками
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement