Advertisement
niks32

help2

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