Box Office Ticket Sales

This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (3) was titled “Expressions and Interactivity”.

I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions are indexed by search engines, so that other beginning programmers may get help if they need it.

3.5: 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 profit 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 the example (pictured in book, faithfully recreated in my programming example). Assume the theater keeps 20% of the gross box office profit.

My solution:

/* Chapter 3 Challenge 5
Written by Kirk Hingsberger
September 26, 2007
Box Office
*/

#include
#include
#include
using namespace std;

int main()
{
char movieTitle[50];
const float PRICE_ADULT = 6.0;
const float PRICE_KID = 3.0;
const float REV_THEATER = .2;
const float REV_DISTRIBUTOR = .8;
int soldAdult, soldKid;
float grossAdult, grossKid;
float profitGross, profitNet, royalty;

cout << "What was the movie name?" << endl;
cin.getline(movieTitle, 50);

cout << "How many adult tickets were sold?" << endl;
cin >> soldAdult;
cout << "How many kid tickets were sold?" << endl;
cin >> soldKid;

cout << setprecision(2) << fixed;

grossAdult = soldAdult * PRICE_ADULT;
grossKid = soldKid * PRICE_KID;

profitGross = grossAdult + grossKid;
profitNet = profitGross * REV_THEATER;
royalty = profitGross * REV_DISTRIBUTOR;

cout << left << setw(32) << "Movie Name: ";
cout << setw(50) << movieTitle << endl;

cout << left << setw(32) << "Adult Tickets Sold: ";
cout << " " << setw(10) << soldAdult << endl;

cout << setw(32) << "Child Tickets Sold: ";
cout << " " << setw(10) << soldKid << endl;

cout << setw(32) << "Gross Box Office Profit: ";
cout << right << setw(1) << "$" << setw(8) << profitGross << endl;

cout << left << setw(32) << "Net Box Office Profit: ";
cout << right << setw(1) << "$" << setw(8) << profitNet << endl;

cout << left << setw(32) << "Amount Paid to Distributor: ";
cout << right << setw(1) << "$" << setw(8) << royalty << endl;

return 0;
}

Here is the capture script I turned in for grading:

Script started on Thu 27 Sep 2007 01:22:56 PM MDT
$ cat chap3chlg5.cc
/* Chapter 3 Challenge 5
Written by Kirk Hingsberger
September 26, 2007
Box Office
*/

#include
#include
#include
using namespace std;

int main()
{
char movieTitle[50];
const float PRICE_ADULT = 6.0;
const float PRICE_KID = 3.0;
const float REV_THEATER = .2;
const float REV_DISTRIBUTOR = .8;
int soldAdult, soldKid;
float grossAdult, grossKid;
float profitGross, profitNet, royalty;

cout << "What was the movie name?" << endl;
cin.getline(movieTitle, 50);

cout << "How many adult tickets were sold?" << endl;
cin >> soldAdult;
cout << "How many kid tickets were sold?" << endl;
cin >> soldKid;

cout << setprecision(2) << fixed;

grossAdult = soldAdult * PRICE_ADULT;
grossKid = soldKid * PRICE_KID;

profitGross = grossAdult + grossKid;
profitNet = profitGross * REV_THEATER;
royalty = profitGross * REV_DISTRIBUTOR;

cout << left << setw(32) << “Movie Name: “;
cout << setw(50) << movieTitle << endl;

cout << left << setw(32) << “Adult Tickets Sold: “;
cout << ” ” << setw(10) << soldAdult << endl;

cout << setw(32) << “Child Tickets Sold: “;
cout << ” ” << setw(10) << soldKid << endl;

cout << setw(32) << “Gross Box Office Profit: “;
cout << right << setw(1) << “$” << setw(8) << profitGross << endl;

cout << left << setw(32) << “Net Box Office Profit: “;
cout << right << setw(1) << “$” << setw(8) << profitNet << endl;

cout << left << setw(32) << “Amount Paid to Distributor: “;
cout << right << setw(1) << “$” << setw(8) << royalty << endl;

return 0;
}
$ g++ -o chap3chlg5 chap3chlg5.cc -s
$ chap3chlg5
What was the movie name?
Gone with the Wind
How many adult tickets were sold?
100
How many kid tickets were sold?
200
Movie Name: Gone with the Wind
Adult Tickets Sold: 100
Child Tickets Sold: 200
Gross Box Office Profit: $ 1200.00
Net Box Office Profit: $ 240.00
Amount Paid to Distributor: $ 960.00
$ exit
exit

Script done on Thu 27 Sep 2007 01:23:40 PM MDT

  • Share/Bookmark




Leave a Reply