Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- 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;
- }
- int main() {
- setlocale(LC_ALL, "ru");
- std::vector<student> students{ {"Иван", "Иванов", 1, 33, 3.7 }, { "Владимир", "Владимиров", 3, 39, 3.9 }, { "Геннадий", "Петров", 2, 56, 4.2 }, { "Ольга", "Григорьева", 5, 48, 4.0 }, { "Константин", "Сидоров", 4, 29, 3.5 }, { "Елена", "Гришина", 1, 75, 4.9 } };
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment