Advertisement
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(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& left, const Student& right) { return left.surname < right.surname; });
- Print(students);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement