#include // Source: https://github.com/triffon/oop-2021-22/blob/main/practicum/6/week1/%D0%A1%D1%82%D1%80%D1%83%D0%BA%D1%82%D1%83%D1%80%D0%B8.%20%D0%94%D0%B5%D0%BA%D0%B0%D0%BB%D1%80%D0%B0%D1%86%D0%B8%D1%8F%20%D0%B8%20%D0%B8%D0%B7%D0%BF%D0%BE%D0%BB%D0%B7%D0%B2%D0%B0%D0%BD%D0%B5%20%D0%BD%D0%B0%20%D1%81%D1%82%D1%80%D1%83%D0%BA%D1%82%D1%83%D1%80%D0%B8..pdf // Ex 1 struct comp { // a + b * i double a; double b; }; comp sum(comp x, comp y) { return { x.a + y.a, x.b + y.b }; } void printComp(comp x) { std::cout << x.a << " + " << x.b << " * i"; } void ex1() { comp first = { 3, 5 }; comp second = { 7, 25 }; printComp(sum(first, second)); } // Ex 2 struct Student { int fn; int course; int grade; }; Student initStudent(int fn, int course, int grade) { return { fn, course, grade }; } void printStudent(const Student& st) { std::cout << "FN: " << st.fn << ";COURSE: " << st.course << ";GRADE: " << st.grade << std::endl; } void ex2() { Student gosho = initStudent(12345, 1, 7); printStudent(gosho); } // Ex 3 struct StudentList { Student * students; int size; }; struct Group { StudentList students; int avgGrade; }; Group cinGroup() { int n; std::cin >> n; Student* students = new Student[n]; int gradeSum = 0; for (int i = 0; i < n; i++) { std::cin >> students[i].fn >> students[i].course >> students[i].grade; gradeSum += students[i].grade; } return { { students, n }, gradeSum / n }; } int countScolarship(const Group& gr, int minGrade) { int count = 0; for (int i = 0; i < gr.students.size; i++) if (gr.students.students[i].grade >= minGrade) count++; return count; } void ex3() { Group ourGroup = cinGroup(); int minGrade; std::cin >> minGrade; std::cout << countScolarship(ourGroup, minGrade) << std::endl; delete[] ourGroup.students.students; } // Ex 4 void orderByGrades(const StudentList& sl) { for (int i = 0, minInd = i; i < sl.size; i++, minInd = i) { for (int j = i; j < sl.size; j++) { if (sl.students[j].grade > sl.students[minInd].grade) minInd = j; } Student temp = sl.students[i]; sl.students[i] = sl.students[minInd]; sl.students[minInd] = temp; } } StudentList scolarshipStudents(const Group& gr, int scolarshipGrade) { StudentList res = { new Student[gr.students.size], gr.students.size }; int ind = 0; for (int i = 0; i < gr.students.size; i++) if (gr.students.students[i].grade >= scolarshipGrade) res.students[ind++] = gr.students.students[i]; res.size = ind; return res; } void ex4() { Group ourGroup = cinGroup(); int scolarshipGrade; std::cin >> scolarshipGrade; StudentList withScolarship = scolarshipStudents(ourGroup, scolarshipGrade); orderByGrades(withScolarship); for (int i = 0; i < withScolarship.size; i++) printStudent(withScolarship.students[i]); delete[] ourGroup.students.students; delete[] withScolarship.students; } int main() { ex4(); }