Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <stdlib.h>
  6. #include <fstream>
  7. using namespace std;
  8. struct birthday
  9. {
  10. int day;
  11. int month;
  12. int year;
  13. };
  14. struct STUDENTS
  15. {
  16. char surname[20];
  17. char name[20];
  18. char familiya[20];
  19. birthday born;
  20. int mark;
  21. int num;
  22. };
  23.  
  24. void sort(STUDENTS* student, int fcount)
  25. {
  26. for (int i = 0; i < fcount - 1; i++)
  27. for (int j = i + 1; j < fcount; j++)
  28. if (strcmp(student[i].surname, student[j].surname) > 0)
  29. {
  30. STUDENTS t = student[i];
  31. student[i] = student[j];
  32. student[j] = t;
  33. }
  34. }
  35. int main()
  36. {
  37. FILE* fstud;
  38. fstud = fopen("D://students.bin", "ab");
  39.  
  40. fclose(fstud);
  41. int N;
  42. int count = 0;
  43. cout << "How many students in the group?\n";
  44. cin >> N;
  45. STUDENTS* student = new STUDENTS[N];
  46. STUDENTS* fmass = new STUDENTS[N];
  47. int fcount = 0;
  48. int q;
  49. int low_count = 0;
  50. int mid_count = 0;
  51. int high_count = 0;
  52. question:
  53. cout << "\nВыберите пункт меню: "<< endl;
  54. cout << "1.Добавить студента. " << endl;
  55. cout << "2.Показать всех студентов. " << endl;
  56. cout << "3.Поиск студента по: " << endl;
  57. cout << "4.Удалить студента по номеру " << endl;
  58. cout << "5.По оценкам " << endl;
  59. cin >> q;
  60. switch (q)
  61. {
  62. case 1:
  63. if (count == N)
  64. N++;
  65. cout << "Enter name: ";
  66. cin >> student[count].name;
  67. cout << "Enter surname: ";
  68. cin >> student[count].surname;
  69. cout << "Enter patronymic: ";
  70. cin >> student[count].familiya;
  71. cout << "Enter date of birth(day/space/month/space/year): ";
  72. cin >> student[count].born.day;
  73. cin >> student[count].born.month;
  74. cin >> student[count].born.year;
  75. cout << "Enter avarage mark from 0 to 100: ";
  76. cin >> student[count].mark;
  77. student[count].num = count + 1;
  78. fopen("students.bin", "ab");
  79. fwrite(&student[count], sizeof(STUDENTS), 1, fstud);
  80. fclose(fstud);
  81. count++;
  82.  
  83. goto question;
  84. case 2:
  85. fopen("students.bin", "rb");
  86. for (int i = 0; i < count; i++)
  87. fread(&fmass[i], sizeof(STUDENTS), 1, fstud);
  88. sort(fmass, count);
  89. for (int i = 0; i < count; i++)
  90. {
  91. student[i].num = i + 1;
  92. fmass[i].num = i + 1;
  93. cout << fmass[i].num << " " << fmass[i].surname << " " << fmass[i].name << " " << fmass[i].familiya << " " << fmass[i].born.day << "." << fmass[i].born.month << "." << fmass[i].born.year << " " << fmass[i].mark;
  94. cout << "\n";
  95. }
  96. fclose(fstud);
  97. goto question;
  98. case 3:
  99. sort(fmass, count);
  100. fopen("students.bin", "rb");
  101. cout << "1.By surname\n";
  102. cout << "2.By marks\n";
  103. cout << "3.By date of birth\n";
  104. cin >> q;
  105. switch (q)
  106. {
  107. case 1:
  108. cout << "Enter surname: ";
  109. char sur[20];
  110. cin >> sur;
  111. for (int i = 0; i < count; i++)
  112. {
  113. fread(&fmass[i], sizeof(STUDENTS), 1, fstud);
  114. if (!strcmp(sur, fmass[i].surname))
  115. {
  116. cout << fmass[i].num << " " << fmass[i].surname << " " << fmass[i].name << " " << fmass[i].familiya << " " << fmass[i].born.day << "." << fmass[i].born.month << "." << fmass[i].born.year << " " << fmass[i].mark;
  117. cout << "\n";
  118. }
  119. }
  120. fclose(fstud);
  121. goto question;
  122. case 2:
  123. cout << "From mark: ";
  124. int fmark;
  125. cin >> fmark;
  126. cout << "To mark: ";
  127. int tmark;
  128. cin >> tmark;
  129. for (int i = 0; i < N; i++)
  130. {
  131. if (fmass[i].mark >= fmark && fmass[i].mark <= tmark)
  132. {
  133. cout << fmass[i].num << " " << fmass[i].surname << " " << fmass[i].name << " " << fmass[i].familiya << " " << fmass[i].born.day << "." << fmass[i].born.month << "." << fmass[i].born.year << " " << fmass[i].mark;
  134. cout << "\n";
  135. }
  136. }
  137. fclose(fstud);
  138. goto question;
  139. case 3:
  140. cout << "Enter date of birth(day/space/month)";
  141. int day1;
  142. int month1;
  143. cin >> day1;
  144. cin >> month1;
  145. for (int i = 0; i < count; i++)
  146. {
  147. fread(&fmass[i], sizeof(STUDENTS), 1, fstud);
  148. if (fmass[i].born.day == day1 && fmass[i].born.month == month1)
  149. {
  150. cout << fmass[i].num << " " << fmass[i].surname << " " << fmass[i].name << " " << fmass[i].familiya << " " << fmass[i].born.day << "." << fmass[i].born.month << "." << fmass[i].born.year << " " << fmass[i].mark;
  151. cout << "\n";
  152. }
  153. }
  154. fclose(fstud);
  155. goto question;
  156.  
  157. }
  158. case 4:
  159. cout << "Enter student's number:";
  160. int num1;
  161. cin >> num1;
  162. fopen("students.bin", "wb");
  163. for (int i = num1 - 1; i < count - 1; i++)
  164. {
  165. strcpy(student[i].name, student[i + 1].name);
  166. strcpy(student[i].surname, student[i + 1].surname);
  167. strcpy(student[i].familiya, student[i + 1].familiya);
  168. student[i].born.day = student[i + 1].born.day;
  169. student[i].born.month = student[i + 1].born.month;
  170. student[i].born.year = student[i + 1].born.year;
  171. student[i].mark = student[i + 1].mark;
  172. student[i].num = student[i + 1].num;
  173. }
  174. for (int i = 0; i < count - 1; i++)
  175. fwrite(&student[i], sizeof(STUDENTS), 1, fstud);
  176. fclose(fstud);
  177. count--;
  178. goto question;
  179. case 5:
  180. low_count = 0;
  181. mid_count = 0;
  182. high_count = 0;
  183. fopen("low_mark.bin", "wb");
  184. fclose(fstud);
  185. fopen("mid_mark.bin", "wb");
  186. fclose(fstud);
  187. fopen("high_mark.bin", "wb");
  188. fclose(fstud);
  189. sort(student, count);
  190. for (int i = fcount; i < count; i++)
  191. {
  192. if (student[i].mark < 50)
  193. {
  194. low_count++;
  195. fopen("low_mark.bin", "ab");
  196. fwrite(&student[i], sizeof(STUDENTS), 1, fstud);
  197. fclose(fstud);
  198. }
  199. else
  200. if (student[i].mark < 70)
  201. {
  202. mid_count++;
  203. fopen("mid_mark.bin", "ab");
  204. fwrite(&student[i], sizeof(STUDENTS), 1, fstud);
  205. fclose(fstud);
  206. }
  207. else
  208. if (student[i].mark < 101)
  209. {
  210. high_count++;
  211. fopen("high_mark.bin", "ab");
  212. fwrite(&student[i], sizeof(STUDENTS), 1, fstud);
  213. fclose(fstud);
  214. }
  215. }
  216. STUDENTS low[5];
  217. STUDENTS mid[5];
  218. STUDENTS high[5];
  219. cout << "1.High mark students \n";
  220. cout << "2.Middle mark students\n";
  221. cout << "3.Low mark students\n";
  222. cin >> q;
  223. switch (q)
  224. {
  225. case 1:
  226. fopen("high_mark.bin", "rb");
  227. for (int i = 0; i < high_count; i++)
  228. fread(&high[i], sizeof(STUDENTS), 1, fstud);
  229. for (int i = 0; i < high_count; i++)
  230. {
  231. cout << high[i].num << " " << high[i].surname << " " << high[i].name << " " << high[i].familiya << " " << high[i].born.day << "." << high[i].born.month << "." << high[i].born.year << " " << high[i].mark;
  232. cout << "\n";
  233. }
  234. fclose(fstud);
  235. goto question;
  236. case 2:
  237. fopen("mid_mark.bin", "rb");
  238. for (int i = 0; i < mid_count; i++)
  239. fread(&mid[i], sizeof(STUDENTS), 1, fstud);
  240. for (int i = 0; i < mid_count; i++)
  241. {
  242. cout << mid[i].num << " " << mid[i].surname << " " << mid[i].name << " " << mid[i].familiya << " " << mid[i].born.day << "." << mid[i].born.month << "." << mid[i].born.year << " " << mid[i].mark;
  243. cout << "\n";
  244. }
  245. fclose(fstud);
  246. goto question;
  247. case 3:
  248. fopen("low_mark.bin", "rb");
  249. for (int i = 0; i < low_count; i++)
  250. fread(&low[i], sizeof(STUDENTS), 1, fstud);
  251. for (int i = 0; i < low_count; i++)
  252. {
  253. cout << low[i].num << " " << low[i].surname << " " << low[i].name << " " << low[i].familiya << " " << low[i].born.day << "." << low[i].born.month << "." << low[i].born.year << " " << low[i].mark;
  254. cout << "\n";
  255. }
  256. fclose(fstud);
  257. goto question;
  258.  
  259. }
  260. goto question;
  261.  
  262.  
  263. }
  264. return 0;
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement