Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
#include <iostream>
#include <string>
using namespace std;
//class TRAVEL CONTROLS ALL FUNCTIONS
class Travel
{
struct Hotel
{ string cityName;
string hotelName;
int hotelCode;
int standardRoomNo;
int standardRoomPrice;
int deluxeRoomNo;
int deluxeRoomPrice;
}H;
struct Resort
{ string cityName;
int resortID;
string resortName;
int numberOfResorts;
int resortPrice;
}R;
struct Booking
{ int reservationNum;
string clientName;
int contactTel;
string email;
char option;
}B;public:
void Hotelinput();
void Resortinput();
void Bookinginput();
void Display1();
void Display2();
void Display3();
} P;
//**********************************************************
// FUNCTION NAME : Hotel
//**********************************************************void Travel::Hotelinput()
{
//DATA OF HOTEL
cout<<"Enter Hotel Information:";
cout<<"Enter City Name:";
cin>>(H.cityName);
cout<<"Hotel Name:";
cin>>(H.hotelName);
cout<<"Hotel Code:";
cin>>(H.hotelCode);
cout<<"Standard Room Number:";
cin>>(H.standardRoomNo);
cout<<"Standard Room Price:";
cin>>(H.standardRoomPrice);
cout<<"Deluxe Room Number:";
cin>>(H.deluxeRoomNo);
cout<<"Deluxe Room Price:";
cin>>(H.deluxeRoomPrice);
}void Travel::Resortinput()
//DATA OFRESORT
{ cout<<"Enter City Name:";
cin>>(R.cityName);
cout<<"Enter Resort ID:";
cin>>(R.resortID);
cout<<"Enter Resort Name:";
cin>>(R.resortName);
cout<<"Number Of Resorts:";
cin>>(R.numberOfResorts);
cout<<"Enter Resort Price:";
cin>>(R.resortPrice);
}void Travel::Bookinginput()
//BOOKING DATA
{ cout<<"Enter Reservation Number:";
cin>>(B.reservationNum);
cout<<"Enter Client Name:";
cin>>(B.clientName);
cout<<"Enter Contact Tel.:";
cin>>(B.contactTel);
cout<<"Enter E-mail:";
cin>>(B.email);
cout<<"Enter Catergory(H for Hotel,R forResort):";
cin>>(B.option);
}void Travel::Display1()
{
cout<<"Hotel information:";
cout<<"City Name:"<<H.cityName<<endl;
cout<<"Hotel Name:"<<H.hotelName<<endl;
cout<<"Hotel Code:"<<H.hotelCode<<endl;
cout<<"Standard Room Number:"<<H.standardRoomNo<<endl;
cout<<"Standard Room Price:"<<H.standardRoomPrice<<endl;
cout<<" Deluxe Room Number:"<<H.deluxeRoomNo<<endl;
cout<<"Deluxe Room Price:"<<H.deluxeRoomPrice<<endl;
}void Travel::Display2()
{
cout<<"Resort information:"<<endl;
cout<<"City Name:"<<R.cityName<<endl;
cout<<"Resort Name:"<<R.resortName<<endl;
cout<<"Resort ID:"<<R.resortID<<endl;
cout<<"Resort Price:"<<R.resortPrice<<endl;
}void Travel::Display3()
{
cout<<"Reservation Number:"<<B.reservationNum<<endl;
cout<<"Client Name:"<<B.clientName<<endl;
cout<<"Contact Tel.:"<<B.contactTel<<endl;
cout<<"E-mail:"<<B.email<<endl;
cout<<"Catergory:"<<B.option<<endl;
}int main()
{
struct Travel::Hotel Hot_1;
void displayMain();
return 0;
}
void displayMain()
{
{int selection;
do
{
cout<<"**********MAIN**********"<<endl;
cout<<"1.) Add Hotel Information: " << endl;
cout<<"2.) Add Resort Information:" << endl;
cout<<"3.) Add New Booking:" << endl;
cout<<"4.) View Hotel Information:"<<endl;
cout<<"5.) View Resort Information:"<<endl;
cout<<"6.) View Booking Information:"<<endl;
cout<<"7.) EXIT" << endl;
cout << "Selection: ";
cin >> selection;
}
while (selection <= 0 && selection >= 7);switch (selection)
{
case 1:
P.Hotelinput();
break;
case 2:
P.Resortinput();
break;
case 3:
P.Bookinginput();
break;
case 4:
P.Display1();
case 5:
P.Display2();
case 6:
P.Display3();case 7://leave blank
default:
;
}
}
}

Without throwing it into a complier, VS doesn't use int main(). It uses int _tmain(int argc, _TCHAR* argv[])
EDIT after throwing it into VC++:
struct Travel::Hotel Hot_1;
In your main function, you attempt to make a copy of a struct you defined as private to class Travel. You cannot do this.

Razor2.3 thank you for your answer.I am still new to programming......so i am failing to understand how to go about it.As for attempting to make a copy of a struct i defined as private to class Travel in the main function I got it.

Step 1: Change the main()'s definition as I said in my previous post.
Step 2: Get rid of the line struct Travel::Hotel Hot_1; in your main function. You don't need it, and you never do anything with it.
Step 3: Just below that line, strip the void off of the line below that.
Step 4: Move the entire main function below the displayVoid() function.
Step 4 Alt: Before the main function, add the following line:
void displayMain();

thank you once again Razor2.3.Now the problem is that the program can't be executed.When i compile there are no errors.

Hi...the program is now executable.Now how do i enter and display information for different(several) hotels,resorts and clients?
#include <iostream>
#include <string>
using namespace std;
//class TRAVEL CONTROLS ALL FUNCTIONS
class Travel
{
struct Hotel
{ string cityName;
string hotelName;
int hotelCode;
int standardRoomNo;
int standardRoomPrice;
int deluxeRoomNo;
int deluxeRoomPrice;
}H;
struct Resort
{ string cityName;
int resortID;
string resortName;
int numberOfResorts;
int resortPrice;
}R;
struct Booking
{ int reservationNum;
string clientName;
int contactTel;
string email;
char option;
}B;public:
void Hotelinput();
void Resortinput();
void Bookinginput();
void Display1();
void Display2();
void Display3();
} P;
//**********************************************************
// FUNCTION NAME : Hotel
//**********************************************************void Travel::Hotelinput()
{
//DATA OF HOTEL
cout<<"Enter Hotel Information:";
cout<<"Enter City Name:";
cin>>(H.cityName);
cout<<"Hotel Name:";
cin>>(H.hotelName);
cout<<"Hotel Code:";
cin>>(H.hotelCode);
cout<<"Standard Room Number:";
cin>>(H.standardRoomNo);
cout<<"Standard Room Price:";
cin>>(H.standardRoomPrice);
cout<<"Deluxe Room Number:";
cin>>(H.deluxeRoomNo);
cout<<"Deluxe Room Price:";
cin>>(H.deluxeRoomPrice);
}void Travel::Resortinput()
//DATA OFRESORT
{ cout<<"Enter City Name:";
cin>>(R.cityName);
cout<<"Enter Resort ID:";
cin>>(R.resortID);
cout<<"Enter Resort Name:";
cin>>(R.resortName);
cout<<"Number Of Resorts:";
cin>>(R.numberOfResorts);
cout<<"Enter Resort Price:";
cin>>(R.resortPrice);
}void Travel::Bookinginput()
//BOOKING DATA
{ cout<<"Enter Reservation Number:";
cin>>(B.reservationNum);
cout<<"Enter Client Name:";
cin>>(B.clientName);
cout<<"Enter Contact Tel.:";
cin>>(B.contactTel);
cout<<"Enter E-mail:";
cin>>(B.email);
cout<<"Enter Catergory(H for Hotel,R forResort):";
cin>>(B.option);
}void Travel::Display1()
{
cout<<"Hotel information:";
cout<<"City Name:"<<H.cityName<<endl;
cout<<"Hotel Name:"<<H.hotelName<<endl;
cout<<"Hotel Code:"<<H.hotelCode<<endl;
cout<<"Standard Room Number:"<<H.standardRoomNo<<endl;
cout<<"Standard Room Price:"<<H.standardRoomPrice<<endl;
cout<<" Deluxe Room Number:"<<H.deluxeRoomNo<<endl;
cout<<"Deluxe Room Price:"<<H.deluxeRoomPrice<<endl;
}void Travel::Display2()
{
cout<<"Resort information:"<<endl;
cout<<"City Name:"<<R.cityName<<endl;
cout<<"Resort Name:"<<R.resortName<<endl;
cout<<"Resort ID:"<<R.resortID<<endl;
cout<<"Resort Price:"<<R.resortPrice<<endl;
}void Travel::Display3()
{
cout<<"Reservation Number:"<<B.reservationNum<<endl;
cout<<"Client Name:"<<B.clientName<<endl;
cout<<"Contact Tel.:"<<B.contactTel<<endl;
cout<<"E-mail:"<<B.email<<endl;
cout<<"Catergory:"<<B.option<<endl;
}
void displayMain();
int main()
{
displayMain();
return 0;
}
void displayMain()
{
{int selection;
do
{
cout<<"**********MAIN**********"<<endl;
cout<<"1.) Add Hotel Information: " << endl;
cout<<"2.) Add Resort Information:" << endl;
cout<<"3.) Add New Booking:" << endl;
cout<<"4.) View Hotel Information:"<<endl;
cout<<"5.) View Resort Information:"<<endl;
cout<<"6.) View Booking Information:"<<endl;
cout<<"7.) EXIT" << endl;
cout << "Selection: ";
cin >> selection;
}
while (selection <= 0 && selection >= 7);switch (selection)
{
case 1:
P.Hotelinput();
break;
case 2:
P.Resortinput();
break;
case 3:
P.Bookinginput();
break;
case 4:
P.Display1();
case 5:
P.Display2();
case 6:
P.Display3();case 7://leave blank
default:
;
}
}
}

You need to either:
A: Wrap your menu and your select case in a loop
B: Have your displayMain() return the value of your selection, and place the loop in your main() function.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |