Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <vector>
- #include <algorithm>
- #include "Console.h"
- #include "Defines.h"
- #include "PlayStation.h"
- #include "xBox.h"
- class Store {
- public:
- Store() {}
- void addPs(int& price, int& quality, int& generation) {
- PlayStation p = PlayStation(price, quality, generation);
- _playstations.push_back(p);
- std::cout << "Adding: PS with generation " << generation << ", price: " << price << ", quality: " << quality << std::endl;
- }
- void addXbox(int& price, int& quality) {
- xBox x = xBox(price, quality);
- _xBoxes.push_back(x);
- std::cout << "Adding: Xbox with price: " << price << ", quality: " << quality << std::endl;
- }
- void remove(ConsoleType& type) {
- if (type == ConsoleType::PS) {
- if (_playstations.empty()) {
- return;
- }
- std::cout << "Removing: PS with price: " << _playstations.back().getPrice() << ", quality: " << _playstations.back().getQuality() << std::endl;
- _playstations.pop_back();
- }
- else if (type == ConsoleType::XBOX) {
- if (_xBoxes.empty()) {
- return;
- }
- std::cout << "Removing: Xbox with price: " << _xBoxes.back().getPrice() << ", quality: " << _xBoxes.back().getQuality() << std::endl;
- _xBoxes.pop_back();
- }
- }
- void sortByPrice(ConsoleType& type) {
- if (type == ConsoleType::PS) {
- std::sort(_playstations.begin(), _playstations.end(),
- [](const PlayStation& a, const PlayStation& b) {return a.getPrice() > b.getPrice(); });
- std::cout << "Sorting all PS by price" << std::endl;
- }
- else if(type == ConsoleType::XBOX) {
- std::sort(_xBoxes.begin(), _xBoxes.end(),
- [](const xBox& a, const xBox& b) {return a.getPrice() > b.getPrice(); });
- std::cout << "Sorting all Xbox by price" << std::endl;
- }
- }
- void sortByQuality(ConsoleType& type) {
- if (type == ConsoleType::PS) {
- std::sort(_playstations.begin(), _playstations.end(),
- [](const PlayStation& a, const PlayStation& b) {return a.getQuality() > b.getQuality(); });
- std::cout << "Sorting all PS by quality" << std::endl;
- }
- else if (type == ConsoleType::XBOX) {
- std::sort(_xBoxes.begin(), _xBoxes.end(),
- [](const xBox& a, const xBox& b) {return a.getQuality() > b.getQuality(); });
- std::cout << "Sorting all Xbox by quality" << std::endl;
- }
- }
- void print(ConsoleType& type) {
- if (type == ConsoleType::PS) {
- std::cout << "Printing all PS data" << std::endl;
- for (auto& playstation : _playstations) {
- std::cout << "Playstation with generation: "<< playstation.getGen() << ", price: " << playstation.getPrice() << ", quality: " << playstation.getQuality() << std::endl;
- }
- }
- else if (type == ConsoleType::XBOX) {
- std::cout << "Printing all Xbox data" << std::endl;
- for (auto& xbox : _xBoxes) {
- std::cout << "Xbox with price: " << xbox.getPrice() << ", quality: " << xbox.getQuality() << std::endl;
- }
- }
- }
- private:
- std::vector<PlayStation> _playstations;
- std::vector<xBox> _xBoxes;
- };
Add Comment
Please, Sign In to add comment