Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. class CL {
  2. public:
  3.     CL(){
  4.         m_cars = std::vector<Car>();
  5.     }
  6.     CL(const std::vector<Car> &cars) {
  7.         m_cars = cars;
  8.     }
  9.     CL(const Car &car) {
  10.         m_cars = {car};
  11.     }
  12.     void find(int start, int end, const char *txt, std::list<Car> &result) {
  13.         std::regex pattern(std::string(".*" + std::string(txt) + ".*"), std::regex_constants::icase);
  14.         for (const auto &car: m_cars) {
  15.             if (start < car.m_year && car.m_year < end) {
  16.                 if (std::regex_match(car.m_model, pattern) || std::regex_match(car.m_brand, pattern)) {
  17.                     result.emplace_back(car);
  18.                 }
  19.             }
  20.         }
  21.     }
  22.     friend std::ostream &operator<<(std::ostream &stream, const CL  &cl);
  23.     friend std::istream &operator>>(std::istream& is, CL& ocl);
  24. public:
  25.     std::vector<Car> m_cars;
  26. };
  27.  
  28. std::ostream &operator<<(std::ostream &os, const CL &cl) {
  29.     os << "CL {";
  30.     for (const auto &car: cl.m_cars) {
  31.         os << "(brand: " << car.m_brand << ", model: " << car.m_model << ", year: " << car.m_year << "), ";
  32.     }
  33.     os << "}";
  34.     return os;
  35. }
  36.  
  37. std::istream &operator>>(std::istream& is, CL &cl) {
  38.     std::string brand;
  39.     std::string model;
  40.     std::string year;
  41.     is >> brand;
  42.     is >> model;
  43.     is >> year;
  44.     cl.m_cars.emplace_back(brand, model, std::stoi(year));
  45.     return is;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement