Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- template<typename container>
- void print(container cont) {
- for (const auto& a : cont) {
- std::cout << a;
- }
- std::cout << std::endl;
- }
- struct student {
- std::string name;
- std::string surname;
- int course; // от 1 до 5
- int rating; // до 100
- double average_score; // до 5
- };
- std::ostream& operator<<(std::ostream& output, const student& st) {
- output << st.name << " " << st.surname << " " << st.course << " " << st.rating << " " << st.average_score << std::endl;
- return output;
- }
- 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, 75, 4.9} };
- print(students);
- std::sort(students.begin(), students.end(), [](const student& left, const student& right) { return left.surname < right.surname; });
- print(students);
- std::sort(students.begin(), students.end(), [](const student& left, const student& right) { return left.rating > right.rating; });
- print(students);
- std::sort(students.begin(), students.end(), [](const student& left, const student& right) { return left.average_score > right.average_score; });
- print(students);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement