Question

In: Computer Science

3. Write a C++ program to choose one of the following five options for your summer...

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.


you pick the charge rate per company

Solutions

Expert Solution

(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;

}

  • As asked in the question, the charges per company are decided by the program itself. The 2-dimensional array "fares" represents the charges for all the destinations for all the airlines. 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.
  • Next, the program asks the user to choose the destination. The destination number is stored in the variable destination.
  • Next, the program asks the user to choose the airline. The airline number is stored in the variable airline.
  • Now, the program asks the user to enter the number of passengers. This information is stored in the variable n.
  • The fare for the round trip is now calculated by the formula: total_fare = n * fares[airline-1][destination-1]
  • We have subtracted 1 from both airline and destination because the array index starts from 0 and not 1.
  • The quantity fares[airline-1][destination-1] gives the charges of the "airline" airline for the "destination" destination.
  • The total fare is being printed on the screen.

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.


Related Solutions

Write a C++ program to choose one of the following five options for your summer vacation...
Write a C++ program to choose one of the following five options for your summer vacation Hawaii Bahamas Cancun Las Vegas 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: US Air Delta Southwest Continental American Airline Once the airline is selected then read number of passengers airfare for round trip. Calculate the total charge. make your own charges
write a complete C++ program that allows the user to choose from one of several options....
write a complete C++ program that allows the user to choose from one of several options. The program will display a menu and each option will be in a separate function. The program will continue looping until the user chooses to quit. The module descriptions are given below. a. Prompt for and take as input 3 floating point values (l, w, and h). The program will then calculate the volume (volume = l*h*w ). The program should then output to...
Write a java program that will first display the following menu: Choose one of the following...
Write a java program that will first display the following menu: Choose one of the following 1- To add 2 double integers 2- To add 2 integer numbers 3- To add 3 double numbers 4- To add 3 integer numbers After reading user’s choice, use a switch case statement to call the corresponding method Void add 1 (double n1, double n2) Void add2() Double add3 (double n1, double n2, double n3) Double add4 ()
Choose one (1) and only one of the following three 3 assignment options. Investigate and document...
Choose one (1) and only one of the following three 3 assignment options. Investigate and document your response. Provide your response back in this document, and SUBMIT it back using Google Classroom once completed. Alternative Options list: 1. Information Systems roles and jobs 2. Personal Use of Technology 3. Database creation Details are provided below: 1. Information Systems roles and jobs: Prepare a report on purchasing a computer for yourself. Identify your requirements (what you will need to use it...
3. Write a C++ program that takes in the name of a store, and the following...
3. Write a C++ program that takes in the name of a store, and the following details for 4 employees working at the store; their first name, last name, number of hours they worked that week and how much they are paid per hour. Your program should output the name of the store, along with each employee's full name and how much they earned that week in the manner below. Monetary values should be format to 2 decimal places. Also...
In C program #include<stdio.h> You found an exciting summer job for five weeks. Suppose that the...
In C program #include<stdio.h> You found an exciting summer job for five weeks. Suppose that the total tax you pay on your summer job income is 14%. After paying the taxes, you spend: You spend 10% of your net income to buy new clothes and other accessories for the next school year You 1% to buy school supplies AFTER buying clothes and school supplies, you save 25% of the remaining money For each dollar you save, your parents add $0.50...
Please write program in C++ format: Write a program to accept five negative numbers from the...
Please write program in C++ format: Write a program to accept five negative numbers from the user. (1) Find the average of the five numbers and display the answer to the standard output. Keep the answer two decimal points - 5 points (2) Output the numbers in ascending order and display the answer to the standard output. - 5 points
I need to write a program in C with the following specification * ​​​​​​​Line one of...
I need to write a program in C with the following specification * ​​​​​​​Line one of the standard input will have the total number of people which must not be greater than 10 * Each of the subsequent lines of input will be the first name of a person and their number (ex. "Adam 85") one space between name and number * Each name must be a maximum of 14 characters * Put the first names into an array called...
in java Write a Java Program that displays a menu with five different options: 1. Lab...
in java Write a Java Program that displays a menu with five different options: 1. Lab Test Average Calculator 2. Dice Roll 3. Circle Area Calculator 4. Compute Distance 5. Quit The program will display a menu with each of the options above, and then ask the user to enter their choice. There is also a fifth option to quit, in which case, the program will simply display a goodbye message. Based on the user’s choice, one of the options...
Write a menu program to have the above options for the polynomials. Your menu program should...
Write a menu program to have the above options for the polynomials. Your menu program should not use global data; data should be allowed to be read in and stored dynamically. Test your output with the data below. Poly #1: {{2, 1/1}, {1, 3/4}, {0, 5/12}} Poly #2: {{4, 1/1}, {2, -3/7}, {1, 4/9}, {0, 2/11}} provide a C code (only C please) that gives the output below: ************************************ *         Menu HW #4 * * POLYNOMIAL OPERATIONS * * 1....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT