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);
- vector<Student> chekMidScore(vector<Student>& currentStudents);
- void chekScoreToTwo(vector<Student> ¤tStudent, int count);
- void chekScoreToForFive(vector<Student> ¤tStudent, int count);
- int main()
- {
- setlocale(LC_ALL, "Rus");
- int countOfStudent = 3;
- vector<Student> currentStudents;
- //Student* currentStudent = new Student[countOfStudent];
- //мое обьявление
- /*map<int, void(*)(Student, int)> menu =
- { {1, &chekMidScore},
- {2, &chekScoreToTwo},
- {3, &chekScoreToForFive} };*/
- //typedef void(*MenuFunc)(Student, int) обьявление НИКИТА
- //setDataStudent(currentStudents, countOfStudent); //Ввод данных о студентаз с клавиатуры
- setDataTest(currentStudents, countOfStudent);
- sortStudentMidScore(currentStudents);
- //chekMidScore(currentStudents);
- printDataStudent(chekMidScore(currentStudents));
- //printDataStudent(currentStudent, countOfStudent);
- //Объяви тип указатель на функцию, которая принимает на вход массив структур студентов
- void* somePointer(Student, int);
- 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;
- }
- }
- }
- vector<Student> chekMidScore(vector<Student>& currentStudents)
- {
- vector<Student> ResultArr;
- 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];
- }
- if (tmpMidlScore > 4.0)
- {
- ResultArr.push_back(currentStudents[i]);
- }
- }
- cout << "----------123131231------" << endl;
- for (int i = 0; i < ResultArr.size(); i++)
- {
- cout << "name" << ResultArr[i].name << endl;
- }
- return ResultArr;
- }
- void setDataTest(vector<Student> ¤tStudent, int count)
- {
- for (int i = 0; i < count; i++)
- {
- currentStudent.push_back(Student());
- }
- strcpy_s(currentStudent[0].name, "1");
- 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, "2");
- 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, "3");
- 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
- }
- // Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
- // Отладка программы: F5 или меню "Отладка" > "Запустить отладку"
- // Советы по началу работы
- // 1. В окне обозревателя решений можно добавлять файлы и управлять ими.
- // 2. В окне Team Explorer можно подключиться к системе управления версиями.
- // 3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения.
- // 4. В окне "Список ошибок" можно просматривать ошибки.
- // 5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода.
- // 6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement