In: Computer Science
3. Write a C++ program to choose one of the following five options for your summer vacation 1. Hawaii 2. Bahamas 3. Cancun 4. Las Vegas 5. Europe Your program should select one of the above option. Once the option is selected then your program should select one of the following airlines: 1. US Air 2. Delta 3. Southwest 4. Continental 5. American Airline Once the airline is selected then read number of passengers airfare for round trip. Calculate the total charge.
(Note: The question doesn't exactly tell whether to select the airline and destination randomly or ask it from the user. Thus, I'm assuming that it intends to ask it from the user, which is the more obvious option out of the two.)
The complete C++ program for the given problem is given below:
#include<iostream>
using namespace std;
int main()
{
int fares[][5]={ {140, 120, 190, 165,
178},
{155, 130, 188, 170, 182},
{138, 123, 200, 168, 180},
{142, 128, 200, 172, 176},
{140, 130, 185, 170, 177} };
//fares[0] represents the charges charged by US Air, fares[1] for Delta, fares[2] for Southwest, fares[3] for Continental, and fares[4] for American Airline.
int destination, airline, n,
total_fare;
cout<<"Choose the destination for your summer
vacation:";
cout<<"\n1. Hawaii";
cout<<"\n2. Bahamas";
cout<<"\n3. Cancun";
cout<<"\n4. Las Vegas";
cout<<"\n5. Europe";
cout<<"\n\nEnter your choice (1-5): ";
cin>>destination;
cout<<"\nSelect the airlines you want to travel with:";
cout<<"\n1. US Air";
cout<<"\n2. Delta";
cout<<"\n3. Southwest";
cout<<"\n4. Continental";
cout<<"\n5. American Airline";
cout<<"\n\nEnter your choice (1-5): ";
cin>>airline;
cout<<"Enter the number of passengers: ";
cin>>n;
total_fare = n * fares[airline-1][destination-1];
cout<<"The total fare for round trip for "<<n<<"
passengers is "<<total_fare<<"$.";
return 0;
}
The screenshots of the code are:
The screenshot of the output is:
Hope it helped. If you have any doubts or queries, please feel free to ask in the comments section. If it helped in any way, please consider giving a thumbs up.