This is for a c++ program. I have most of the program done, but I need to create
ID: 3570309 • Letter: T
Question
This is for a c++ program. I have most of the program done, but I need to create a menu in the int main () portion and I don't know how to do that. I have posted what I have so far and the assignment.
#include <iostream>
#include <string>
using namespace std;
class TravelInfo
{
string DestinationName;
int TravelDays;
double TripCost;
void setDestinationName(string Destination)
{
DestinationName = Destination;
}
string getDestinationName()
{
return DestinationName;
}
void setTravelDays(int Days)
{
TravelDays = Days;
}
int getTravelDays()
{
return TravelDays;
}
void setTripCost(double Cost)
{
TripCost = Cost;
}
double getTripCost()
{
return TripCost;
}
void operator << (TravelInfo& ob)
{
cout<<"TripCost = "<< ob.TripCost<< endl<< "TravelDays = "<< ob.TravelDays<< endl << "DestinationName = " << ob.DestinationName <<endl;
}
void add_travelDays(int days)
{
TravelDays += days;
TripCost += (days*((TripCost)/(TravelDays)));
}
void add_hotel()
{
cout << "What kind of hotel do you want to stay in? 1) Economy($70/day) 2)Luxury ($180$/day) and 3) Elite ($320/day)";
int ch;
cin >> ch;
switch(ch)
{
case 1:
TripCost += (TravelDays*70);
break;
case 2:
TripCost += (TravelDays*180);
break;
case 3:
TripCost += (TravelDays*320);
break;
default:
cout << "Invalid Choice";
}
}
void rent_a_car( int rentDays)
{
TripCost += (TravelDays*40);
}
friend void CompareTrip(const TravelInfo& tour1 , const TravelInfo& tour2)
{
if(tour1.TripCost > tour2.TripCost)
{
cout <<"The second tour is costlier."<<endl;
}
else if(tour1.TripCost < tour2.TripCost)
{
cout <<"The first tour is costlier."<<endl;
}
else
{
cout << "They both cost the same.";
}
}
TravelInfo()
{
TripCost = 0;
TravelDays = 0;
DestinationName = "";
}
TravelInfo(int days, int cost, string name)
{
TripCost = cost;
TravelDays = days;
DestinationName = name;
}
};
class PassengerDetails
{
string PassengerName;
string Destination;
char Gender;
ifstream in_file;
in_file.open("FileNameXYZ.txt");
if (in_file.fail())
{
cout << "Failed to open file." << endl;
exit(1);
}
int a[20];
int stuff;
int i = 0;
while(in_file >> stuff)
{
a[i] = stuff;
i++;
}
TravelInfo ob1 = new TravelInfo();
TravelInfo ob2 = new TravelInfo();
TravelInfo ob3 = new TravelInfo();
TravelInfo ob4 = new TravelInfo();
ob1.setDestinationName(a[0]);
ob1.setTravelDays(a[1]);
ob1.setTripCost(a[2]);
ob1.setDestinationName(a[3]);
ob1.setTravelDays(a[4]);
ob1.setTripCost(a[5]);
ob1.setDestinationName(a[6]);
ob1.setTravelDays(a[7]);
ob1.setTripCost(a[8]);
ob1.setDestinationName(a[9]);
ob1.setTravelDays(a[10]);
ob1.setTripCost(a[11]);
PassengerDetails passengers[20];
};
bool checkAvailablity(int size,int NumOfPassengers, int MAX_SIZE)
{
if(size + NumOfPassengers < MAX_SIZE)
{
return true;
}
return false;
}
int main ()
{
}
Objectives
To gain more experience with Classes, Friend functions and Overloading Operators.
Problem
For this project you should design and implement an online tourism application for a travel agent
who wants his customers to enquire and book for a tourism package using the application.
Assumptions
1) Our agent has only four destinations for which he can offer services.
2) All the details about the four destinations are provided in the input file
3) The maximum number of passengers the agent can accommodate is 20.
4) Initial price quote available in the file is for 1 person and it does not include accomodation.
5) Every Customer must choose one of the three accommodation options available.
Description:
1) You need to create a class called TravelInfo which has the following members
? DestinationName(String)
? TravelDays(int)
? TripCost(double)
Note : All the above attributes should only be accessible through methods of the TravelInfo class.
? void add_travelDays(int days);
This function should add any additional days that the user wants to add to his tour package
and update the members TravelDays and TripCost accordingly.
? void add_hotel();
This function asks the user for the type of hotel he wishes to stay in and updates the TripCost
based on TravelDays. Our agent offers three different categories of hotels. 1) Economy
($70/day) 2)Luxury ($180$/day) and 3) Elite ($320/day)
? void rent_a_car( int rentDays);
This function asks the user to add any rental car to his package and updates the TripCost
based on rentDays. Our Agent offers a rental car for a cost of $40/day to his customers.
? friend void CompareTrip(const TravelInfo& tour1 , const TravelInfo& tour2);
This is friend function which takes the TravelInfo Objects, compares the TripCost of two
objects and tells the user about the cheapest destination.
ou must write two constructors for the TravelInfo class
? A default constructor
? An overloaded constructor that takes in three parameters and sets the DestinationName,
TravelDays, and TripCost.
You must write one set method (mutator) and get method (accessor) for each of the attributes of the
TravelInfo class.
After you have defined all the members, overload the following operator:
<< - to output all the details of the existing TravelInfo object.
2) You need to create a structure called PassengerDetails with the following members
? PassengerName(string)
? Destination(String)
? Gender(char)
3) Declare a function outside structure:
bool checkAvailablity(int size,int NumOfPassengers, int MAX_SIZE);
This function returns true if the sum of size and NumOfPassengers is less than the MAX_SIZE
Implementation
In the main Program-
1) Create four different objects for the TravelInfo class and read the input file to fill in all the details
of the created objects.
2) Create an array of PassengerDetails objects with a capacity of MAX_SIZE of 20 and a size
variable to keep track of actual elements of the array used
3) Display a menu for the Following options for the user-
? To view all the available tour packages
Display the information of all the available tour packages using the overloaded <<
? To compare two different tour packages
Take the input of two different destinations, and call the friend function CompareTrip() with
appropriate objects as arguments
? Proceed to booking for an available package
a) Ask the user to choose a package based on destination.
b) Add any additional travel days.
c) Give the option to choose the accommodation type. ) Ask the user to choose for the additional features like renting a car.
d) Then ask the user for the number of passengers as input from keyboard and call the
checkAvailablity() function with appropriate arguments .
e) If the function returns true, then read the input for all of the details of the passenger from the
keyboard.
f) Then display the details of all passengers entered by the user on screen for the customer
reference.
g) Finally display total trip cost.
h) If the function returns false, ask the user if he would like to choose a different tour
package.
? Exit
Terminate the program
Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
class TravelInfo
{
string DestinationName;
int TravelDays;
double TripCost;
void setDestinationName(string Destination)
{
DestinationName = Destination;
}
string getDestinationName()
{
return DestinationName;
}
void setTravelDays(int Days)
{
TravelDays = Days;
}
int getTravelDays()
{
return TravelDays;
}
void setTripCost(double Cost)
{
TripCost = Cost;
}
double getTripCost()
{
return TripCost;
}
void operator << (TravelInfo& ob)
{
cout<<"TripCost = "<< ob.TripCost<< endl<< "TravelDays = "<< ob.TravelDays<< endl << "DestinationName = " << ob.DestinationName <<endl;
}
void add_travelDays(int days)
{
TravelDays += days;
TripCost += (days*((TripCost)/(TravelDays)));
}
void add_hotel()
{
cout << "What kind of hotel do you want to stay in? 1) Economy($70/day) 2)Luxury ($180$/day) and 3) Elite ($320/day)";
int ch;
cin >> ch;
switch(ch)
{
case 1:
TripCost += (TravelDays*70);
break;
case 2:
TripCost += (TravelDays*180);
break;
case 3:
TripCost += (TravelDays*320);
break;
default:
cout << "Invalid Choice";
}
}
void rent_a_car( int rentDays)
{
TripCost += (TravelDays*40);
}
friend void CompareTrip(const TravelInfo& tour1 , const TravelInfo& tour2)
{
if(tour1.TripCost > tour2.TripCost)
{
cout <<"The second tour is costlier."<<endl;
}
else if(tour1.TripCost < tour2.TripCost)
{
cout <<"The first tour is costlier."<<endl;
}
else
{
cout << "They both cost the same.";
}
}
TravelInfo()
{
TripCost = 0;
TravelDays = 0;
DestinationName = "";
}
TravelInfo(int days, int cost, string name)
{
TripCost = cost;
TravelDays = days;
DestinationName = name;
}
};
class PassengerDetails
{
string PassengerName;
string Destination;
char Gender;
};
bool checkAvailablity(int size,int NumOfPassengers, int MAX_SIZE)
{
if(size + NumOfPassengers < MAX_SIZE)
{
return true;
}
return false;
}
int main()
{
ifstream in_file;
in_file.open("FileNameXYZ.txt");
if (in_file.fail())
{
cout << "Failed to open file." << endl;
exit(1);
}
int a[20];
int stuff;
int i = 0;
while(in_file >> stuff)
{
a[i] = stuff;
i++;
}
TravelInfo ob1 = new TravelInfo();
TravelInfo ob2 = new TravelInfo();
TravelInfo ob3 = new TravelInfo();
TravelInfo ob4 = new TravelInfo();
ob1.setDestinationName(a[0]);
ob1.setTravelDays(a[1]);
ob1.setTripCost(a[2]);
ob1.setDestinationName(a[3]);
ob1.setTravelDays(a[4]);
ob1.setTripCost(a[5]);
ob1.setDestinationName(a[6]);
ob1.setTravelDays(a[7]);
ob1.setTripCost(a[8]);
ob1.setDestinationName(a[9]);
ob1.setTravelDays(a[10]);
ob1.setTripCost(a[11]);
PassengerDetails passengers[20];
int choice;
do{
cout<<"1-To view all the available tour packages"<<endl;
//Display the information of all the available tour packages using the overloaded <<
cout<<"2-To compare two different tour packages"<<endl;
//Take the input of two different destinations, and call the friend function CompareTrip() with
//appropriate objects as arguments
cout<<"3-Proceed to booking for an available package"<<endl;
cin>>choice;
switch(choice)
{
case 1:
cout<<obj1;
cout<<obj2;
cout<<obj3;
cout<<obj4;
break;
case 2:
string a,b;
cout<<"Enter destination 1?"<<endl;
cin>>a;
cout<<"Enter destination 2?"<<endl;
cin>>b;
TravelInfo tmp1,tmp2;
if(obj1.DestinationName == a)
tmp1 = obj1;
else if(obj2.DestinationName == a)
tmp1 = obj2;
else if(obj3.DestinationNmae == a)
tmp1 = obj3;
else if(obj4.DestinationName == a)
tmp1 = obj4;
if(obj1.DestinationName == b)
tmp2 = obj1;
else if(obj2.DestinationName == b)
tmp2 = obj2;
else if(obj3.DestinationNmae == b)
tmp2 = obj3;
else if(obj4.DestinationName == b)
tmp2 = obj4;
CompareTrip(tmp1,tmp2);
case 3:
int package,rentdays,travelDays,num;
cout<<"1- "<<obj1<<endl;
cout<<"2- "<<obj2<<endl;
cout<<"3- "<<obj3<<endl;
cout<<"4- "<<obj4<<endl;
cout<<"Enter choice"<<endl;
cin>>package;
cout<<"Add travel days?"<<endl;
cin>>travelDays;
cout<<"Rent a car?(Enter days)"<<endl;
cin>>rentdays;
cout<<"Enter number of passengers?"<<endl;
cin>>num;
if(checkAvailablity(20,num,20))
{
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.