Programming Challenge Chapter 3 – Q #5 Box Office – Tony Gaddis – Starting Out With C++

Programming Challenge Chapter 3 – Q #5 Box Office – Tony Gaddis – Starting Out With C++

Box Office

Problem: -

A movie theater only keeps a percentage of the revenue earned from ticket sales. The remainder goes to the movie distributor. Write a program that calculates a theater's gross and net box office pro t for a night. The program should ask for the name of the movie, and how many adult and child tickets were sold. (The price of an adult ticket is $6.00 and a child s ticket is $3.00.) It should display a report similar to
Movie Name:                           Wheels of Fury
Adult Tickets Sold:                         382
Child Tickets Sold:                         127
Gross Box Office Profit:              $ 2673.00
Net Box Office Profit:                 $ 534.60
Amount Paid to Distributor:        $ 2138.40

Solution: -

#include <iostream>

#include<string>

using namespace std;

int main()

{

      const float  ADULT = 6,

            CHILD = 3,

            PROFIT_PERCENTAGE = 0.2;

 

      string name;

      float ticket1, ticket2;

      float boxOffice = 0.0, netProfit = 0.0, distributer_ammount = 0.0;

      float adult, child;

 

      cout << "Enter Movie Name: ";

      getline(cin, name);

      cout << "How many Child ticket Sale: ";

      cin >> ticket1;

      cout << "How many Adult ticket Sale: ";

      cin >> ticket2;

 

      child = ticket1 * CHILD;

      adult = ticket2 * ADULT;

 

      boxOffice = child + adult;

      netProfit = boxOffice * PROFIT_PERCENTAGE;

      distributer_ammount = boxOffice - netProfit;

 

      cout << "\nMovie Name:                   " << name << endl;

      cout << "Adult Ticket Sold:              " << ticket2 << endl;

      cout << "Child Ticket Sold:              " << ticket1 << endl;

      cout << "Box Office:                    $" << boxOffice << endl;

      cout << "Net Profit:                    $" << netProfit << endl;

      cout << "Ammount Paid to Distributer:   $" << distributer_ammount << endl;

 

      return 0;

}

This is the solution of this question




OUTPUT OF THIS QUESTION 

Input is highlighted with yellow color.


Explanation of this Solution


  1. Use string header file for string variables.
  2. Declare three float constant and initialize given values.
  3. Declare a string  variable for movie name.
  4. Declare two float variables for tickets input.
  5. Declare three float variables for calculation.
  6. Declare another two float variables for calculation.
  7. Take input of movie name from the user by using cin.
  8. Take input of tickets from the user by using cin.
  9. Calculate child and adult ticket prices.
  10. Calculate profits and distributer amount. 
  11.  In last, display output on the screen.
  12. Return 0 to the main function.

Also, I attach CPP file of this problem. You can download this file

Click Here to Download This File




Thanks!  



Post a Comment

0 Comments