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...
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...
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) {...
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...
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...
(Python Code please) Guess the number! You will add to the program you created last week....
(Python Code please) Guess the number! You will add to the program you created last week. This week you will add quite a bit of code to your project. You will add an option for the computer to guess as well as the user to guess a number. In addition, you will add a menu system. Be sure to import random at the beginning of your code and use a comment block explaining what your program does #Guess the number...
**Add comments to existing ARM code to explain steps** Write an ARM assembly program to convert...
**Add comments to existing ARM code to explain steps** Write an ARM assembly program to convert temperatures from Celsius to Fahrenheit or from Fahrenheit to Celsius. Here are the two formulas for your reference. Use variable to read and store values. C= 5* (F - 32) / 9 F = (9 * C / 5 ) + 32 My code below: TempConvert.s LDR R8,=temperature LDR R1,[R8] LDR R8,=unit LDRB R2,[R8] LDR R8,=celsius LDRB R3,[R8] LDR R8,=fahrenheit LDRB R4,[R8] MOV R6,#9...
2. Specification - Given the following code base, add the appropriate function that will give the...
2. Specification - Given the following code base, add the appropriate function that will give the correct results/output. CODE: # TODO : Add Two Missing Functions HERE mlist = [(" Orange ", 10 , 0.25) ,( " Apple ", 5 , .20) , (" Banana ", 2 , 0.3) ,(" Kiwi ", 1 , 0.5)] addFruit (10 ," Lemon " ,0.1) displayFruitList ( mlist ) OUTPUT: Orange --- $ 2.50 Apple --- $ 1.00 Banana --- $ 0.60 Kiwi ---...
For this program you will add and test 2 new member functions to the class in...
For this program you will add and test 2 new member functions to the class in //************************ intSLList.h ************************** // singly-linked list class to store integers #ifndef INT_LINKED_LIST #define INT_LINKED_LIST class IntSLLNode { public: IntSLLNode() { next = 0; } IntSLLNode(int el, IntSLLNode *ptr = 0) { info = el; next = ptr; } int info; IntSLLNode *next; }; class IntSLList { public: IntSLList() { head = tail = 0; } ~IntSLList(); int isEmpty() { return head == 0; }...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT