mitkonikov

Rooms

May 9th, 2023
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.60 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Room {
  6.    public:
  7.     virtual void displayRoomInfo() = 0;
  8.     virtual void displayRoomPrice() = 0;
  9. };
  10.  
  11. class StandardRoom : public Room {
  12.    private:
  13.     bool hasBathroom;
  14.  
  15.    public:
  16.     StandardRoom() {}
  17.     StandardRoom(bool b) { hasBathroom = b; }
  18.     void displayRoomInfo() {
  19.         cout << "This is a standard room with a queen-sized bed";
  20.         if (hasBathroom) cout << " and a bathroom";
  21.         cout << "." << endl;
  22.     }
  23.     void displayRoomPrice() {
  24.         cout << "The price for a standard room is ";
  25.         if (hasBathroom) {
  26.             cout << "$100";
  27.         } else {
  28.             cout << "$80";
  29.         }
  30.         cout << " per night." << endl;
  31.     }
  32. };
  33.  
  34. class DeluxeRoom : public Room {
  35.    private:
  36.     bool hasBalcony = false;
  37.  
  38.    public:
  39.     DeluxeRoom() {}
  40.     DeluxeRoom(bool b) {
  41.         hasBalcony = b;
  42.     }
  43.     void displayRoomInfo() {
  44.         cout << "This is a deluxe room with a king-sized bed, a bathroom, a "
  45.                 "mini-fridge";
  46.         if (hasBalcony) {
  47.             cout << " and a balcony";
  48.         }
  49.         cout << "." << endl;
  50.     }
  51.     void displayRoomPrice() {
  52.         cout << "The price for a deluxe room is ";
  53.         if (hasBalcony) {
  54.             cout << "$200";
  55.         } else {
  56.             cout << "$160";
  57.         }
  58.         cout << " per night." << endl;
  59.     }
  60. };
  61.  
  62. // DO NOT CHANGE THE MAIN FUNCTION
  63. int main() {
  64.     Room* rooms[5];
  65.  
  66.     int testCase;
  67.  
  68.     cin >> testCase;
  69.  
  70.     if (testCase == 1) {
  71.         cout << "TEST CASE 1: TESTING STANDARD ROOM CLASS" << endl;
  72.  
  73.         for (int i = 0; i < 5; i++) {
  74.             rooms[i] = new StandardRoom();
  75.             rooms[i]->displayRoomInfo();
  76.             rooms[i]->displayRoomPrice();
  77.         }
  78.     } else if (testCase == 2) {
  79.         cout << "TEST CASE 2: TESTING DELUXE ROOM CLASS" << endl;
  80.         for (int i = 0; i < 5; i++) {
  81.             rooms[i] = new DeluxeRoom();
  82.             rooms[i]->displayRoomInfo();
  83.             rooms[i]->displayRoomPrice();
  84.         }
  85.     } else {
  86.         cout << "TEST CASE 3: TESTING BOTH CLASSES" << endl;
  87.         for (int i = 0; i < 5; i++) {
  88.             if (i % 2) {
  89.                 bool hasBalcony;
  90.                 cin >> hasBalcony;
  91.                 rooms[i] = new DeluxeRoom(hasBalcony);
  92.             } else {
  93.                 bool hasBathroom;
  94.                 cin >> hasBathroom;
  95.                 rooms[i] = new StandardRoom(hasBathroom);
  96.             }
  97.             rooms[i]->displayRoomInfo();
  98.             rooms[i]->displayRoomPrice();
  99.         }
  100.     }
  101.  
  102.     return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment