Advertisement
niks32

Untitled

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