#include <iostream>
#include <algorithm>
#include <string>
#include "student.h"
using namespace std;
int getAvgMark(int marks[5], int numMarks) {
int avgMark = 0;
for (int i = 0; i < numMarks; i++) {
avgMark += marks[i];
}
return avgMark / numMarks;
}
void enterStudents(Student students[], int limit) {
for (int i = 0; i < limit; i++) {
cout << "Student " << i + 1 << endl;
cout << "Last name and initials: ";
getline(cin, students[i].last_name_and_initials);
cout << "Group: ";
cin >> students[i].group;
cout << "Marks: ";
for (int j = 0; j < 5; j++) {
cin >> students[i].marks[j];
}
cin.ignore(); // ignore the newline character left in the input stream by cin
}
cout << endl;
}
void printGoodAndExcellentStudents(Student students[], int limit) {
bool found = false;
for (int i = 0; i < limit; i++) {
int avgMark = getAvgMark(students[i].marks, 5);
if (avgMark >= 75 && avgMark <= 89) {
cout << students[i].last_name_and_initials << ", Group " << students[i].group << " (Good)" << endl;
found = true;
}
else if (avgMark >= 90 && avgMark <= 100) {
cout << students[i].last_name_and_initials << ", Group " << students[i].group << " (Excellent)" << endl;
found = true;
}
}
if (!found) {
cout << "Students not found" << endl;
}
cout << endl;
}
void sortStudents(Student students[], int limit) {
for (int i = 0; i < limit - 1; i++) {
for (int j = i + 1; j < limit; j++) {
if (getAvgMark(students[i].marks, 5) > getAvgMark(students[j].marks, 5)) {
swap(students[i], students[j]);
}
}
}
}
int main() {
const int LIMIT_OF_STUDENTS = 10;
Student students[LIMIT_OF_STUDENTS];
enterStudents(students, LIMIT_OF_STUDENTS);
cout << "Good and Excellent Students: " << endl;
printGoodAndExcellentStudents(students, LIMIT_OF_STUDENTS);
cout << "Sort students in ascending order: " << endl;
sortStudents(students, LIMIT_OF_STUDENTS);
cout << "Sorted students in ascending order: " << endl;
for (int i = 0; i < LIMIT_OF_STUDENTS; i++) {
cout << students[i].last_name_and_initials << ", Group " << students[i].group << ", Average mark: " << getAvgMark(students[i].marks, 5) << endl;
}
return 0;
}