35657

Untitled

Sep 21st, 2024
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6.  
  7. template <typename container>
  8. void print(const container& cont) {
  9.     for (const auto& a : cont) {
  10.         std::cout << a;
  11.     }
  12.     std::cout << std::endl;
  13. }
  14.  
  15. struct student {
  16.     std::string name;
  17.     std::string surname;
  18.     int course;
  19.     int rating;
  20.     double average_score;
  21. };
  22.  
  23. std::ostream& operator<<(std::ostream& output, const student& student) {
  24.     return output << student.name << " " << student.surname << " " << student.course << " " << student.rating << " " << student.average_score << std::endl;
  25. }
  26.  
  27. int main() {
  28.  
  29.     setlocale(LC_ALL, "ru");
  30.  
  31.     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 } };
  32.  
  33.     print(students);
  34.  
  35.     std::sort(students.begin(), students.end(), [](const student & a, const student & b) {return a.surname < b.surname; });
  36.  
  37.     print(students);
  38.  
  39.     std::sort(students.begin(), students.end(), [](const student & a, const student & b) {return a.rating > b.rating; });
  40.  
  41.     print(students);
  42.  
  43.     std::sort(students.begin(), students.end(), [](const student & a, const student & b) {return a.average_score > b.average_score; });
  44.  
  45.     print(students);
  46.  
  47.     auto it = std::remove_if(students.begin(), students.end(), [](const student & a) {return a.course == 5; });
  48.  
  49.     students.erase(it, students.end());
  50.  
  51.     //students.erase(std::remove_if(students.begin(), students.end(), [](const student & a) {return a.course == 5; }), students.end());
  52.  
  53.     print(students);
  54.  
  55.     std::for_each(students.begin(), students.end(), [](student & a) {a.course++; });
  56.  
  57.     print(students);
  58.  
  59.     it = std::max_element(students.begin(), students.end(), [](const student & a, const student & b) {return a.rating < b.rating; });
  60.  
  61.     std::cout << *it << std::endl;
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment