Advertisement
darinab

Game.h

Mar 25th, 2024
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #pragma warning (disable:4996)
  3.  
  4. class Game {
  5. private:
  6.     char title[65];
  7.     double price;
  8.     bool isAvailable;
  9.  
  10. public:
  11.     //default constructor
  12.     Game() = default;
  13.  
  14.     Game(const char* title, double price, bool isAvailable) {
  15.         char* newTitle = new char[strlen(title) + 1];
  16.         strcpy(this->title, title);
  17.         this->price = price;
  18.         this->isAvailable = isAvailable;
  19.     }
  20.  
  21.     const char* getTitle() const {
  22.         return title;
  23.     }
  24.  
  25.     double getPrice() {
  26.         return price;
  27.     }
  28.  
  29.     bool getAvailability() {
  30.         return isAvailable;
  31.     }
  32.  
  33.     void setTitle() {
  34.         for (int i = 0; i < strlen(title); i++) {
  35.             this->title[i] = title[i];
  36.         }
  37.     }
  38.  
  39.     void setPrice() {
  40.         this->price = price;
  41.     }
  42.  
  43.     void setAvailability() {
  44.         this->isAvailable = isAvailable;
  45.     }
  46.  
  47.     bool isFree() const {
  48.         return price == 0.0;
  49.     }
  50.  
  51.     void print() {
  52.         std::cout << "Title: " << title << ", Price: " << price << ", Available: " << isAvailable << std::endl;
  53.     }
  54. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement