In: Computer Science
Overview
For this assignment, write a program that will calculate the amount that a customer spends on tickets at a movie theater.
This program will be continued in program 3 so it is important that this program is completed.
Basic Program Logic
The basic logic for this program is similar to program 1: the user is asked to enter values, a calculation is performed, and the result of the calculation is displayed.
For this program, prompt the user for the number of adult tickets they would like to purchase. This is an integer value and must be placed into an int variable.
Prompt the user for the number of childrens tickets they would like to purchase. This value should also be placed in an int variable.
Calculate the user's purchase amount using a cost of $11.25 for a single adult ticket and $4.50 for a single child ticket. The purchase amount is the cost of adult tickets plus the cost of childrens tickets.
After the calculation, display the number of adult tickets that were purchased, the number of childrens tickets that were purchased, and the total purchase amount. Use the setw manipulator to line up the last digit of the number of tickets that were purchased and the total purchase amount. The total purchase amount should be displayed with exactly 2 digits after the decimal point, including zeroes.
Program Requirements
At the top of the C++ source code, include a documentation box that resembles the one from program 1.Make sure the Date Due and Purpose are updated to reflect the current program.
Include line documentation. There is no need to document every single line, but logical "chunks" of code should be preceded by a line or two that describes what the "chunk" of code does. This will be a part of every program that is submitted for the remainder of the semester.
The calculated dollar amount should be displayed with exactly 2 digits after the decimal point.
The numeric values read in from the user should all be integer values. Use meaningful variable names.
Make sure and test the program with values other than the ones supplied in the sample output.
Hand in a copy of the source code (CPP file) using Blackboard.
Sample 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 ************************************ Theater Sale ************************************ Number of adult tickets: 2 Number of child tickets: 5 Total purchase: 45.00
Run 2
Enter the number of adult tickets that are being purchased: 1 Enter the number of child tickets that are being purchased: 2 ************************************ 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: 21 Enter the number of child tickets that are being purchased: 0 ************************************ Theater Sale ************************************ Number of adult tickets: 21 Number of child tickets: 0 Total purchase: 236.25
Run 4
Enter the number of adult tickets that are being purchased: 0 Enter the number of child tickets that are being purchased: 0 ************************************ Theater Sale ************************************ Number of adult tickets: 0 Number of child tickets: 0 Total purchase: 0.00
Below is the .CPP code with all the self-explanatory comments required
************************************
//@documentation
//
************************************
#include<bits/stdc++.h> // std template library
#include <iostream>
#include <iomanip> // std::setw
//to store the per ticket prices in constants
#define ADULT_TICKET_PRICE 11.25
#define CHILD_TICKET_PRICE 4.50
using namespace std;
void generateInvoice(int noOfAdultTickets, int
noOfChildTickets){
float costOfAdultTickets = noOfAdultTickets *
ADULT_TICKET_PRICE;
float costOfChildTickets = noOfChildTickets *
CHILD_TICKET_PRICE;
float totalAmount = costOfAdultTickets +
costOfChildTickets;
cout << "\n************************************"
<< endl;
cout << "\t\tTheater Sale" << endl;
cout << "************************************"
<< endl << endl;
cout << "Number of adult tickets:" <<
setw(6) << noOfAdultTickets << endl;
cout << "Number of child tickets:" <<
setw(6) << noOfChildTickets << endl <<
endl;
cout << "Total purchase:" << setw(15)
<< totalAmount;
}
pair<int,int> getUserData(){
int noOfAdultTickets = 0;
int noOfChildTickets = 0;
cout << "Enter the number of adult tickets that
are being purchased:";
cin >> noOfAdultTickets;
cout << "Enter the number of child tickets that
are being purchased:";
cin >> noOfChildTickets;
//return the variables in form of pair so that we can
return 2 values at a time
return make_pair(noOfAdultTickets,
noOfChildTickets);
}
int main() {
// get the Input data from user and we receive the
result in pair
// which can store 2 variables at a time
pair<int,int> ticketCounts =
getUserData();
// this function will calculate the total amount and
print the
// output in the desired format using the setw
manipulator
generateInvoice(ticketCounts.first,
ticketCounts.second);
return 0;
}