Question

In: Computer Science

Overview For this program, add code to program 2 that will (potentially) allow for a discount...

Overview

For this program, add code to program 2 that will (potentially) allow for a discount to be applied to the cost of the tickets to the movie theater.

Basic Program Logic

The program should start the same as program 2 by asking the user for the number of tickets to purchase for adult and children.

The program should then ask the user if they have a discount coupon. This is a string value. A value of "Y" indicates the user does have a coupon. Any other value indicates the user does not have a coupon.

If the user does have a discount coupon, ask if the coupon is for a free adult ticket or free child ticket. This is also a string value. A value of "A" is for a free adult ticket which means that a discount of 11.25 should be applied to total purchase. A value of "C" is for a free child ticket which means that a discount of 4.50 should be applied to the total purchase. Any other value is invalid which means that no discount should be applied to the total purchase. If an invalid discount type is selected, display a message to the user that their discount type is not valid and that no discount will be applied.

Calculate the user's total purchase amount, making sure to apply the appropriate discount amount (11.25, 4.50, or 0.00).

Finally, display the results similar to program 2: the number of adult tickets that were purchased, the number of child tickets that were purchased, the discount amount (if a discount was applied to the purchase), and the total purchase amount. The discount amount should ONLY be displayed if the user indicated they had a discount coupon. As with program 2, use setw to line up the last digit of the displayed values and setprecision to display 2 digits after the decimal point.

Program Requirements

  1. At the top of the C++ source code, include a documentation box that resembles the one from programs 1 and 2.

  2. The dollar amounts should all be displayed with exactly 2 digits after the decimal point, including zeros.

  3. The numeric values read in from the user should all be integer values. The discount values read in from the user should all be string values. Use meaningful variable names.

  4. Make sure and test the program with values other than those in the sample output.

Output

A few runs of the program should produce the following results:

Run 1

Enter the number of adult tickets that are being purchased: 2
Enter the number of child tickets that are being purchased: 5

Do you have a discount coupon (Y for yes)? Y

Is the discount for an adult or child's ticket (A for adult, C for child)? C


************************************
           Theater Sale
************************************
Number of adult tickets:           2
Number of child tickets:           5

Discount:                       4.50

Total purchase:                40.50

Run 2

Enter the number of adult tickets that are being purchased: 1
Enter the number of child tickets that are being purchased: 2

Do you have a discount coupon (Y for yes)? n


************************************
           Theater Sale
************************************
Number of adult tickets:           1
Number of child tickets:           2

Total purchase:                20.25

Run 3

Enter the number of adult tickets that are being purchased: 2
Enter the number of child tickets that are being purchased: 2

Do you have a discount coupon (Y for yes)? Y

Is the discount for an adult or child's ticket (A for adult, C for child)? S
Error: S is not a valid discount type. No discount will be applied

************************************
           Theater Sale
************************************
Number of adult tickets:           2
Number of child tickets:           2

Discount:                       0.00

Total purchase:                31.50

Run 4

Enter the number of adult tickets that are being purchased: 4
Enter the number of child tickets that are being purchased: 2

Do you have a discount coupon (Y for yes)? Y

Is the discount for an adult or child's ticket (A for adult, C for child)? A


************************************
           Theater Sale
************************************
Number of adult tickets:           4
Number of child tickets:           2

Discount:                      11.25

Total purchase:                42.75

Solutions

Expert Solution

Answer :

please upvote if its upto your expectation or comment for any query.

Program plan :

1. run a while loop to continuously asking for input

2. get input no of adult ticket ,child ticket and store in variables

3. get discount input and check for discount.

4. check discount type A for adult C for child else display error

5. calculate total purchase amount and display

Program :

#include <iostream> //Header File for Basic I/O
#include <iomanip> //Header file for setw()

using namespace std;


const double ChildTicketAmount=4.50; //ticket amount
const double AdultTicketAmount=11.25;
const double InvalidDiscountAmount=0.00;

int main()
{


while(1)
{
int adultTicket=0,childTicket=0; //variable for number of ticket
double totalPurchase=0.0;
char Discount='N',DiscountType='X'; //string input for discount
bool DiscountError=false; //store error of discount type

/*
Program 1 of C++ for getting input of Theatre ticket
here we store adult ticket ,child ticket ,discount type in variable
to calculate in program 2

*/
cout<<"Enter the number of adult tickets that are being purchased:"; //enter no. of adult ticket
cin>>adultTicket;
cout<<"Enter the number of child tickets that are being purchased:"; //enter no. of child ticket
cin>>childTicket;
cout<<"Do you have a discount coupon (Y for yes)?"; //enter discount y for yes and n for no both cases supported
cin>>Discount;
if(Discount=='Y' || Discount=='y') //both cases supported
{

cout<<"Is the discount for an adult or child's ticket (A for adult, C for child)?"; //get discount type
cin>>DiscountType;

switch(DiscountType) //switch for type of discount
{
case 'A':
DiscountError=false;
break;
case 'a':
DiscountError=false;
break;
case 'c':
DiscountError=false;
break;
case 'C':
DiscountError=false;
break;
default:
cout<<"Error: "<<DiscountType << "is not a valid discount type. No discount will be applied"<<endl;
DiscountError=true;
break;

}

}

/*
Program 2
Calculate total ticket amount using variable we get in Program 1 and deduct appropriate discount amount
display no of ticket for adult ,child
display discount amount if have
display total purchase of ticket
*/
cout<<"************************************\n\tTheater Sale\n************************************";
cout <<setprecision(2) << fixed; //set precision for 2 decimal point
totalPurchase=(childTicket*ChildTicketAmount)+(adultTicket*AdultTicketAmount); //calculate total purchase
cout<<endl<<"Number of adult tickets:"<<setw(5)<<adultTicket; //output on screen
cout<<endl<<"Number of child tickets:"<<setw(5)<<childTicket;
if(DiscountType=='C' || DiscountType=='c') //to deduct discount amount
{
cout<<endl<<"Discount Amount:"<<setw(17)<<ChildTicketAmount;
totalPurchase-=ChildTicketAmount; //subtract 4.50
}
else if(DiscountType=='A' || DiscountType=='a') //subtract 11.25
{
cout<<endl<<"Discount Amount:"<<setw(17)<<AdultTicketAmount;
totalPurchase-=AdultTicketAmount;
}
if(DiscountError)
{
cout<<endl<<"Discount Amount:"<<setw(17)<<InvalidDiscountAmount;
}


cout<<endl<<"Total Purchase :"<<setw(17)<<totalPurchase<<endl<<endl<<endl; // display total purchase

}

return 0;
}

Output Images :

Run1

run2

run3

run4


Related Solutions

Please add to this Python, Guess My Number Program. Add code to the program to make...
Please add to this Python, Guess My Number Program. Add code to the program to make it ask the user for his/her name and then greet that user by their name. Please add code comments throughout the rest of the program If possible or where you add in the code to make it ask the name and greet them before the program begins. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the...
Design and implement a program to allow a college administrator to register new students and add...
Design and implement a program to allow a college administrator to register new students and add courses to the existing one. In addition, your program should allow the administrator to do the following: • Add/Remove a new student • Add/Remove a course to/from a selected student • Search for a student either by last name or by id. • Search for a course either by name or by id. • Display a selected student along with the courses s/he is...
make a C++ program to calculate discount for a customer. If customer code equals 1 discount...
make a C++ program to calculate discount for a customer. If customer code equals 1 discount = 5% Any other code discount = 2% Display the discount
CODE IN PYTHON: Your task is to write a simple program that would allow a user...
CODE IN PYTHON: Your task is to write a simple program that would allow a user to compute the cost of a road trip with a car. User will enter the total distance to be traveled in miles along with the miles per gallon (MPG) information of the car he drives and the per gallon cost of gas. Using these 3 pieces of information you can compute the gas cost of the trip. User will also enter the number of...
C++ code Inventory Item Stack You are writing an Inventory program that will allow the user...
C++ code Inventory Item Stack You are writing an Inventory program that will allow the user to enter a part into the inventory, take a part from the inventory, or quit. You are provided with the InvItem class (InvItem.h) and a partial Driver.cpp. You will be creating a DynamicStack class that should implement a Stack data structure. The DynamicClass should be implemented as a template class to allow any data type be added/removed from the stack. You will submit three...
3.) Analyze the Java Program LinkRotator RUN the code and add the screenshot of the window...
3.) Analyze the Java Program LinkRotator RUN the code and add the screenshot of the window and output. Describe what code change you would make if you wanted each link to be displayed for 2.5 seconds. _______________________________________________________________ Below is the "LinkRotator" java program: 1: package com.java24hours; 2: 3: import java.awt.*; 4: import java.awt.event.*; 5: import java.io.*; 6: import javax.swing.*; 7: import java.net.*; 8:    9: public class LinkRotator extends JFrame 10: implements Runnable, ActionListener { 11: 12: String[] pageTitle =...
code in c++ using the code given add a hexadecimal to binary converter and add a...
code in c++ using the code given add a hexadecimal to binary converter and add a binary to hexadecimal converter #include <iostream> #include <string> #include<cmath> #include<string> using namespace std; int main() { string again; do { int userChoice; cout << "Press 2 for Decimal to Binary"<< endl; cout << "Press 1 for Binary to Decimal: "; cin >> userChoice; if (userChoice == 1) { long n; cout << "enter binary number" << endl; cin>>n; int decnum=0, i=0, remainder; while(n!=0) {...
1) Credit terms that allow for a 4% discount for early payment : a- 2/10, N/60...
1) Credit terms that allow for a 4% discount for early payment : a- 2/10, N/60 b- n/45 c- FOB destination d- FOB shipping point e- 4/10, N/45 2) Shipping terms that would typically mean that the seller has to pay the freight charges : a- 2/10, N/60 b- n/45 c- FOB destination d- FOB shipping point e- 4/10, N/45 3) Credit terms that allow for a 2% discount for early payment: a- 2/10, N/60 b- n/45 c- FOB destination...
The code must be under c++ program. For your Double and Integer classes add a default...
The code must be under c++ program. For your Double and Integer classes add a default constructor that sets the value to 0.0 and 0 respectively. Then add the following overloaded constructors Double class A Double argument A primitive double An Integer class Integer class An Integer class A primitive int Each of these constructors should set the data section of the class to the value being passed to it. In addition to the overloaded constructors add the following overloaded...
In C++ 2. Test Scores #2 Modify the program #1 to allow the user to enter...
In C++ 2. Test Scores #2 Modify the program #1 to allow the user to enter name-score pairs. For each student taking a test, the user types a string representing the name of the student, followed by an integer representing the student's score. (use a structure) Modify the average-calculating function so they take arrays of structures, with each structure containing the name and score of a single student. In traversing the arrays, use pointers notation rather than array indices. (myArray->name...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT