mstoyanov7

Store.h

Sep 12th, 2021 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.93 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. #include "Console.h"
  7. #include "Defines.h"
  8. #include "PlayStation.h"
  9. #include "xBox.h"
  10.  
  11. class Store {
  12. public:
  13.     Store() {}
  14.  
  15.     void addPs(int& price, int& quality, int& generation) {
  16.         PlayStation p = PlayStation(price, quality, generation);
  17.         _playstations.push_back(p);
  18.  
  19.         std::cout << "Adding: PS with generation " << generation << ", price: " << price << ", quality: " << quality << std::endl;
  20.     }
  21.  
  22.     void addXbox(int& price, int& quality) {
  23.         xBox x = xBox(price, quality);
  24.         _xBoxes.push_back(x);
  25.         std::cout << "Adding: Xbox with price: " << price << ", quality: " << quality << std::endl;
  26.     }
  27.  
  28.     void remove(ConsoleType& type) {
  29.         if (type == ConsoleType::PS) {
  30.             if (_playstations.empty()) {
  31.                 return;
  32.             }
  33.             std::cout << "Removing: PS with price: " << _playstations.back().getPrice() << ", quality: " << _playstations.back().getQuality() << std::endl;
  34.             _playstations.pop_back();
  35.         }
  36.         else if (type == ConsoleType::XBOX) {
  37.             if (_xBoxes.empty()) {
  38.                 return;
  39.             }
  40.             std::cout << "Removing: Xbox with price: " << _xBoxes.back().getPrice() << ", quality: " << _xBoxes.back().getQuality() << std::endl;
  41.             _xBoxes.pop_back();
  42.         }
  43.     }
  44.  
  45.     void sortByPrice(ConsoleType& type) {
  46.         if (type == ConsoleType::PS) {     
  47.             std::sort(_playstations.begin(), _playstations.end(),
  48.             [](const PlayStation& a, const PlayStation& b) {return a.getPrice() > b.getPrice(); });
  49.  
  50.             std::cout << "Sorting all PS by price" << std::endl;
  51.         }
  52.         else if(type == ConsoleType::XBOX) {
  53.             std::sort(_xBoxes.begin(), _xBoxes.end(),
  54.             [](const xBox& a, const xBox& b) {return a.getPrice() > b.getPrice(); });
  55.  
  56.             std::cout << "Sorting all Xbox by price" << std::endl;
  57.         }
  58.     }
  59.  
  60.     void sortByQuality(ConsoleType& type) {
  61.         if (type == ConsoleType::PS) {
  62.             std::sort(_playstations.begin(), _playstations.end(),
  63.                 [](const PlayStation& a, const PlayStation& b) {return a.getQuality() > b.getQuality(); });
  64.  
  65.             std::cout << "Sorting all PS by quality" << std::endl;
  66.         }
  67.         else if (type == ConsoleType::XBOX) {
  68.             std::sort(_xBoxes.begin(), _xBoxes.end(),
  69.                 [](const xBox& a, const xBox& b) {return a.getQuality() > b.getQuality(); });
  70.  
  71.             std::cout << "Sorting all Xbox by quality" << std::endl;
  72.         }
  73.     }
  74.  
  75.     void print(ConsoleType& type) {
  76.         if (type == ConsoleType::PS) {
  77.             std::cout << "Printing all PS data" << std::endl;
  78.             for (auto& playstation : _playstations) {
  79.                 std::cout << "Playstation with generation: "<< playstation.getGen() << ", price: " << playstation.getPrice() << ", quality: " << playstation.getQuality() << std::endl;
  80.             }
  81.         }
  82.         else if (type == ConsoleType::XBOX) {
  83.             std::cout << "Printing all Xbox data" << std::endl;
  84.             for (auto& xbox : _xBoxes) {
  85.                 std::cout << "Xbox with price: " << xbox.getPrice() << ", quality: " << xbox.getQuality() << std::endl;
  86.             }
  87.         }
  88.     }
  89.  
  90. private:
  91.     std::vector<PlayStation> _playstations;
  92.     std::vector<xBox> _xBoxes;
  93. };
Add Comment
Please, Sign In to add comment