Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<map>
- #include<vector>
- using namespace std;
- struct Student
- {
- char name[30];
- int group;
- int score[5];
- };
- void setDataStudent(vector<Student> ¤tStudent, int count);
- void setDataTest(vector<Student> ¤tStudent, int count); //Данные для теста
- void printDataStudent(vector<Student> ¤tStudents);
- void sortStudentMidScore(vector<Student>& currentStudent);
- void chekMidScore(vector<Student>& currentStudents, vector<Student>& filterResult);
- void chekScoreToTwo(vector<Student> ¤tStudents, vector<Student>& filterResult);
- void chekScoreToForFive(vector<Student>& currentStudents, vector<Student>& filterResult);
- int main()
- {
- setlocale(LC_ALL, "Rus");
- int countOfStudent = 4;
- vector<Student> currentStudents;
- vector<Student> filterResult;
- //Объяви тип указатель на функцию, которая принимает на вход массив структур студентов (и
- typedef void(*studentFilter)(vector<Student>, vector<Student>);
- //Объяви map, ключ это номер выбора из меню, значение это указатель на функцию
- map<int, *studentFilter> menu =
- { {1, &chekMidScore},
- {2, &chekScoreToTwo},
- {3, &chekScoreToForFive} };
- //setDataStudent(currentStudents, countOfStudent); //Ввод данных о студентах с клавиатуры
- setDataTest(currentStudents, countOfStudent);
- sortStudentMidScore(currentStudents);
- //chekMidScore(currentStudents, filterResult);
- //chekScoreToTwo(currentStudents, filterResult);
- //chekScoreToForFive(currentStudents, filterResult);
- printDataStudent(filterResult);
- cout << "Welcome to Online IDE!! Happy Coding :)";
- return 0;
- }
- void setDataStudent(vector<Student> ¤tStudents, int count)
- {
- for (int i = 0; i < count; i++)
- {
- currentStudents.push_back(Student());
- cout << "----Ввод данных о студентах------------------------------------------" << endl;
- cout << "Введите данные студента №" << i + 1 << endl;
- cout << "Введите Имя, фамилие студента: ";
- cin.getline(currentStudents[i].name, 30);
- cout << "Введите номер группы: ";
- cin >> currentStudents[i].group;
- double tmpSumScore = 0;
- for (int j = 0; j < 5; j++)
- {
- cout << "Введите оценку №" << j + 1 << " ";
- cin >> currentStudents[i].score[j];
- }
- cin.get(); // считывает из потока Enter который пользователь нажимает после последнего ввода
- }
- }
- void printDataStudent(vector<Student> ¤tStudents)
- {
- for (int i = 0; i < currentStudents.size(); i++)
- {
- cout << "------------------------------------------------" << 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 (currentStudents.empty())
- {
- cout << "Студентов удовлетваряющих условиям нет!" << endl;
- }
- }
- void sortStudentMidScore(vector<Student> ¤tStudent)
- {
- if (!currentStudent.empty())
- {
- int sizeOfVector = currentStudent.size();
- //Считаем средний балл
- vector<double> tmpMidlScoerStudents; // средние баллы студентов
- double tmpMidlScore; // средний балл текущего студента
- for (int i = 0; i < sizeOfVector; i++)
- {
- tmpMidlScore = 0;
- for (int j = 0; j < 5; j++) {
- tmpMidlScore = tmpMidlScore + currentStudent[i].score[j];
- }
- tmpMidlScoerStudents.push_back(tmpMidlScore / 5);
- }
- //Сортировка студентов по среднему баллу tmpMidlScoerStudents[]
- Student tmpStudentForSwap;
- for (int i = 0; i < sizeOfVector; i++)
- {
- int indexMinElement = i;
- tmpMidlScore = tmpMidlScoerStudents[i];
- for (int j = i; j < sizeOfVector; j++)
- {
- if (tmpMidlScore > tmpMidlScoerStudents[j])
- {
- tmpMidlScore = tmpMidlScoerStudents[j];
- indexMinElement = j;
- }
- }
- tmpMidlScoerStudents[indexMinElement] = tmpMidlScoerStudents[i];
- tmpMidlScoerStudents[i] = tmpMidlScore;
- tmpStudentForSwap = currentStudent[indexMinElement];
- currentStudent[indexMinElement] = currentStudent[i];
- currentStudent[i] = tmpStudentForSwap;
- }
- }
- }
- void chekMidScore(vector<Student>& currentStudents, vector<Student>& filterResult)
- {
- filterResult.clear();
- double tmpMidlScore; // средний балл текущего студента
- for (int i = 0; i < currentStudents.size(); i++)
- {
- tmpMidlScore = 0;
- for (int j = 0; j < 5; j++)
- {
- tmpMidlScore = tmpMidlScore + currentStudents[i].score[j];
- }
- tmpMidlScore = tmpMidlScore / 5;
- if (tmpMidlScore > 4.0)
- {
- filterResult.push_back(currentStudents[i]);
- }
- }
- }
- void chekScoreToTwo(vector<Student>& currentStudents, vector<Student>& filterResult)
- {
- filterResult.clear();
- for (int i = 0; i < currentStudents.size(); i++)
- {
- for (int j = 0; j < 5; j++)
- {
- if (currentStudents[i].score[j] == 2)
- {
- filterResult.push_back(currentStudents[i]);
- break;
- }
- }
- }
- }
- void chekScoreToForFive(vector<Student> ¤tStudents, vector<Student>& filterResult)
- {
- filterResult.clear();
- for (int i = 0; i < currentStudents.size(); i++)
- {
- //есть еще идея как реализовать проверку. Сперва добавлять все обьекты, после (если находим другие оценки, удалять)
- for (int j = 0; j < 5; j++)
- {
- if (currentStudents[i].score[j] == 4 || currentStudents[i].score[j] == 5)
- {
- if (j = 5)
- {
- filterResult.push_back(currentStudents[i]);
- }
- }
- else
- {
- break;
- }
- }
- }
- }
- void setDataTest(vector<Student> ¤tStudent, int count)
- {
- for (int i = 0; i < count; i++)
- {
- currentStudent.push_back(Student());
- }
- strcpy_s(currentStudent[0].name, "Первый");
- currentStudent[0].group = 1;
- currentStudent[0].score[0] = 5;
- currentStudent[0].score[1] = 5;
- currentStudent[0].score[2] = 5;
- currentStudent[0].score[3] = 5;
- currentStudent[0].score[4] = 5;
- //Средний балл студента 5
- strcpy_s(currentStudent[1].name, "Второй");
- currentStudent[1].group = 2;
- currentStudent[1].score[0] = 1;
- currentStudent[1].score[1] = 1;
- currentStudent[1].score[2] = 2;
- currentStudent[1].score[3] = 1;
- currentStudent[1].score[4] = 2;
- //Средний балл студента 1.4
- strcpy_s(currentStudent[2].name, "Третий");
- currentStudent[2].group = 3;
- currentStudent[2].score[0] = 4;
- currentStudent[2].score[1] = 4;
- currentStudent[2].score[2] = 5;
- currentStudent[2].score[3] = 4;
- currentStudent[2].score[4] = 5;
- //Средний балл студента 4.4
- strcpy_s(currentStudent[3].name, "Четвертый");
- currentStudent[3].group = 4;
- currentStudent[3].score[0] = 3;
- currentStudent[3].score[1] = 3;
- currentStudent[3].score[2] = 5;
- currentStudent[3].score[3] = 4;
- currentStudent[3].score[4] = 2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement