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. double clas;
  38. };
  39. class Base {
  40. int a, num, j, b, g;
  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\n" << 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. look();
  62. next();
  63. break;
  64. case '2':
  65. enter();
  66. next();
  67. break;
  68. case '3':
  69. redac();
  70. next();
  71. break;
  72. case '4':
  73. poshyk();
  74. next();
  75. break;
  76. case '5':
  77. sort();
  78. next();
  79. break;
  80. case '6':
  81. delet();
  82. next();
  83. break;
  84. case '7':
  85. exit(1);
  86. break;
  87. default:
  88. cout << "Помилка, повторіть ввід!";
  89. }
  90. }
  91. void next()
  92. {
  93. cout << "Для виходу в головне меню натисніть (1)" << endl;
  94. a = _getch();
  95. switch (b) {
  96. case '1':
  97. menu();
  98. break;
  99. case '2':
  100. exit(1);
  101. }
  102. }
  103.  
  104. void provirka()
  105. {
  106. fstream fil;
  107. fil.open(file, ios::out | ios::in | ios::binary);
  108. if (!file) {
  109. cout << " Файл не знайдений !!!" << endl;
  110. system("pause");
  111. }
  112. fil.close();
  113. }
  114.  
  115. void look()
  116. {
  117. system("cls");
  118. Stud ob;
  119. ifstream in;
  120. in.open(file, ios::in | ios::binary);
  121. if (!in) {
  122. cout << "Помилка";
  123. }
  124. cout << "******************************************************************************************************************************************" << endl;
  125. cout << "|№| Прізвище | Ім'я | По батькові |Матем.|Укр.мова|Укр.літ|Інформ.|Ін.мова|Укр.історія|Географія|Фізика|Біологія|Фіз-ра|Середн.бал|Клас|" << endl;
  126. while (in.read((char*)&ob, sizeof ob))
  127. cout << "|" << ob.number << "|" << setw(10) << ob.prizv << "|" << setw(8) << ob.name << "|"
  128. << setw(13) << ob.batk << "| " << setw(2) << ob.matem << " | " << setw(2) << ob.ukr_mov << " | "
  129. << setw(2) << ob.ukr_lit << " | " << setw(2) << ob.informatic << " | " << setw(2) << ob.in_mov << " | "
  130. << ob.istor_ukr << " | " << setw(2) << ob.geografiy << " | " << setw(2) << ob.fizika << " | " << setw(2)
  131. << ob.biologia << " | " << setw(2) << ob.fizra << " | " << setw(4)
  132. << setw(2) << ob.seredniy_bal << " | " << setprecision(2) << ob.clas << "|" << endl;
  133. cout << "******************************************************************************************************************************************" << endl;
  134. in.close();
  135. }
  136. void enter()
  137. {
  138. Stud ob;
  139. ofstream out;
  140. out.open(file, ios::out | ios::app | ios::binary);
  141. if (!out) {
  142. cout << "Помилка";
  143. }
  144. system("cls");
  145. cout << "Клас: ";
  146. cin >> ob.clas;
  147. cout << "Особистий номер: ";
  148. cin >> ob.number;
  149. eatline();
  150. cout << "Прізвище: ";
  151. cin.getline(ob.prizv, 15);
  152. cout << "Ім'я: ";
  153. cin.getline(ob.name, 15);
  154. cout << "По батькові: ";
  155. cin.getline(ob.batk, 15);
  156. cout << "Математика: ";
  157. cin >> ob.matem;
  158. cout << "Українська мова: ";
  159. cin >> ob.ukr_mov;
  160. cout << "Українська література: ";
  161. cin >> ob.ukr_lit;
  162. cout << "Іноземна мова: ";
  163. cin >> ob.in_mov;
  164. cout << "Інформатика: ";
  165. cin >> ob.informatic;
  166. cout << "Фізика: ";
  167. cin >> ob.fizika;
  168. cout << "Історія України: ";
  169. cin >> ob.istor_ukr;
  170. cout << "Географія: ";
  171. cin >> ob.geografiy;
  172. cout << "Біологія: ";
  173. cin >> ob.biologia;
  174. cout << "Фіз-ра: ";
  175. cin >> ob.fizra;
  176.  
  177. 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;
  178. eatline();
  179. out.write((char*)&ob, sizeof ob);
  180. out.close();
  181. system("pause");
  182. }
  183. void poshyk()
  184. {
  185. system("cls");
  186. int temp;
  187. Stud ob;
  188. fstream poshyk(file, ios::in | ios::binary);
  189. look();
  190. cout << "Пошук по особистому номером:" << endl;
  191. cin >> temp;
  192. eatline();
  193. while (true) {
  194. poshyk.read((char*)&ob, sizeof(Stud));
  195. if (poshyk.eof()) {
  196. cout << "Немає " << temp << endl;
  197. return;
  198. }
  199. if (temp == ob.number) {
  200. cout << "******************************************************************************************************************************************" << endl;
  201. cout << "|№| Прізвище | Ім'я | По батькові |Матем.|Укр.мова|Укр.літ|Інформ.|Ін.мова|Укр.історія|Географія|Фізика|Біологія|Фіз-ра|Середн.бал|Клас|" << endl;
  202. cout << "|" << ob.number << "|" << setw(10) << ob.prizv << "|" << setw(8) << ob.name << "|"
  203. << setw(13) << ob.batk << "| " << setw(2) << ob.matem << " | " << setw(2) << ob.ukr_mov << " | "
  204. << setw(2) << ob.ukr_lit << " | " << setw(2) << ob.informatic << " | " << setw(2) << ob.in_mov << " | "
  205. << ob.istor_ukr << " | " << setw(2) << ob.geografiy << " | " << setw(2) << ob.fizika << " | " << setw(2)
  206. << ob.biologia << " | " << setw(2) << ob.fizra << " | " << setw(4)
  207. << setw(2) << ob.seredniy_bal << " | " << setprecision(2) << ob.clas << "|" << endl;
  208. cout << "******************************************************************************************************************************************" << endl;
  209. return;
  210. }
  211. }
  212. }
  213. void sort()
  214. {
  215. system("cls");
  216. fstream sort;
  217. sort.open(file, ios::in | ios::binary);
  218. Stud ob[1000];
  219. Stud tem;
  220. int count = 0;
  221.  
  222. while (!sort.eof()) {
  223. sort.read((char*)&ob[count], sizeof(Stud));
  224. count++;
  225. }
  226. count--;
  227. cout << "Сортування по:\n1 - Особистому номеру\n2 - По прізвищу\nЗ - Середньому балу\n4 - Групі" << endl;
  228. int a;
  229. cin >> a;
  230. eatline();
  231. if (a == 1) {
  232. for (int i = 0; i < count; i++)
  233. for (int j = 0; j < count; j++) {
  234. if (ob[i].number < ob[j].number) {
  235. tem = ob[i];
  236. ob[i] = ob[j];
  237. ob[j] = tem;
  238. }
  239. }
  240. if (a == 2)
  241. for (int i = 0; i < count; i++)
  242. for (int j = 0; j < count; j++)
  243.  
  244. if (ob[i].prizv[0] < ob[j].prizv[0]) {
  245. tem = ob[i];
  246. ob[i] = ob[j];
  247. ob[j] = tem;
  248. }
  249. }
  250.  
  251. if (a == 3)
  252. for (int i = 0; i < count; i++)
  253. for (int j = 0; j < count; j++)
  254.  
  255. if (ob[i].seredniy_bal < ob[j].seredniy_bal) {
  256. tem = ob[i];
  257. ob[i] = ob[j];
  258. ob[j] = tem;
  259. }
  260.  
  261. if (a == 4)
  262. for (int i = 0; i < count; i++)
  263. for (int j = 0; j < count; j++)
  264. if (ob[i].clas < ob[j].clas) {
  265. tem = ob[i];
  266. ob[i] = ob[j];
  267. ob[j] = tem;
  268. }
  269.  
  270. sort.close();
  271. sort.clear();
  272. sort.open(file, ios::out | ios::binary);
  273. for (a = 0; a < count; a++)
  274. sort.write((char*)&ob[a], sizeof(Stud));
  275. sort.close();
  276. cout << "Успішно!" << endl;
  277. }
  278. //////////////////////////////////////////////////
  279. void redac()
  280.  
  281. {
  282. system("cls");
  283. int t = 0;
  284. Stud ob[1000];
  285. fstream del;
  286. del.open(file, ios::in | ios::out | ios::binary);
  287. if (!del.is_open()) {
  288. cout << "Помилка!!!" << endl;
  289. exit(1);
  290. }
  291. int count = 0;
  292. while (!del.eof()) {
  293. del.read((char*)&ob[count], sizeof(Stud));
  294. count++;
  295. }
  296. look();
  297. count--;
  298. cout << "Введіть особистий номер учня для редагування: ";
  299. double number;
  300. cin >> number;
  301. del.close();
  302. del.clear();
  303. del.open(file, ios::out | ios::binary);
  304. for (int x = 0; x < count; x++)
  305. if (ob[x].number != number)
  306. del.write((char*)&ob[x], sizeof(Stud));
  307. enter();
  308. del.close();
  309. cout << "Успішно!" << endl;
  310. }
  311.  
  312. void delet()
  313. {
  314. system("cls");
  315. int t = 0;
  316. Stud ob[1000];
  317. fstream del;
  318. del.open(file, ios::in | ios::out | ios::binary);
  319. if (!del.is_open()) {
  320. cout << "Помилка!!!" << endl;
  321. exit(1);
  322. }
  323. int count = 0;
  324. while (!del.eof()) {
  325. del.read((char*)&ob[count], sizeof(Stud));
  326. count++;
  327. }
  328. look();
  329. count--;
  330. cout << "Введіть особистий номер учня каторого треба видалити: ";
  331. double number;
  332. cin >> number;
  333. del.close();
  334. del.clear();
  335. del.open(file, ios::out | ios::binary);
  336. for (int x = 0; x < count; x++)
  337. if (ob[x].number != number)
  338. del.write((char*)&ob[x], sizeof(Stud));
  339. del.close();
  340. cout << "Успішно!" << endl;
  341. }
  342. };
  343. int main()
  344. {
  345. system("chcp 65001 > nul");
  346. Base ob;
  347. ob.provirka();
  348. while (1) {
  349. ob.menu();
  350. }
  351. return 0;
  352. }
  353.  
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