EDIT: Well, almost. What I'm guessing what your getavailable is doing is returning a value, which you're then trying to assign another error, resulting in something similar to what I showed above. You'd need to return a reference to get the desired effect.
are you saying you want the function to be a getter? if so, then you need to either print out the result of the function or assign it to a variable. std::cout << b.getavailable();
or someInt = b.getavailable();
i'm not entirely sure what you're asking, though
this is the coding Exercise?
A small hotel tries to build a new system to keep information to facilitate
the searching process for available rooms. It has a number of rooms (assume
that it has only 10 room); the hotel database contains each room information
and a list of available rooms.
Each room contains the following ( room number, room type "single or
couple" , with a view or not, and its price)
Your program should include the following functions:
1. Build hotel information:
By calling this function , the information of each room will be entered.
Also suppose at the beginning that all of rooms are available.
2. Reserve a room:
When a new customer come ,the receptionist will ask the customer
about his/her preference ( room type "single or couple", with a view or
not) .Then, the receptionist will search for a suitable room . finally,
providing the customer with the cost of selected room (note that any
room costs 500SR , if it's couple add 100SR , and if it's with a view
add another 100SR) .
3. print Information of all "single" rooms:
#include<iostream>
usingnamespace std;
#include<string>
class room{
int roomNum;
string roomType;// single or couple
bool with_a_view;// 0 or 1
double price;
int available;
public:
room()
{available=1;
price=0.0;
with_a_view=0;
roomType=" ";
}
void build_hotel_information()
{
cout<<"enter the number of room"<<endl;
cin>>roomNum;
cout<<"enter room type (single or couple):"<<endl;
cin>>roomType;
cout<<"with a view or not:press(0) for no and press (1) for yes : "<<endl;
cin>>with_a_view;
if(roomType=="couple"&&with_a_view==1)
price=500+100+100;
if(roomType=="couple"&&with_a_view==0)
price=500+100;
if(roomType=="single"&&with_a_view==1)
price=500+100;
else
price=500;
}
int getroomNum()
{return roomNum;
}
string getroomType()
{ return roomType;}
bool getwith_a_view()
{ return with_a_view;}
double getprice()
{ return price;}
int& getavailable()
{ return available;}
};//end of class
class hotel{
room r[10];
string type;
bool view;
public:
void Reserve_room()
{
for(int i=0;i<10;i++)
{r[i].build_hotel_information();
r[i].getavailable();
r[i].getprice();
r[i].getroomNum();
r[i].getroomType();
r[i].getwith_a_view();
}
cout<<"enter the room type you want (single or couple): "<<endl;
cin>>type;
cout<<"Do you want it with a view or not? :press(0) for no and press (1) for yes : "<<endl;
cin>>view;
for(int j=0;j<10;j++)
{
if(type==r[j].getroomType())
if(view==r[j].getwith_a_view())
if(r[j].getavailable()==1){
r[j].getavailable()=0;
cout<<"your room is:"<<r[j].getroomNum()<<endl;
cout<<"the room cost: "<<r[j].getprice()<<endl;
else
cout<<"sorry there is no rooms available"<<endl;
}
}
}
};
int main()
{
hotel h1;
h1.Reserve_room();
return 0;
}