C/C++

С++ Задание: Сформировать списки студентов, в котором студенты-задолжники по двум предметам расположены по алфавиту.

С++ Создать структуру "Студент" со следующими данными: фамилия, имя, отчество, пол, факультет, курс, группа, отметки по пяти предметам, город проживания. Сформировать текстовый файл со списком студентов. Для каждого пункта характеристики студента выделять строку. Данные о студентах отделяются пустыми строками. Для выполнения задания данные из текстового файла ввести массив структур программы.
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <array>
#include <set>
using namespace std;
struct Student {
short course;
array<char, 5> grades;
string name;
string surname;
string patronymic;
string sex;
string city;
string faculty;
string group;
Student() : course(0) {}
friend istream& operator>>(istream& inp, Student& s) {
inp >> s.surname >> s.name >> s.patronymic >> s.sex >> s.faculty >> s.course >> s.group;
for (auto& grade : s.grades) inp >> grade;
inp >> s.city;
return inp;
}
friend ostream& operator<<(ostream& out, const Student& s) {
out << s.surname << ' ' << s.name << ' ' << s.patronymic << ", " << s.sex << ", "
<< s.course << " курс, " << s.faculty << " факультет, " << s.group << " группа\n"
<< "\tОценки:";
for (auto& grade : s.grades) out << ' ' << grade;
return out.put('\n');
}
friend bool operator<(const Student& a, const Student& b) {
if (a.surname < b.surname) return true;
if (a.surname == b.surname && a.name < b.name) return true;
if (a.surname == b.surname && a.name == b.name && a.patronymic < b.patronymic) return true;
return false;
}
};
int main() {
system("chcp 1251 > nul");
set<Student> list;
ifstream db("students.txt");
if (db.is_open()) {
Student student;
while (db >> student) list.emplace(student);
db.close();
}
if (list.empty()) puts("Ошибка! Данные не загружены.");
else {
const auto n = '3';
auto bad = [](char x) { return x < n; };
auto m = 0;
for (const auto& item : list) {
auto k = count_if(item.grades.begin(), item.grades.end(), bad);
if (k > 1) cout << setw(3) << ++m << ". " << item << '\n';
}
}
system("pause > nul");
}
ФМ
Филипп Маграчёв
88 159
Лучший ответ