Advertisement
nikminer4sv

Untitled

Nov 13th, 2022
707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <string>
  5. #include "product.h"
  6.  
  7. using namespace std;
  8.  
  9. struct Product {
  10. public:
  11.     string type;
  12.  
  13.     Product() = default;
  14.  
  15.     Product(string type) {
  16.         this->type = type;
  17.     }
  18.  
  19.     string GetType() const {
  20.         return this->type;
  21.     }
  22.  
  23.     friend bool operator==(const Product& a, const Product& b) {
  24.         return a.GetType() == b.GetType();
  25.     }
  26. };
  27.  
  28. int main() {
  29.     const Product searchProduct("laptop");
  30.     Product product1("phone");
  31.     Product product2("laptop");
  32.     Product product3("phone");
  33.     Product product4("phone");
  34.     vector<Product> storage;
  35.     storage.push_back(product1);
  36.     storage.push_back(product2);
  37.     storage.push_back(product3);
  38.     storage.push_back(product4);
  39.     cout << count(storage.begin(), storage.end(), searchProduct);
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement