Advertisement
35657

Untitled

Jul 26th, 2023
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7.  
  8. template <typename Container>
  9. void Print(Container cont) {
  10.     for (const auto& a : cont) {
  11.         std::cout << a;
  12.     }
  13.     std::cout << std::endl;
  14. }
  15.  
  16. struct Student {
  17.     std::string name;
  18.     std::string surname;
  19.     int course;
  20.     int rating;
  21.     double average_score;
  22. };
  23.  
  24. std::ostream& operator<<(std::ostream& output, const Student& student) {
  25.     return output << student.name << " " << student.surname << " " << student.course << " " << student.rating << " " << student.average_score << std::endl;
  26. }
  27.  
  28. int main() {
  29.     setlocale(LC_ALL, "ru");
  30.     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 }};
  31.  
  32.     Print(students);
  33.  
  34.     std::sort(students.begin(), students.end(), [](const Student& left, const Student& right) { return left.surname < right.surname; });
  35.  
  36.     Print(students);
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement