C/C++

Помогите на с++

Написать программу, которая вводит с клавиатуры данные, содержащие информацию: фамилия студента, год рождения, оценки по 5-ти экзаменам и создает массив структур. Отсортировать список студентов в алфавитном порядке.
Andriy Kantonistiy
Andriy Kantonistiy
121
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <array>
using namespace std;
struct Student {
unsigned short birthday;
string name;
array<unsigned short, 5> marks;
private:
friend bool operator<(const Student& a, const Student& b) {
return a.name < b.name;
}
friend istream& operator>>(istream& inp, Student& s) {
cout << "Ф. И. О.: ";
getline(inp, s.name);
s.birthday = s.integer(inp, "Год рождения: ");
cout << "Введите пять оценок за экзамены: ";
for (auto& mark : s.marks) mark = s.integer(inp);
inp.ignore(numeric_limits<streamsize>::max(), '\n');
return inp;
}
friend ostream& operator<<(ostream& out, const Student& s) {
out << setw(40) << left << s.name << ' '
<< setw(5) << right << s.birthday << " г. р.";
for (auto mark : s.marks) cout << setw(3) << mark;
puts("");
return out;
}
static unsigned short integer(istream& inp, const char* msg = "") {
auto value = 0U;
do {
cout << msg;
inp >> value;
} while (value > numeric_limits<unsigned short>::max());
return value;
}
};
unsigned integer(const char* msg) {
cout << msg;
unsigned value;
cin >> value;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
return value;
}
int main() {
system("chcp 1251 > nul");
auto n = integer("Количество студентов в группе: ");
auto students = new Student[n];
for (auto i = 0U; i < n; ++i) {
cin >> students[i];
puts("");
}
sort(students, students + n);
for (auto i = 0U; i < n; ++i) cout << students[i];
delete[] students;
system("pause > nul");
}
Виталик Белов
Виталик Белов
96 883
Лучший ответ