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 fam[15];
  24. char name[15];
  25. char otchestvo[15];
  26. double istor_bel;
  27. double informatic;
  28. double fizika;
  29. double matem;
  30. double bel_yz;
  31. double bel_lit;
  32. double rus_yz;
  33. double rus_lit;
  34. double chog;
  35. double in_yz;
  36. double fizra;
  37. double biologia;
  38. double geografiy;
  39. double sredni_ball;
  40. };
  41. class Base {
  42. int a, num, j, b, g;
  43.  
  44. public:
  45. Stud ob;
  46. void menu()
  47. {
  48. system("cls");
  49. cout << r(" Контроль успеваемости учащихся СШ№ 3\n") << endl;
  50. cout << r(" 1.Просмотр") << endl;
  51. cout << r(" 2.Ввод") << endl;
  52. cout << r(" 3.Редактирование") << endl;
  53. cout << r(" 4.Поиск") << endl;
  54. cout << r(" 5.Сортировка") << endl;
  55. cout << r(" 6.Удаление") << endl;
  56. cout << r(" 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. poisk();
  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 << r("Ошибка повторите ввод!!!");
  89. }
  90. }
  91. void next()
  92. {
  93. cout << r("Для выхода в главное меню нажмите (1) для выхода (2)") << 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 proverka()
  105. {
  106. fstream fil;
  107. fil.open(file, ios::out | ios::in | ios::binary);
  108. if (!file) {
  109. cout << r(" Файл не найден !!!") << 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 << r("Ошибка");
  123. }
  124. cout << "********************************************************************************" << endl;
  125. while (in.read((char*)&ob, sizeof ob))
  126. cout << "|" << setw(2) << ob.number << "|" << setw(10) << ob.fam << "|" << setw(8) << ob.name << "|"
  127. << setw(13) << ob.otchestvo << "|" << setw(2) << ob.matem << "|" << setw(2) << ob.bel_yz << "|"
  128. << setw(2) << ob.bel_lit << "|" << setw(2) << ob.rus_yz << "|" << setw(2) << ob.rus_lit << "|"
  129. << setw(2) << ob.informatic << "|" << setw(2) << ob.in_yz << "|" << setw(2) << ob.chog << "|"
  130. << ob.istor_bel << "|" << setw(2) << ob.geografiy << "|" << setw(2) << ob.fizika << "|" << setw(2)
  131. << ob.biologia << "|" << setw(2) << ob.fizra << "|" << setw(4)
  132. << setprecision(2) << ob.sredni_ball << "|" << 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 << r("Ошибка");
  143. }
  144. system("cls");
  145. cout << r("Личный номер:");
  146. cin >> ob.number;
  147. eatline();
  148. cout << r("Фамилия:");
  149. cin.getline(ob.fam, 15);
  150. cout << r("Имя:");
  151. cin.getline(ob.name, 15);
  152. cout << r("Отчество:");
  153. cin.getline(ob.otchestvo, 15);
  154.  
  155. cout << r("Математика:");
  156. cin >> ob.matem;
  157.  
  158. cout << r("Белорусский язык:");
  159. cin >> ob.bel_yz;
  160. cout << r("Белорусская литература:");
  161. cin >> ob.bel_lit;
  162. cout << r("Русский язык:");
  163. cin >> ob.rus_yz;
  164. cout << r("Русская литература:");
  165. cin >> ob.rus_lit;
  166. cout << r("Иностранный язык:");
  167. cin >> ob.in_yz;
  168. cout << r("Информатика:");
  169. cin >> ob.informatic;
  170. cout << r("Физика:");
  171. cin >> ob.fizika;
  172. cout << r("Истрория Беларуси:");
  173. cin >> ob.istor_bel;
  174. cout << r("Ч.О.Г:");
  175. cin >> ob.chog;
  176. cout << r("География:");
  177. cin >> ob.geografiy;
  178. cout << r("Биология:");
  179. cin >> ob.biologia;
  180. cout << r("Ф-ра:");
  181. cin >> ob.fizra;
  182.  
  183. ob.sredni_ball = (ob.matem + ob.bel_yz + ob.informatic + ob.bel_lit + ob.in_yz + ob.rus_yz + ob.rus_lit + ob.biologia + ob.istor_bel + ob.chog + ob.fizika + ob.fizra + ob.geografiy) / 13;
  184. eatline();
  185. out.write((char*)&ob, sizeof ob);
  186. out.close();
  187. system("pause");
  188. }
  189. void poisk()
  190. {
  191. system("cls");
  192. int temp;
  193. Stud ob;
  194. fstream poisk(file, ios::in | ios::binary);
  195. look();
  196. cout << r("Поиск по личному номеру:") << endl;
  197. cin >> temp;
  198. eatline();
  199. while (true) {
  200. poisk.read((char*)&ob, sizeof(Stud));
  201. if (poisk.eof()) {
  202. cout << "net " << temp << endl;
  203. return;
  204. }
  205. if (temp == ob.number) {
  206. cout << "*****************************************************************************" << endl;
  207.  
  208. cout << "|" << setw(2) << ob.number << "|" << setw(10) << ob.fam << "|" << setw(8) << ob.name << "|"
  209. << setw(13) << ob.otchestvo << "|" << setw(2) << ob.matem << "|" << setw(2) << ob.bel_yz << "|"
  210. << setw(2) << ob.bel_lit << "|" << setw(2) << ob.rus_yz << "|" << setw(2) << ob.rus_lit << "|"
  211. << setw(2) << ob.informatic << "|" << setw(2) << ob.in_yz << "|" << setw(2) << ob.chog << "|"
  212. << ob.istor_bel << "|" << setw(2) << ob.geografiy << "|" << setw(2) << ob.fizika << "|" << setw(2)
  213. << ob.biologia << "|" << setw(2) << ob.fizra << "|" << setw(4)
  214. << setprecision(2) << ob.sredni_ball << "|" << endl;
  215. cout << "*****************************************************************************" << endl;
  216. return;
  217. }
  218. }
  219. }
  220. void sort()
  221. {
  222. system("cls");
  223. fstream sort;
  224. sort.open(file, ios::in | ios::binary);
  225. Stud ob[1000];
  226. Stud tem;
  227. int count = 0;
  228.  
  229. while (!sort.eof()) {
  230. sort.read((char*)&ob[count], sizeof(Stud));
  231. count++;
  232. }
  233. count--;
  234. cout << r("Сортировка по:\n1 -Личному номеру\n2 - По фамилие\nЗ - Среднему баллу: ");
  235. int a;
  236. cin >> a;
  237. eatline();
  238. if (a == 1) {
  239. for (int i = 0; i < count; i++)
  240. for (int j = 0; j < count; j++) {
  241. if (ob[i].number < ob[j].number) {
  242. tem = ob[i];
  243. ob[i] = ob[j];
  244. ob[j] = tem;
  245. }
  246. }
  247. if (a == 2)
  248. for (int i = 0; i < count; i++)
  249. for (int j = 0; j < count; j++)
  250.  
  251. if (ob[i].fam[0] < ob[j].fam[0]) {
  252. tem = ob[i];
  253. ob[i] = ob[j];
  254. ob[j] = tem;
  255. }
  256. }
  257.  
  258. else if (a == 3)
  259. for (int i = 0; i < count; i++)
  260. for (int j = 0; j < count; j++)
  261. if (ob[i].sredni_ball < ob[j].sredni_ball) {
  262. tem = ob[i];
  263. ob[i] = ob[j];
  264. ob[j] = tem;
  265. }
  266. sort.close();
  267. sort.clear();
  268. sort.open(file, ios::out | ios::binary);
  269. for (a = 0; a < count; a++)
  270. sort.write((char*)&ob[a], sizeof(Stud));
  271. sort.close();
  272. }
  273. //////////////////////////////////////////////////
  274. void redac()
  275.  
  276. {
  277. system("cls");
  278. int t = 0;
  279. Stud ob[1000];
  280. fstream del;
  281. del.open(file, ios::in | ios::out | ios::binary);
  282. if (!del.is_open()) {
  283. cout << r("Ошибка!!!") << endl;
  284. exit(1);
  285. }
  286. int count = 0;
  287. while (!del.eof()) {
  288. del.read((char*)&ob[count], sizeof(Stud));
  289. count++;
  290. }
  291. look();
  292. count--;
  293. cout << r("Введите личный номер ученика для редактирования: ");
  294. double number;
  295. cin >> number;
  296. del.close();
  297. del.clear();
  298. del.open(file, ios::out | ios::binary);
  299. for (int x = 0; x < count; x++)
  300. if (ob[x].number != number)
  301. del.write((char*)&ob[x], sizeof(Stud));
  302. enter();
  303. del.close();
  304. }
  305.  
  306. void delet()
  307. {
  308. system("cls");
  309. int t = 0;
  310. Stud ob[1000];
  311. fstream del;
  312. del.open(file, ios::in | ios::out | ios::binary);
  313. if (!del.is_open()) {
  314. cout << r("Ошибка!!!") << endl;
  315. exit(1);
  316. }
  317. int count = 0;
  318. while (!del.eof()) {
  319. del.read((char*)&ob[count], sizeof(Stud));
  320. count++;
  321. }
  322. look();
  323. count--;
  324. cout << r("Введите личный номер ученика каторого надо удалить: ");
  325. double number;
  326. cin >> number;
  327. del.close();
  328. del.clear();
  329. del.open(file, ios::out | ios::binary);
  330. for (int x = 0; x < count; x++)
  331. if (ob[x].number != number)
  332. del.write((char*)&ob[x], sizeof(Stud));
  333. del.close();
  334. }
  335. };
  336. int main()
  337. {
  338. Base ob;
  339. ob.proverka();
  340. while (1) {
  341. ob.menu();
  342. }
  343. return 0;
  344. }
  345.  
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