E0289 отсутствуют экземпляры конструктора "Student::Student"
5 ошибок E0289
: отсутствуют экземпляры конструктора Student::Student
, соответствующие списку аргументов, строки 37-41.
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
struct Student {
string name;
string group;
int grades[5];
double average;
// Конструктор для вычисления среднего балла при создании объекта
Student(string name, string group, int grades[]) {
this->name = name;
this->group = group;
for (int i = 0; i < 5; i++) {
this->grades[i] = grades[i];
}
this->average = accumulate(grades, grades + 5, 0.0) / 5;
}
// Оператор для сравнения студентов по среднему баллу
bool operator<(const Student& other) const {
return average < other.average;
}
};
int main() {
const int n = 5;
Student students[n] =
{
Student("Ivanov I.I.", "group1", {5, 4, 5, 4, 5}),
Student("Petrov P.P.", "group2", {4, 4, 4, 5, 5}),
Student("Sidorov S.S.", "group1", {3, 4, 3, 4, 4}),
Student("Kuznetsov K.K.", "group2", {5, 5, 5, 5, 5}),
Student("Smirnov S.S.", "group1", {4, 4, 4, 4, 4})
};
// Сортировка студентов по среднему баллу
sort(students, students + n);
// Вывод фамилий и номеров групп студентов с оценками 4 и 5
bool found = false;
for (int i = 0; i < n; i++) {
bool has_good_grades = all_of(students[i].grades, students[i].grades + 5, [](int grade) { return grade >= 4; });
if (has_good_grades) {
cout << students[i].name << " " << students[i].group << endl;
found = true;
}
}
if (!found) {
cout << "No students with good grades found." << endl;
}
return 0;
}
Источник: Stack Overflow на русском