Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Online C++ Compiler - Build, Compile and Run your C++ programs online in your favorite browser
- #include<iostream>
- #include<map>
- using namespace std;
- struct Student
- {
- char name[30];
- int group;
- int score[5];
- //double midScore = 0; //убрать свойство
- bool flagForPrint = true; //убрать свойство
- };
- void setDataStudent(Student *currentStudent, int count);
- void printDataStudent(Student *currentStudents, int count);
- void sortStudentMidScore(Student *currentStudent, int count);
- Student *chekMidScore(const Student *currentStudents, int count);
- void chekScoreToTwo(Student *currentStudents, int count);
- void chekScoreToForFive(Student *currentStudents, int count);
- int main()
- {
- setlocale(LC_ALL, "Rus");
- int countOfStudent = 2;
- Student *currentStudent = new Student[countOfStudent];
- //мое обьявление
- /*map<int, void(*)(Student, int)> menu =
- { {1, &chekMidScore},
- {2, &chekScoreToTwo},
- {3, &chekScoreToForFive}, };*/
- //typedef void(*MenuFunc)(Student, int) обьявление НИКИТА
- setDataStudent(currentStudent, countOfStudent);
- //printDataStudent(currentStudent, countOfStudent);
- //cout << "Сортировка ----------------" << endl;
- sortStudentMidScore(currentStudent, countOfStudent);
- chekMidScore(currentStudent, countOfStudent);
- //printDataStudent(currentStudent, countOfStudent);
- //Объяви тип указатель на функцию, которая принимает на вход массив структур студентов
- void *somePointer(Student, int);
- cout<<"Welcome to Online IDE!! Happy Coding :)";
- return 0;
- }
- void setDataStudent(Student *currentStudent, int count)
- {
- for (int i=0; i < count; i++)
- {
- cout << "-------------------------------------------------------" << endl;
- cout << "Введите данные студента №" << i+1 << endl;
- cout << "Введите Имя, фамилие студента: ";
- cin.getline(currentStudent[i].name, 30 );
- //cout << "Введите номер группы: ";
- //cin >> currentStudent[i].group;
- double tmpSumScore = 0;
- for (int j=0; j < 5; j++)
- {
- cout << "Введите оценку №" << j+1;
- cin >> currentStudent[i].score[j];
- tmpSumScore = tmpSumScore + currentStudent[i].score[j];
- }
- cin.get(); // считывает из потока Enter который пользователь нажимает после последнего ввода
- }
- }
- void printDataStudent(Student *currentStudents, int count)
- {
- bool anyStudentPrint = false;
- for (int i=0; i < count; i++)
- {
- if (currentStudents[i].flagForPrint == true )
- {
- bool anyStudentPrint = true;
- cout << "-------------------------------------------------------" << endl;
- //cout << "Данные о студенте №" << i+1 << endl;
- cout << "Имя, фамилие студента: " << currentStudents[i].name << endl;
- cout << "Номер группы: " << currentStudents[i].group << endl;
- cout << "Оценки: ";
- for (int j=0; j < 5; j++)
- {
- cout << currentStudents[i].score[j] << " ";
- }
- cout << endl;
- }
- }
- if (anyStudentPrint == false)
- {
- cout << "Студентов удовлетваряющих условиям нет!" << endl;
- }
- }
- void sortStudentMidScore(Student *currentStudent, int count)
- {
- if (count > 1)
- {
- //Считаем средний балл
- double tmpMidlScoerStudents[count]; // средние баллы студентов
- double tmpMidlScore; // средний балл текущего студента
- for (int i=0; i < count; i++)
- {
- tmpMidlScore = 0;
- for (int j=0; j < 5; j++) {
- tmpMidlScore = tmpMidlScore + currentStudent[i].score[j];
- }
- tmpMidlScoerStudents[i] = tmpMidlScore / 5;
- }
- //Сортировка студентов по среднему баллу tmpMidlScoerStudents[]
- Student tmpStudentForSwap;
- for (int i=0; i < count; i++)
- {
- int indexMinElement = i;
- for (int j=i; j<count; j++)
- {
- if (tmpMidlScoerStudents[i] > tmpMidlScoerStudents[j])
- {
- tmpMidlScore = tmpMidlScoerStudents[j];
- indexMinElement = j;
- }
- }
- tmpMidlScoerStudents[indexMinElement] = tmpMidlScoerStudents[i];
- tmpMidlScoerStudents[i] = tmpMidlScore;
- tmpStudentForSwap = currentStudent[indexMinElement];
- currentStudent[indexMinElement] = currentStudent[i];
- currentStudent[i] = tmpStudentForSwap;
- }
- }
- //Смотрим результат3
- /*cout << "Результат: "<< endl;
- for (int i=0; i <count; i++)
- {
- cout << currentStudent[i].name << endl;
- }*/
- }
- void chekScoreToTwo(Student *currentStudents, int count)
- {
- for (int i=0; i<count; i++)
- {
- currentStudents[i].flagForPrint = true;
- for (int j=0; j<5; j++)
- {
- if (currentStudents[i].score[j] == 2)
- {
- currentStudents[i].flagForPrint = false;
- break;
- }
- }
- }
- }
- Student *chekMidScore(const Student *currentStudents, int count)
- {
- int sizeResultArr = 0;
- Student ResultArr[count] = {};
- double tmpMidlScore; // средний балл текущего студента
- for (int i=0; i < count; i++)
- {
- tmpMidlScore = 0;
- for (int j=0; j < 5; j++)
- {
- tmpMidlScore = tmpMidlScore + currentStudents[i].score[j];
- }
- if (tmpMidlScore < 4.0)
- {
- sizeResultArr++;
- ResultArr[sizeResultArr-1] = currentStudents[i];
- }
- }
- cout << "----------123131231------" << endl;
- cout << "2131 - " << ResultArr[2].name;
- return ResultArr; //, sizeResultArr;
- }
- void chekScoreToForFive(Student *currentStudents, int count)
- {
- for (int i=0; i<count; i++)
- {
- currentStudents[i].flagForPrint = false; //тут обратная логика
- for (int j=0; j<5; j++)
- {
- if (currentStudents[i].score[j] == 4 || currentStudents[i].score[j] ==5)
- {
- currentStudents[i].flagForPrint = true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement