Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include "Game.h";
- class GamePlatform {
- private:
- Game games[100];
- int gameCount;
- public:
- GamePlatform() = default;
- bool addGame(const Game& game) {
- if (gameCount < 100) {
- games[gameCount++] = game;
- return true;
- }
- return false;
- }
- void printGame(int idx) {
- if (idx >= 0 && idx < gameCount) {
- games[idx].print();
- }
- else {
- std::cout << "Invalid index!" << std::endl;
- }
- }
- void printAllGames() {
- for (int i = 0; i < gameCount; i++) {
- games[i].print();
- }
- }
- void printCheapestGame() {
- if (gameCount == 0) {
- std::cout << "No games in the platform!" << std::endl;
- }
- return;
- int idxCheapest = 0;
- for (int i = 1; i < gameCount; i++) {
- if (games[i].getPrice() < games[idxCheapest].getPrice()) {
- idxCheapest = i;
- }
- }
- std::cout << "Cheapest game: " << std::endl;
- games[idxCheapest].print();
- }
- void printMostExpensiveGame() {
- if (gameCount == 0) {
- std::cout << "No games in the platform!" << std::endl;
- return;
- }
- int idxExpensive = 0;
- for (int i = 1; i < gameCount; i++) {
- if (games[i].getPrice() > games[idxExpensive].getPrice()) {
- idxExpensive = i;
- }
- }
- std::cout << "Most expensive game: " << std::endl;
- games[idxExpensive].print();
- }
- void printAllFreeGames() {
- std::cout << "Free game: " << std::endl;
- bool found = false;
- for (int i = 0; i < gameCount; i++) {
- if (games[i].isFree()) {
- games[i].print();
- found = true;
- }
- }
- }
- bool removeGame(int idx) {
- if (idx < 0 || idx >= gameCount) {
- return false; //invalid index
- }
- for (int i = idx; i < gameCount - 1; i++) {
- games[i] = games[i + 1]; //moving each next element with one position to left
- }
- gameCount--;
- return true;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement