Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <Windows.h>
- #include <fstream>
- template <typename container>
- void print(const container& cont) {
- for (const auto& a : cont) {
- std::cout << a;
- }
- std::cout << std::endl;
- }
- struct student {
- std::string name;
- std::string surname;
- int course;
- int rating;
- double average_score;
- };
- std::ostream& operator<<(std::ostream& output, const student& student) {
- return output << student.name << " " << student.surname << " " << student.course << " " << student.rating << " " << student.average_score << std::endl;
- }
- std::istream& operator>>(std::istream& input, student& student) {
- return input >> student.name >> student.surname >> student.course >> student.rating >> student.average_score;
- }
- int main() {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- std::vector<student> students;
- std::ifstream fin("students.txt");
- std::ofstream fout("students2.txt");
- if (!fin.is_open() || !fout.is_open()) {
- std::cout << "Ошибка открытия файла" << std::endl;
- }
- else {
- student temp;
- fin >> temp;
- while (!fin.eof()) {
- students.push_back(temp);
- fin >> temp;
- }
- print(students);
- std::sort(students.begin(), students.end(), [](const student & a, const student & b) {return a.surname < b.surname; });
- print(students);
- std::sort(students.begin(), students.end(), [](const student & a, const student & b) {return a.rating > b.rating; });
- print(students);
- std::sort(students.begin(), students.end(), [](const student & a, const student & b) {return a.average_score > b.average_score; });
- print(students);
- auto it = std::remove_if(students.begin(), students.end(), [](const student & a) {return a.course == 5; });
- students.erase(it, students.end());
- //students.erase(std::remove_if(students.begin(), students.end(), [](const student & a) {return a.course == 5; }), students.end());
- print(students);
- std::for_each(students.begin(), students.end(), [](student & a) {a.course++; });
- print(students);
- it = std::max_element(students.begin(), students.end(), [](const student & a, const student & b) {return a.rating < b.rating; });
- std::cout << *it << std::endl;
- for (const auto& a : students) {
- fout << a;
- }
- fin.close();
- fout.close();
- std::remove("students.txt");
- std::rename("students2.txt", "students.txt");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment