fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <windows.h>
  4. #include <cstdlib>
  5. #include <iomanip>
  6. #include <conio.h>
  7. using namespace std;
  8. const char* file = "jurnal";
  9. char* r(char* buf);
  10. char a[256];
  11. char* r(char* b)
  12. {
  13. CharToOem(b, a);
  14. return a;
  15. }
  16. inline void eatline()
  17. {
  18. while (cin.get() != '\n')
  19. continue;
  20. }
  21. struct Stud {
  22. int number;
  23. char prizv[15];
  24. char name[15];
  25. char batk[15];
  26. double istor_ukr;
  27. double informatic;
  28. double fizika;
  29. double matem;
  30. double ukr_mov;
  31. double ukr_lit;
  32. double in_mov;
  33. double fizra;
  34. double biologia;
  35. double geografiy;
  36. double seredniy_bal;
  37. char clas[15];
  38. };
  39. class Base {
  40. int a, num, j, b, g, c, d;
  41.  
  42. public:
  43. Stud ob;
  44. void menu()
  45. {
  46. system("cls");
  47. cout << "**********************************************************************************************************************************************" << endl;
  48. cout << "\n\t\t\t\t\t\tКонтроль успішності учнів ліцею №11\t\t\t\t\t\t" << endl << endl;
  49. cout << "**********************************************************************************************************************************************" << endl;
  50. cout << "\n\t\t\t\t\t\t\t 1. Перегляд" << endl;
  51. cout << "\t\t\t\t\t\t\t 2. Ввід" << endl;
  52. cout << "\t\t\t\t\t\t\t 3. Редагування" << endl;
  53. cout << "\t\t\t\t\t\t\t 4. Пошук" << endl;
  54. cout << "\t\t\t\t\t\t\t 5. Сортування" << endl;
  55. cout << "\t\t\t\t\t\t\t 6. Видалення" << endl;
  56. cout << "\t\t\t\t\t\t\t 7. Вихід" << endl;
  57.  
  58. a = _getch();
  59. switch (a) {
  60. case '1':
  61. view();
  62. //look();
  63. next();
  64. break;
  65. case '2':
  66. enter();
  67. next();
  68. break;
  69. case '3':
  70. redac();
  71. next();
  72. break;
  73. case '4':
  74. poshyk();
  75. next();
  76. break;
  77. case '5':
  78. sort();
  79. next();
  80. break;
  81. case '6':
  82. delet();
  83. next();
  84. break;
  85. case '7':
  86. exit(1);
  87. break;
  88. default:
  89. cout << "Помилка, повторіть ввід!";
  90. }
  91. }
  92. void next()
  93. {
  94. cout << "Для виходу в головне меню натисніть (1)" << endl;
  95. a = _getch();
  96. switch (b) {
  97. case '1':
  98. menu();
  99. break;
  100. case '2':
  101. exit(1);
  102. }
  103. }
  104.  
  105. void que()
  106. {
  107. cout << "Для виходу в головне меню натисніть (1), в перегляд (2)" << endl;
  108. d = _getch();
  109. switch (d) {
  110. case '1':
  111. menu();
  112. break;
  113. case '2':
  114. view();
  115. break;
  116. }
  117. }
  118.  
  119. void provirka()
  120. {
  121. fstream fil;
  122. fil.open(file, ios::out | ios::in | ios::binary);
  123. if (!file) {
  124. cout << " Файл не знайдений !!!" << endl;
  125. system("pause");
  126. }
  127. fil.close();
  128. }
  129.  
  130. void look()
  131. {
  132. system("cls");
  133. Stud ob;
  134. ifstream in;
  135. in.open(file, ios::in | ios::binary);
  136. if (!in) {
  137. cout << "Помилка" << endl;
  138. }
  139. cout << "**********************************************************************************************************************************************";
  140. cout << "\n\t\t\t\t\t\t\t\tВсі учні школи" << endl;
  141. cout << "**********************************************************************************************************************************************" << endl;
  142. cout << "|Номер|Клас| Прізвище | Ім'я | По батькові |Укр.мова|Матем.|Укр.літ|Інформ.|Ін.мова|Укр.історія|Географія|Фізика|Біологія|Фіз-ра|Середн.бал|" << endl;
  143. while (in.read((char*)&ob, sizeof ob))
  144. cout << "|" << setw(4) << ob.number << " |" << setw(4) << ob.clas << "|" << setw(10) << ob.prizv << "|" << setw(8) << ob.name << "|"
  145. << setw(13) << ob.batk << "| " << setw(2) << ob.ukr_mov << " | " << setw(2) << ob.matem << " | "
  146. << setw(2) << ob.in_mov << " | " << setw(2) << ob.fizra << " | " << setw(2) << ob.ukr_lit << " | "
  147. << setw(2) << ob.istor_ukr << " | " << setw(2) << ob.geografiy << " | " << setw(2) << ob.fizika << " | "
  148. << setw(2) << ob.biologia << " | " << setw(2) << ob.informatic << " | " << setw(4)
  149. << setprecision(2) << ob.seredniy_bal << " |" << endl;
  150. cout << "**********************************************************************************************************************************************" << endl;
  151. in.close();
  152. }
  153. void enter()
  154. {
  155. Stud ob;
  156. ofstream out;
  157. out.open(file, ios::out | ios::app | ios::binary);
  158. if (!out) {
  159. cout << "Помилка";
  160. }
  161. system("cls");
  162. detail();
  163. cout << "Клас: ";
  164. cin >> ob.clas;
  165. cout << "Особистий номер: ";
  166. cin >> ob.number;
  167. eatline();
  168. cout << "Прізвище: ";
  169. cin.getline(ob.prizv, 15);
  170. cout << "Ім'я: ";
  171. cin.getline(ob.name, 15);
  172. cout << "По батькові: ";
  173. cin.getline(ob.batk, 15);
  174. if (ob.number < 499) {
  175. cout << "Українська мова: ";
  176. cin >> ob.ukr_mov;
  177. cout << "Математика: ";
  178. cin >> ob.matem;
  179. cout << "Іноземна мова: ";
  180. cin >> ob.in_mov;
  181. cout << "Фіз-ра: ";
  182. cin >> ob.fizra;
  183. ob.ukr_lit = '\0';
  184. ob.informatic = '\0';
  185. ob.fizika = '\0';
  186. ob.istor_ukr = '\0';
  187. ob.geografiy = '\0';
  188. ob.biologia = '\0';
  189. ob.seredniy_bal = (ob.matem + ob.ukr_mov + ob.in_mov + ob.fizra) / 4;
  190. } else {
  191. cout << "Українська мова: ";
  192. cin >> ob.ukr_mov;
  193. cout << "Математика: ";
  194. cin >> ob.matem;
  195. cout << "Українська література: ";
  196. cin >> ob.ukr_lit;
  197. cout << "Іноземна мова: ";
  198. cin >> ob.in_mov;
  199. cout << "Інформатика: ";
  200. cin >> ob.informatic;
  201. cout << "Фізика: ";
  202. cin >> ob.fizika;
  203. cout << "Історія України: ";
  204. cin >> ob.istor_ukr;
  205. cout << "Географія: ";
  206. cin >> ob.geografiy;
  207. cout << "Біологія: ";
  208. cin >> ob.biologia;
  209. cout << "Фіз-ра: ";
  210. cin >> ob.fizra;
  211.  
  212. ob.seredniy_bal = (ob.matem + ob.ukr_mov + ob.informatic + ob.ukr_lit + ob.in_mov + ob.biologia + ob.istor_ukr + ob.fizika + ob.fizra + ob.geografiy) / 10;
  213. }
  214. eatline();
  215. out.write((char*)&ob, sizeof ob);
  216. out.close();
  217. system("pause");
  218. }
  219. void poshyk()
  220. {
  221. system("cls");
  222. int temp;
  223. Stud ob;
  224. fstream poshyk(file, ios::in | ios::binary);
  225. look();
  226. detail();
  227. cout << "Пошук по особистому номером:" << endl;
  228. cin >> temp;
  229. eatline();
  230. while (true) {
  231. poshyk.read((char*)&ob, sizeof(Stud));
  232. if (poshyk.eof()) {
  233. cout << "Немає " << temp << endl;
  234. return;
  235. }
  236. if (temp == ob.number) {
  237. if (ob.number < 499) {
  238. cout << "**************************************************************************************" << endl;
  239. cout << "| № |Клас| Прізвище | Ім'я | По батькові |Укр.мова|Матем.|Ін.мова|Фіз-ра|Середн.бал|" << endl;
  240. cout << "|" << setw(3) << ob.number << "|" << setw(4) << ob.clas << "|" << setw(10) << ob.prizv << "|" << setw(8) << ob.name << "|"
  241. << setw(13) << ob.batk << "| " << setw(2) << ob.ukr_mov << " | " << setw(2) << ob.matem << " | "
  242. << setw(2) << ob.in_mov << " | " << setw(2) << ob.fizra << " | "
  243. << setprecision(10) << ob.seredniy_bal << " |" << endl;
  244. cout << "**************************************************************************************" << endl;
  245. return;
  246. } else {
  247. cout << "**********************************************************************************************************************************************" << endl;
  248. cout << "|Номер|Клас| Прізвище | Ім'я | По батькові |Укр.мова|Матем.|Укр.літ|Інформ.|Ін.мова|Укр.історія|Географія|Фізика|Біологія|Фіз-ра|Середн.бал|" << endl;
  249. cout << "|" << setw(4) << ob.number << " |" << setw(4) << ob.clas << "|" << setw(10) << ob.prizv << "|" << setw(8) << ob.name << "|"
  250. << setw(13) << ob.batk << "| " << setw(2) << ob.ukr_mov << " | " << setw(2) << ob.matem << " | "
  251. << setw(2) << ob.in_mov << " | " << setw(2) << ob.fizra << " | " << setw(2) << ob.ukr_lit << " | "
  252. << setw(2) << ob.istor_ukr << " | " << setw(2) << ob.geografiy << " | " << setw(2) << ob.fizika << " | "
  253. << setw(2) << ob.biologia << " | " << setw(2) << ob.informatic << " | " << setw(4)
  254. << setprecision(2) << ob.seredniy_bal << " |" << endl;
  255. cout << "**********************************************************************************************************************************************" << endl;
  256. return;
  257. }
  258. }
  259. }
  260. }
  261. void sort()
  262. {
  263. system("cls");
  264. fstream sort;
  265. sort.open(file, ios::in | ios::binary);
  266. Stud ob[1000];
  267. Stud tem;
  268. int count = 0;
  269.  
  270. while (!sort.eof()) {
  271. sort.read((char*)&ob[count], sizeof(Stud));
  272. count++;
  273. }
  274. count--;
  275. cout << "Сортування по:\n1 - Особистому номеру\n2 - По прізвищу\nЗ - Середньому балу\n4 - Класу" << endl;
  276. int a;
  277. cin >> a;
  278. eatline();
  279. if (a == 1) {
  280. for (int i = 0; i < count; i++)
  281. for (int j = 0; j < count; j++) {
  282. if (ob[i].number < ob[j].number) {
  283. tem = ob[i];
  284. ob[i] = ob[j];
  285. ob[j] = tem;
  286. }
  287. }
  288. if (a == 2)
  289. for (int i = 0; i < count; i++)
  290. for (int j = 0; j < count; j++)
  291.  
  292. if (ob[i].prizv[0] < ob[j].prizv[0]) {
  293. tem = ob[i];
  294. ob[i] = ob[j];
  295. ob[j] = tem;
  296. }
  297. }
  298.  
  299. if (a == 3)
  300. for (int i = 0; i < count; i++)
  301. for (int j = 0; j < count; j++)
  302.  
  303. if (ob[i].seredniy_bal < ob[j].seredniy_bal) {
  304. tem = ob[i];
  305. ob[i] = ob[j];
  306. ob[j] = tem;
  307. }
  308.  
  309. if (a == 4)
  310. for (int i = 0; i < count; i++)
  311. for (int j = 0; j < count; j++)
  312. if (ob[i].clas[0] < ob[j].clas[0]) {
  313. tem = ob[i];
  314. ob[i] = ob[j];
  315. ob[j] = tem;
  316. }
  317.  
  318. sort.close();
  319. sort.clear();
  320. sort.open(file, ios::out | ios::binary);
  321. for (a = 0; a < count; a++)
  322. sort.write((char*)&ob[a], sizeof(Stud));
  323. cout << "Успішно!" << endl;
  324. sort.close();
  325.  
  326. }
  327. //////////////////////////////////////////////////
  328. void redac()
  329.  
  330. {
  331. system("cls");
  332. Stud ob[1000];
  333. fstream del;
  334. del.open(file, ios::in | ios::out | ios::binary);
  335. if (!del.is_open()) {
  336. cout << "Помилка!" << endl;
  337. exit(1);
  338. }
  339. int count = 0;
  340. while (!del.eof()) {
  341. del.read((char*)&ob[count], sizeof(Stud));
  342. count++;
  343. }
  344. look();
  345. count--;
  346. cout << "Введіть особистий номер учня для редагування: ";
  347. double number;
  348. cin >> number;
  349. del.close();
  350. del.clear();
  351. del.open(file, ios::out | ios::binary);
  352. for (int x = 0; x < count; x++)
  353. if (ob[x].number != number)
  354. del.write((char*)&ob[x], sizeof(Stud));
  355. enter();
  356. cout << "Успішно!" << endl;
  357. del.close();
  358. }
  359.  
  360. void delet()
  361. {
  362. system("cls");
  363. Stud ob[1000];
  364. fstream del;
  365. del.open(file, ios::in | ios::out | ios::binary);
  366. if (!del.is_open()) {
  367. cout << "Помилка!" << endl;
  368. exit(1);
  369. }
  370. int count = 0;
  371. while (!del.eof()) {
  372. del.read((char*)&ob[count], sizeof(Stud));
  373. count++;
  374. }
  375. look();
  376. count--;
  377. cout << "Введіть особистий номер учня каторого треба видалити: ";
  378. double number;
  379. cin >> number;
  380. del.close();
  381. del.clear();
  382. del.open(file, ios::out | ios::binary);
  383. for (int x = 0; x < count; x++)
  384. if (ob[x].number != number)
  385. del.write((char*)&ob[x], sizeof(Stud));
  386. cout << "Успішно!" << endl;
  387. del.close();
  388. }
  389. void detail()
  390. {
  391. cout << "**************************************" << endl;
  392. cout << "| Для особистого номеру |"<< endl;
  393. cout << "|____________________________________|"<< endl;
  394. cout << "| Клас | А | Б | В |" << endl;
  395. cout << "| 1 | 101-130 | 131-160 | 161-190 |" << endl;
  396. cout << "| 2 | 201-230 | 231-260 | 261-290 |" << endl;
  397. cout << "| 3 | 301-330 | 331-360 | 361-390 |" << endl;
  398. cout << "| 4 | 401-430 | 431-460 | 461-490 |" << endl;
  399. cout << "| 5 | 501-530 | 531-560 | 561-590 |" << endl;
  400. cout << "| 6 | 601-630 | 631-660 | 661-690 |" << endl;
  401. cout << "| 7 | 701-730 | 731-760 | 761-790 |" << endl;
  402. cout << "| 8 | 801-830 | 831-860 | 861-890 |" << endl;
  403. cout << "| 9 | 901-830 | 931-960 | 961-990 |" << endl;
  404. cout << "| 10 |1001-1030|1031-1060|1061-1090|" << endl;
  405. cout << "| 11 |1101-1130|1131-1160|1161-1190|" << endl;
  406. cout << "**************************************" << endl;
  407.  
  408. }
  409.  
  410. void view()
  411. {
  412. system("cls");
  413. cout << "Перегляд:\n1 - 1-4 класи\n2 - 5-11 класи\nЗ - Всіх" << endl;
  414. c = _getch();
  415. switch (c) {
  416. case '1':
  417. look_l();
  418. que();
  419. break;
  420. case '2':
  421. look_b();
  422. que();
  423. break;
  424. case '3':
  425. look();
  426. que();
  427. break;
  428.  
  429. }
  430. }
  431.  
  432. void look_l()
  433. {
  434. system("cls");
  435. Stud ob;
  436. ifstream in;
  437. in.open(file, ios::in | ios::binary);
  438. if (!in) {
  439. cout << "Помилка" << endl;
  440. }
  441.  
  442. cout << "**************************************************************************************";
  443. cout << "\n\t\t\t\t\tПочаткові класи" << endl;
  444. cout << "**************************************************************************************" << endl;
  445. cout << "| № |Клас| Прізвище | Ім'я | По батькові |Укр.мова|Матем.|Ін.мова|Фіз-ра|Середн.бал|" << endl;
  446. while (in.read((char*)&ob, sizeof ob))
  447. if (ob.number < 499){
  448. cout << "|" << setw(3) << ob.number << "|" << setw(4) << ob.clas << "|" << setw(10) << ob.prizv << "|" << setw(8) << ob.name << "|"
  449. << setw(13) << ob.batk << "| " << setw(2) << ob.ukr_mov << " | " << setw(2) << ob.matem << " | "
  450. << setw(2) << ob.in_mov << " | " << setw(2) << ob.fizra << " | "
  451. << setw(2) << ob.seredniy_bal << " |" << endl;
  452.  
  453. }
  454.  
  455. cout << "**************************************************************************************" << endl;
  456.  
  457. in.close();
  458. }
  459.  
  460. void look_b()
  461. {
  462. system("cls");
  463. Stud ob;
  464. ifstream in;
  465. in.open(file, ios::in | ios::binary);
  466. if (!in) {
  467. cout << "Помилка" << endl;
  468. }
  469.  
  470. cout << "**********************************************************************************************************************************************";
  471. cout << "\n\t\t\t\t\t\t\t\tСтарші класи" << endl;
  472. cout << "**********************************************************************************************************************************************" << endl;
  473. cout << "|Номер|Клас| Прізвище | Ім'я | По батькові |Укр.мова|Матем.|Укр.літ|Інформ.|Ін.мова|Укр.історія|Географія|Фізика|Біологія|Фіз-ра|Середн.бал|" << endl;
  474. while (in.read((char*)&ob, sizeof ob))
  475. if (ob.number > 500){
  476. cout << "|" << setw(3) << ob.number << " |" << setw(4) << ob.clas << "|" << setw(10) << ob.prizv << "|" << setw(8) << ob.name << "|"
  477. << setw(13) << ob.batk << "| " << setw(2) << ob.ukr_mov << " | " << setw(2) << ob.matem << " | "
  478. << setw(2) << ob.ukr_lit << " | " << setw(2) << ob.informatic << " | " << setw(2) << ob.in_mov << " | "
  479. << ob.istor_ukr << " | " << setw(2) << ob.geografiy << " | " << setw(2) << ob.fizika << " | " << setw(2)
  480. << ob.biologia << " | " << setw(2) << ob.fizra << " | " << setw(4)
  481. << setw(2) << ob.seredniy_bal << " |" << endl;
  482.  
  483. }
  484. cout << "**********************************************************************************************************************************************" << endl;
  485. in.close();
  486. }
  487. };
  488.  
  489.  
  490. int main()
  491. {
  492. SetConsoleCP(1251);
  493. SetConsoleOutputCP(1251);
  494. Base ob;
  495. ob.provirka();
  496. while (1) {
  497. ob.menu();
  498. }
  499. return 0;
  500. }
  501.  
  502.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:10: fatal error: windows.h: No such file or directory
 #include <windows.h>
          ^~~~~~~~~~~
compilation terminated.
stdout
Standard output is empty