Question

In: Computer Science

QUESTION 1a A valid selection must be between 0 and 4. Enter the program below and...

QUESTION 1a

A valid selection must be between 0 and 4. Enter the program below and complete the while loop. Name the program question1.cpp, compile and run it.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// Fill in the code to define an integer variable called selection
cout << "Please enter the choice of ticket "
<< "(a number from 1 to 4 or 0 to quit) " << endl;
cout << "Ticket Menu " << endl << endl;
cout << "1: Exclusive VIP area A " << endl;
cout << "2: VIP area B " << endl;
cout << "3: Elevated area " << endl;
cout << "4: General area R600 " << endl;
cout << "0: QUIT " << endl <<endl << endl;
cin >> selection ;
while (…………………) //complete the condition

{
cout << “Invalid choice – Please re-enter “;
cin >> selection;
}
cout << “You have selected option number “ << selection;
return 0;
}

QUESTION 1b

Modify question1.cpp by adding the code to calculate the cost per order. Make use of a switch statement.
cout << "You have selected option number "“ <<;
cout << "How many tickets would you like?" << endl;
// Fill in the code to read in number
// Fill in the code to begin a switch statement
// that is controlled by selection
{
case 1: cost = number * 3000;
cout << "The total cost is R " << cost << endl;
break;
// Fill in the code for the case VIP area B ( R2000.00 each)
// Fill in the code for the case Elevated area (R1200.00 each)
// Fill in the code for the case General area (R600.00 each)
case 0: cout << " Please come again" << endl;
break;
default:
cout << “Invalid selection”
cout << " Try again please" << endl;
}

Solutions

Expert Solution

Solution(1a):

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

int selection;

cout << "Please enter the choice of ticket "

<< "(a number from 1 to 4 or 0 to quit) " << endl;

cout << "Ticket Menu " << endl << endl;

cout << "1: Exclusive VIP area A " << endl;

cout << "2: VIP area B " << endl;

cout << "3: Elevated area " << endl;

cout << "4: General area R600 " << endl;

cout << "0: QUIT " << endl <<endl << endl;

cin >> selection ;

while (selection<0 || selection>4) //complete the condition

{

cout << "Invalid choice - Please re-enter";

cin >> selection;

}

cout << "You have selected option number " << selection;

return 0;

}

Output:

Solution(1b):

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

int selection,cost,number;

cout << "Please enter the choice of ticket "

<< "(a number from 1 to 4 or 0 to quit) " << endl;

cout << "Ticket Menu " << endl << endl;

cout << "1: Exclusive VIP area A " << endl;

cout << "2: VIP area B " << endl;

cout << "3: Elevated area " << endl;

cout << "4: General area R600 " << endl;

cout << "0: QUIT " << endl <<endl << endl;

cin >> selection ;

while (selection<0 || selection>4) //complete the condition

{

cout << "Invalid choice - Please re-enter";

cin >> selection;

}

cout << "You have selected option number " << selection;

cout << "\nHow many tickets would you like?" << endl;

cin>>number;

switch(selection)

{

case 1: cost = number * 3000;

cout << "The total cost is R " << cost << endl;

break;

case 2: cost = number * 2000;

cout << "The total cost is R " << cost << endl;

break;

case 3: cost = number * 1200;

cout << "The total cost is R " << cost << endl;

break;

case 4: cost = number * 600;

cout << "The total cost is R " << cost << endl;

break;

case 0: cout << " Please come again" << endl;

break;

default:

cout << "Invalid selection";

cout << " Try again please" << endl;

}

return 0;

}

Output:


Related Solutions

Write a program and ask a user to enter a numeric value between 0 - 99....
Write a program and ask a user to enter a numeric value between 0 - 99. Your program will spell out the numbers into words. You must use at least three switch cases in addition to multiple if statements. Each missing switch statement will reduce your grade for this problem by 20%. Note: The total number of if statements and switch cases should not exceed 28. Additional if/case statement will further reduce your grade by 5%. in c++ please
Question : Write a C program that asks the user to enter an integer between 1...
Question : Write a C program that asks the user to enter an integer between 1 and 7 that represents a weekday number (1 = Sunday, 2 = Monday , …… , 6 = Friday , 7 = Saturday) and it prints the day (i.e., Sunday, Monday, …… , Friday or Saturday). The program continuously asks the user to enter a weekday number till the user responds by ‘N’. and give me an output please use printf and scanf #include...
Program must be in C Write a program that allows the user to enter the last...
Program must be in C Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate in two different arrays. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. Example (Letters and numbers with underscore indicate an input):...
You must prompt the user to enter a menu selection. The menu will have the following...
You must prompt the user to enter a menu selection. The menu will have the following selections (NOTE: all menu selections by the user should not be case sensitive): 1. ‘L’ – Length a. Assume that a file containing a series of names is called names.txt and exists on the computer’s disk. Read that file and display the length of each name in the file to the screen. Each name’s middle character or characters should be displayed on a line...
Run the program and enter domain names to validate. Note that even valid input is flagged...
Run the program and enter domain names to validate. Note that even valid input is flagged as invalid. Change the program to validate a domain name. A valid domain name for this program has a second-level domain followed by a core gTLD. Run the program again. import java.util.Scanner; public class CoreGtldValidation {    public static void main (String [ ] args) { Scanner scnr = new Scanner(System.in); String coreGtld1; String coreGtld2; String coreGtld3; String coreGtld4; String inputName; String searchName; String...
Java Program 1. Write a program that asks the user: “Please enter a number (0 to...
Java Program 1. Write a program that asks the user: “Please enter a number (0 to exit)”. Your program shall accept integers from the user (positive or negative), however, if the user enters 0 then your program shall terminate immediately. After the loop is terminated, return the total sum of all the previous numbers the user entered. a. What is considered to be the body of the loop? b. What is considered the control variable? c. What is considered to...
As we enter the systems integration selection phase, we must select the technical integration framework, and...
As we enter the systems integration selection phase, we must select the technical integration framework, and describe and illustrate our systems integration architecture. For this assignment, share how you think integration frameworks typical to the systems integration selection phase are best used to represent an integration of your system components.
Problem 4 : Write a program that prompts the user to enter in an integer and...
Problem 4 : Write a program that prompts the user to enter in an integer and then prints as shown in the example below Enter an integer 5 // User enters 5 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 Bye
Complete Question 1a-c 1a) Write a C program that displays all the command line arguments that...
Complete Question 1a-c 1a) Write a C program that displays all the command line arguments that appear on the command line when the program is invoked. Use the file name cl.c for your c program. Test your program with cl hello goodbye and cl 1 2 3 4 5 6 7 8 and cl 1b) Write a C program that reads in a string from the keyboard. Use scanf with the conversion code %s. Recall that the 2nd arg in...
In this program, the user will enter some permutation of the integers 0 to n-1, inclusive,...
In this program, the user will enter some permutation of the integers 0 to n-1, inclusive, (each integer in that range will appear exactly once) followed by -1 to indicate the end of the input. The user will never input more than 100 numbers. Your job is to store all the numbers in an array in the order they are input. For example if the user inputs 3 0 2 1 -1 then you should store the 3 at index...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT