Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Q2. (25 marks) Create a class called Room to represent a hotel room. The class h

ID: 3876186 • Letter: Q

Question

Q2. (25 marks) Create a class called Room to represent a hotel room. The class has the following data members:

- Room number ( of type integer)

- Room type that can be one of the following two values: Regular or Suite

- Room availability (Boolean).

This attribute is true if the room is available; false otherwise The class should have at least the following member functions:

- One or more constructors

- Checking if a room is available

- Returning the room type

- A function that prints information about a customer

- A destructor Create a driver to test the class Room.

in c++ please

Explanation / Answer


Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you


room.h
=======
#ifndef room_h
#define room_h
#include <iostream>
using namespace std;
class Room
{
private:
int roomNum;
string roomType;
bool available;
public:
//default constructor
Room();
  
//parameterized constructor
Room(int rnumber, string rtype, bool isAvailable);

//function to check if room is available
bool isAvailable();
  
//function to get room type
string getType();
  
  
//function to get room number
int getNumber();
  
void print();
  
//destructor
~Room() {}
  
};
#endif /* room_h */



room.cpp
========
#include "room.h"
//default constructor
Room::Room()
{
roomNum = 0;
roomType = "";
available = false;
}
//parameterized constructor
Room::Room(int rnumber, string rtype, bool isAvailable)
{
roomNum = rnumber;
roomType = rtype;
available = isAvailable;
}
//function to check if room is available
bool Room::isAvailable()
{
return available;
}
//function to get room type
string Room::getType()
{
return roomType;
}
//function to get room number
int Room::getNumber()
{
return roomNum;
}
void Room::print()
{
cout << "Room Number: " << roomNum ;
cout << " Room Type: " << roomType;
cout << " Availability: " << available << endl;
}



roomtest.cpp
===========
#include <iostream>
#include "room.h"
int main()
{
Room reg(100, "Regular", false);
Room suite(200, "Suite", true);
  
  
cout << "Regular room number is " << reg.getNumber() << endl;
cout << "Regular room type is " << reg.getType() << endl;
cout << "Availability of regular room is " << reg.isAvailable() << endl << endl;
  
cout << "Showing suite details" << endl;
suite.print();
}




output
Regular room number is 100
Regular room type is Regular
Availability of regular room is 0
Showing suite details
Room Number: 200 Room Type: Suite Availability: 1