Question #37107

How would you code for a one-argument method Change_Status() that changes the occupancy status of the room to the value of its argument. The method should verify that the argument value does not exceed the room capacity. If it does, the method should return -1.

Expert's answer

#include <iostream>
#include <conio.h>
using namespace std;
class Room
{
public:
    void Set_Capacity(int newCapacity)
    {
        roomCapacity = newCapacity;
    }
    int Change_Status(int newValue)
    {
        if (newValue < roomCapacity)
    {
        roomStatus = newValue;
        return roomStatus;
    }
    else
        return -1;
    }
private:
    int roomCapacity;
    int roomStatus;
};
int main()
{
    Room room;
    room.Set_Capacity(40);
    int newStatus;
    cout << "Enter the new status for the room: ";
    cin >> newStatus;
    room.Change_Status(newStatus);
    cout << "There is "<< room.Change_Status(newStatus);
    _getch();
    return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS