Question

In: Computer Science

Overview For this assignment, write a program that will calculate the amount that a customer spends...

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

  1. 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.

  2. 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.

  3. The calculated dollar amount should be displayed with exactly 2 digits after the decimal point.

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

  5. Make sure and test the program with values other than the ones supplied in the sample output.

  6. 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

Solutions

Expert Solution

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


Related Solutions

Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
Using C++ Write a program to calculate the amount a customer should pay in a checkout...
Using C++ Write a program to calculate the amount a customer should pay in a checkout counter for the purchases in a bagel shop. The products sold are bagels, cream cheese, and coffee. Use the pseudo code discussed in the class to write the program. Make reasonable assumptions about the prices of bagel, cream cheese, and coffee. Declare prices of bagel, cream cheese, and coffee as constants.
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7...
Overview For this assignment, write a program that uses functions to simulate a game of Craps....
Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7 or 11, the...
Overview In this assignment, you will write a program to track monthly sales data for a...
Overview In this assignment, you will write a program to track monthly sales data for a small company. Input Input for this program will come from two different disk files. Your program will read from these files by explicitly opening them. The seller file (sellers.txt) consists of an unknown number of records, each representing one sale. Records consist of a last name, a first name, a seller ID, and a sales total. So, for example, the first few records in...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice is equal to 7 or 11, the player wins immediately....
For this assignment, write a program that will calculate the quiz average for a student in...
For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT