I am writing a program for class that manages a Hotel. This Report1 function is supposed to list all the occupied rooms and which customer is in each room. I have the code written, but i am getting a error in the condition statement of my nested FOR loop. The compiler is underlining iRoom in the loop………… for(int j = 0; j < iRoom.customerIDinRoom…..it is saying the iRoom expression must have a class type, but I gave it a class type when I declared it in the first FOR loop(of type Room). Any suggestioins?
string Hotel::Report1()
{
string result;
for(int i=0;i<listofrooms.size();i++)
{
Room iRoom = listofrooms.get(i);
result+= padLeft(intToString(iRoom.roomID),' ',8)+" "+
padRight(iRoom.name,' ',20) + " "+
padLeft(intToString(iRoom.floor),' ',8) + " " +
padLeft(intToString(iRoom.number),' ',8) + " " +
padLeft(intToString(iRoom.basePriceInSeason),' ',8) + " " +
padLeft(intToDollarString(iRoom.basePriceOutOfSeason),' ',8) + "\n";
for(int j = 0; j < iRoom.customerIDinRoom.size(); j++)
{
int cusID= iRoom.customerIDinRoom[j];
Customer & cus = listofcustomers.getByID(cusID);
result+= padLeft(intToString(cus.customerID),' ',18)+" "+
padRight(cus.name,' ',20) + " "+
padRight(cus.phoneNumber,' ',10) + " " +
padRight(cus.ccNumber,' ',20) + "\n";
}
}
return result;
}
This is the Room class declaration
#include <iostream>
#include <string>
using namespace std;
class Hotel;
class ListOfRooms;
class Room
{
friend class ListOfRooms;
friend class Hotel;
public:
Room(string n,int flo,int num,int bpin, int bpos);
Room();
void addCusID(int cusID){customerIDinRoom = cusID;}
void removeCustomerID(int cusID) { customerIDinRoom = 0;}
private:
string name; //BUILDING
int floor;
int number;
int basePriceInSeason;
int basePriceOutOfSeason;
int roomID;
int customerIDinRoom; //not pushback, will be assignment
};
The error is that
customerIDInRoomis anint, but you are calling asizemethod on it. If you are trying to loop from 0 tocustomerIDInRoom-1then you can simply remove thesize()call. If you need to keep a range of customerIDInRoom ints (as suggested by your “no pushback” comment in the code), then you would most likely need a standard library container. Which one to use depends on your requirements. All of these have asize()method.