Advertisement
Guest User

Untitled

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