//Lynette Wilkins
//Week 6
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class HotelRoom
{
private:
char room_num[3]; //Character array that stores a 3-character room number
char* guest; //Character pointer,which stores the name of the guest occupying the room
int room_cap;
int occup_stat;
double daily_rt;
public:
HotelRoom(char room[], char* g_p, int roomcap, int occup, double rate = 89.00);
~HotelRoom();
char* Get_Number(); //Displays room number and add the method Display_Guest()
int Get_Capacity();
int Get_Status();
double Get_Rate();
int Change_Status(int);
double Change_Rate(double);
char* Get_Guest();
};
HotelRoom::HotelRoom(char room[], char* g_p, int roomcap,int occup, double rate )
{
strcpy(room_num, room); //copy first argument into room_num[]
guest = new char[strlen(g_p) + 1]; //reserve space for the guest name
strcpy(guest, g_p); //copy fourth argument into new space
room_cap = roomcap;
daily_rt = rate;
occup_stat = occup;
}
HotelRoom::~HotelRoom()
{
cout << endl<<endl;
cout << "Guest in room "<<room_num << " has checked out." <<endl;
delete [] guest;
}
char* HotelRoom::Get_Number()
{
return room_num;
}
int HotelRoom::Get_Capacity()
{
return room_cap;
}
int HotelRoom::Get_Status()
{
return occup_stat;
}
int HotelRoom::Change_Status(int occup)
{
occup_stat = occup;
if (occup > room_cap)
{
return -1;
}
else
return occup_stat;
}
double HotelRoom::Get_Rate()
{
return daily_rt;
}
double HotelRoom::Change_Rate(double rate)
{
daily_rt = rate;
return daily_rt;
}
char* HotelRoom::Get_Guest()
{
return guest;
}
void Display_Room(HotelRoom&); //Function prototypes
HotelRoom* Create_Room();
int main()
{
cout<< setprecision(2)
<<setiosflags(ios::fixed)
<<setiosflags(ios::showpoint);
HotelRoom* hotel[200];
int count = 0;
char response;
cout<<endl;
cout<< "Do you want to enter information about a hotel room?(Y/N): ";
response = cin.get();
cin.get(); //This will clear the input buffer
while (toupper(response) == 'Y' && count< 200)
{
hotel[count] = Create_Room();
++count;
cout<<endl;
cout<< "Do you want to enter information about a hotel room?(Y/N): ";
response = cin.get();
cin.get(); //This will clear the input buffer
}
// Display the rooms
int i;
for (int i = 0; i< count; ++i)
Display_Room(*hotel[i]);
for (i = 0; i < count; ++i)
delete hotel[i];
cout<<endl;
return 0;
}
void Display_Room(HotelRoom& room)
{
cout<<endl;
cout<< "Information for room " << room.Get_Number() <<endl<<endl;
cout<< "Primary Guest Name: " << room.Get_Guest() <<endl;
cout<< "The amount of guest that will occupy this room is: "<<room.Change_Status(occup) <<endl;
cout<< "The daily rate of this room is: " <<room.Get_Rate() <<endl;
}
HotelRoom* Setup_Room()
{
char room[4];
char buffer[100]; //temporarily stores guest name
int roomcap = 4;
int occup;
double rate = 89.00;
HotelRoom* room_ptr;
cout<<"\nEnter the room number: "<<endl;
cin.getline(room, 5);
cout<<"\nEnter the amount of guest to occupy this room: "<<endl;
cin>>occup;
cout<<"\nEnter the primary guest name: "<<endl;
cin.ignore();
cin.getline(buffer, 100);
cin.get(); //Clear the input buffer of newline character
room_ptr = new HotelRoom (room, buffer, roomcap, occup, rate);
return room_ptr;
}
llwilkins, on 19 November 2012 - 04:10 PM, said:
I am getting an error stating that occup is not declared. But I already declared it. Can you find why this is happening?
//Lynette Wilkins
//Week 6
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class HotelRoom
{
private:
char room_num[3]; //Character array that stores a 3-character room number
char* guest; //Character pointer,which stores the name of the guest occupying the room
int room_cap;
int occup_stat;
double daily_rt;
public:
HotelRoom(char room[], char* g_p, int roomcap, int occup, double rate = 89.00);
~HotelRoom();
char* Get_Number(); //Displays room number and add the method Display_Guest()
int Get_Capacity();
int Get_Status();
double Get_Rate();
int Change_Status(int);
double Change_Rate(double);
char* Get_Guest();
};
HotelRoom::HotelRoom(char room[], char* g_p, int roomcap,int occup, double rate )
{
strcpy(room_num, room); //copy first argument into room_num[]
guest = new char[strlen(g_p) + 1]; //reserve space for the guest name
strcpy(guest, g_p); //copy fourth argument into new space
room_cap = roomcap;
daily_rt = rate;
occup_stat = occup;
}
HotelRoom::~HotelRoom()
{
cout << endl<<endl;
cout << "Guest in room "<<room_num << " has checked out." <<endl;
delete [] guest;
}
char* HotelRoom::Get_Number()
{
return room_num;
}
int HotelRoom::Get_Capacity()
{
return room_cap;
}
int HotelRoom::Get_Status()
{
return occup_stat;
}
int HotelRoom::Change_Status(int occup)
{
occup_stat = occup;
if (occup > room_cap)
{
return -1;
}
else
return occup_stat;
}
double HotelRoom::Get_Rate()
{
return daily_rt;
}
double HotelRoom::Change_Rate(double rate)
{
daily_rt = rate;
return daily_rt;
}
char* HotelRoom::Get_Guest()
{
return guest;
}
void Display_Room(HotelRoom&); //Function prototypes
HotelRoom* Create_Room();
int main()
{
cout<< setprecision(2)
<<setiosflags(ios::fixed)
<<setiosflags(ios::showpoint);
HotelRoom* hotel[200];
int count = 0;
char response;
cout<<endl;
cout<< "Do you want to enter information about a hotel room?(Y/N): ";
response = cin.get();
cin.get(); //This will clear the input buffer
while (toupper(response) == 'Y' && count< 200)
{
hotel[count] = Create_Room();
++count;
cout<<endl;
cout<< "Do you want to enter information about a hotel room?(Y/N): ";
response = cin.get();
cin.get(); //This will clear the input buffer
}
// Display the rooms
int i;
for (int i = 0; i< count; ++i)
Display_Room(*hotel[i]);
for (i = 0; i < count; ++i)
delete hotel[i];
cout<<endl;
return 0;
}
void Display_Room(HotelRoom& room)
{
cout<<endl;
cout<< "Information for room " << room.Get_Number() <<endl<<endl;
cout<< "Primary Guest Name: " << room.Get_Guest() <<endl;
cout<< "The amount of guest that will occupy this room is: "<<room.Change_Status(occup) <<endl;
cout<< "The daily rate of this room is: " <<room.Get_Rate() <<endl;
}
HotelRoom* Setup_Room()
{
char room[4];
char buffer[100]; //temporarily stores guest name
int roomcap = 4;
int occup;
double rate = 89.00;
HotelRoom* room_ptr;
cout<<"\nEnter the room number: "<<endl;
cin.getline(room, 5);
cout<<"\nEnter the amount of guest to occupy this room: "<<endl;
cin>>occup;
cout<<"\nEnter the primary guest name: "<<endl;
cin.ignore();
cin.getline(buffer, 100);
cin.get(); //Clear the input buffer of newline character
room_ptr = new HotelRoom (room, buffer, roomcap, occup, rate);
return room_ptr;
}
This error is in line 151

New Topic/Question
Reply



MultiQuote



|