Advertisement
niks32

Untitled

Oct 18th, 2022
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.37 KB | None | 0 0
  1. #include<iostream>
  2. #include<map>
  3. #include<vector>
  4.  
  5. using namespace std;
  6.  
  7. struct Student
  8. {
  9. char name[30];
  10. int group;
  11. int score[5];
  12. };
  13.  
  14. void setDataStudent(vector<Student> &currentStudent, int count);
  15. void setDataTest(vector<Student> &currentStudent, int count); //Данные для теста
  16.  
  17. void printDataStudent(vector<Student> &currentStudents);
  18. void sortStudentMidScore(vector<Student>& currentStudent);
  19.  
  20. void chekMidScore(vector<Student>& currentStudents, vector<Student>& filterResult);
  21. void chekScoreToTwo(vector<Student> &currentStudents, vector<Student>& filterResult);
  22. void chekScoreToForFive(vector<Student>& currentStudents, vector<Student>& filterResult);
  23.  
  24.  
  25. int main()
  26. {
  27. setlocale(LC_ALL, "Rus");
  28. int countOfStudent = 4;
  29. vector<Student> currentStudents;
  30. vector<Student> filterResult;
  31.  
  32.  
  33. //Объяви тип указатель на функцию, которая принимает на вход массив структур студентов (и
  34. typedef void(*studentFilter)(vector<Student>, vector<Student>);
  35. //Объяви map, ключ это номер выбора из меню, значение это указатель на функцию
  36. map<int, studentFilter> menu =
  37. {
  38. {1, chekMidScore},
  39. {2, chekScoreToTwo},
  40. {3, chekScoreToForFive}
  41. };
  42.  
  43. //setDataStudent(currentStudents, countOfStudent); //Ввод данных о студентах с клавиатуры
  44. setDataTest(currentStudents, countOfStudent);
  45. sortStudentMidScore(currentStudents);
  46.  
  47. //chekMidScore(currentStudents, filterResult);
  48. //chekScoreToTwo(currentStudents, filterResult);
  49. //chekScoreToForFive(currentStudents, filterResult);
  50. printDataStudent(filterResult);
  51.  
  52.  
  53. cout << "Welcome to Online IDE!! Happy Coding :)";
  54. return 0;
  55. }
  56.  
  57. void setDataStudent(vector<Student> &currentStudents, int count)
  58. {
  59. for (int i = 0; i < count; i++)
  60. {
  61. currentStudents.push_back(Student());
  62. cout << "----Ввод данных о студентах------------------------------------------" << endl;
  63. cout << "Введите данные студента №" << i + 1 << endl;
  64. cout << "Введите Имя, фамилие студента: ";
  65. cin.getline(currentStudents[i].name, 30);
  66. cout << "Введите номер группы: ";
  67. cin >> currentStudents[i].group;
  68.  
  69. double tmpSumScore = 0;
  70.  
  71. for (int j = 0; j < 5; j++)
  72. {
  73. cout << "Введите оценку №" << j + 1 << " ";
  74. cin >> currentStudents[i].score[j];
  75. }
  76. cin.get(); // считывает из потока Enter который пользователь нажимает после последнего ввода
  77. }
  78. }
  79.  
  80. void printDataStudent(vector<Student> &currentStudents)
  81. {
  82. for (int i = 0; i < currentStudents.size(); i++)
  83. {
  84. cout << "------------------------------------------------" << endl;
  85. cout << "Имя, фамилие студента: " << currentStudents[i].name << endl;
  86. cout << "Номер группы: " << currentStudents[i].group << endl;
  87. cout << "!!! Техническое, убрать перед релизом!!! Оценки: ";
  88. for (int j = 0; j < 5; j++)
  89. {
  90. cout << currentStudents[i].score[j] << " ";
  91. }
  92. cout << endl;
  93. }
  94.  
  95. if (currentStudents.empty())
  96. {
  97. cout << "Студентов удовлетваряющих условиям нет!" << endl;
  98. }
  99. }
  100.  
  101. void sortStudentMidScore(vector<Student> &currentStudent)
  102. {
  103. if (!currentStudent.empty())
  104. {
  105. int sizeOfVector = currentStudent.size();
  106. //Считаем средний балл
  107. vector<double> tmpMidlScoerStudents; // средние баллы студентов
  108. double tmpMidlScore; // средний балл текущего студента
  109. for (int i = 0; i < sizeOfVector; i++)
  110. {
  111. tmpMidlScore = 0;
  112. for (int j = 0; j < 5; j++) {
  113. tmpMidlScore = tmpMidlScore + currentStudent[i].score[j];
  114. }
  115. tmpMidlScoerStudents.push_back(tmpMidlScore / 5);
  116. }
  117.  
  118. //Сортировка студентов по среднему баллу tmpMidlScoerStudents[]
  119. Student tmpStudentForSwap;
  120.  
  121. for (int i = 0; i < sizeOfVector; i++)
  122. {
  123. int indexMinElement = i;
  124. tmpMidlScore = tmpMidlScoerStudents[i];
  125. for (int j = i; j < sizeOfVector; j++)
  126. {
  127. if (tmpMidlScore > tmpMidlScoerStudents[j])
  128. {
  129. tmpMidlScore = tmpMidlScoerStudents[j];
  130. indexMinElement = j;
  131. }
  132. }
  133.  
  134. tmpMidlScoerStudents[indexMinElement] = tmpMidlScoerStudents[i];
  135. tmpMidlScoerStudents[i] = tmpMidlScore;
  136.  
  137. tmpStudentForSwap = currentStudent[indexMinElement];
  138. currentStudent[indexMinElement] = currentStudent[i];
  139. currentStudent[i] = tmpStudentForSwap;
  140. }
  141. }
  142. }
  143.  
  144. void chekMidScore(vector<Student>& currentStudents, vector<Student>& filterResult)
  145. {
  146. filterResult.clear();
  147.  
  148. double tmpMidlScore; // средний балл текущего студента
  149. for (int i = 0; i < currentStudents.size(); i++)
  150. {
  151. tmpMidlScore = 0;
  152. for (int j = 0; j < 5; j++)
  153. {
  154. tmpMidlScore = tmpMidlScore + currentStudents[i].score[j];
  155. }
  156. tmpMidlScore = tmpMidlScore / 5;
  157.  
  158. if (tmpMidlScore > 4.0)
  159. {
  160. filterResult.push_back(currentStudents[i]);
  161. }
  162. }
  163. }
  164.  
  165. void chekScoreToTwo(vector<Student>& currentStudents, vector<Student>& filterResult)
  166. {
  167. filterResult.clear();
  168.  
  169. for (int i = 0; i < currentStudents.size(); i++)
  170. {
  171. for (int j = 0; j < 5; j++)
  172. {
  173. if (currentStudents[i].score[j] == 2)
  174. {
  175. filterResult.push_back(currentStudents[i]);
  176. break;
  177. }
  178. }
  179. }
  180. }
  181.  
  182. void chekScoreToForFive(vector<Student> &currentStudents, vector<Student>& filterResult)
  183. {
  184. filterResult.clear();
  185.  
  186. for (int i = 0; i < currentStudents.size(); i++)
  187. {
  188. //есть еще идея как реализовать проверку. Сперва добавлять все обьекты, после (если находим другие оценки, удалять)
  189. for (int j = 0; j < 5; j++)
  190. {
  191. if (currentStudents[i].score[j] == 4 || currentStudents[i].score[j] == 5)
  192. {
  193. if (j = 5)
  194. {
  195. filterResult.push_back(currentStudents[i]);
  196. }
  197. }
  198. else
  199. {
  200. break;
  201. }
  202. }
  203. }
  204. }
  205.  
  206.  
  207. void setDataTest(vector<Student> &currentStudent, int count)
  208. {
  209. for (int i = 0; i < count; i++)
  210. {
  211. currentStudent.push_back(Student());
  212. }
  213.  
  214. strcpy_s(currentStudent[0].name, "Первый");
  215. currentStudent[0].group = 1;
  216. currentStudent[0].score[0] = 5;
  217. currentStudent[0].score[1] = 5;
  218. currentStudent[0].score[2] = 5;
  219. currentStudent[0].score[3] = 5;
  220. currentStudent[0].score[4] = 5;
  221. //Средний балл студента 5
  222.  
  223. strcpy_s(currentStudent[1].name, "Второй");
  224. currentStudent[1].group = 2;
  225. currentStudent[1].score[0] = 1;
  226. currentStudent[1].score[1] = 1;
  227. currentStudent[1].score[2] = 2;
  228. currentStudent[1].score[3] = 1;
  229. currentStudent[1].score[4] = 2;
  230. //Средний балл студента 1.4
  231.  
  232. strcpy_s(currentStudent[2].name, "Третий");
  233. currentStudent[2].group = 3;
  234. currentStudent[2].score[0] = 4;
  235. currentStudent[2].score[1] = 4;
  236. currentStudent[2].score[2] = 5;
  237. currentStudent[2].score[3] = 4;
  238. currentStudent[2].score[4] = 5;
  239. //Средний балл студента 4.4
  240.  
  241. strcpy_s(currentStudent[3].name, "Четвертый");
  242. currentStudent[3].group = 4;
  243. currentStudent[3].score[0] = 3;
  244. currentStudent[3].score[1] = 3;
  245. currentStudent[3].score[2] = 5;
  246. currentStudent[3].score[3] = 4;
  247. currentStudent[3].score[4] = 2;
  248. }
  249.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement