Advertisement
niks32

Untitled

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