Stadium Seating
This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (3) was titled “Expressions and Interactivity”.
3.2: There are three seating categories at a stadium. For a softball game, Class A seats cost $15, Class B seats cost $12, and Class C seats cost $9. Write a program that asks how many tickets for each class of seats were sold, then displays the amount of income generated from ticket sales.
My solution (with the professor’s instruction to not worry about fixed-point notation yet):
/* Chapter 3 Challenge 2
Written by Kirk Hingsberger
September 18, 2007
Stadium Seating
*/
#include
using namespace std;
int main()
{
const float PRICE_A = 15;
const float PRICE_B = 12;
const float PRICE_C = 9;
float qtyA, qtyB, qtyC, revA, revB, revC, revTotal;
cout << "How many Class A seats ($" << PRICE_A << ") were sold? ";
cin >> qtyA;
cout << "How many Class B seats ($" << PRICE_B << ") were sold? ";
cin >> qtyB;
cout << "How many Class C seats ($" << PRICE_C << ") were sold? ";
cin >> qtyC;
revA = qtyA * PRICE_A;
revB = qtyB * PRICE_B;
revC = qtyC * PRICE_C;
revTotal = revA + revB + revC;
cout << "Class A seats generated total revenue of $" << revA << endl;
cout << "Class B seats generated total revenue of $" << revB << endl;
cout << "Class C seats generated total revenue of $" << revC << endl;
cout << "Total revenue from all seat sales was $" << revTotal << endl;
return 0;
}
Here is the capture script I turned in for grading:
Script started on Thu 20 Sep 2007 09:42:48 AM MDT
$ cat chap3chlg2.cc
/* Chapter 3 Challenge 2
Written by Kirk Hingsberger
September 18, 2007
Stadium Seating
*/
#include
using namespace std;
int main()
{
const float PRICE_A = 15;
const float PRICE_B = 12;
const float PRICE_C = 9;
float qtyA, qtyB, qtyC, revA, revB, revC, revTotal;
cout << "How many Class A seats ($" << PRICE_A << ") were sold? ";
cin >> qtyA;
cout << "How many Class B seats ($" << PRICE_B << ") were sold? ";
cin >> qtyB;
cout << "How many Class C seats ($" << PRICE_C << ") were sold? ";
cin >> qtyC;
revA = qtyA * PRICE_A;
revB = qtyB * PRICE_B;
revC = qtyC * PRICE_C;
revTotal = revA + revB + revC;
cout << “Class A seats generated total revenue of $” << revA << endl;
cout << “Class B seats generated total revenue of $” << revB << endl;
cout << “Class C seats generated total revenue of $” << revC << endl;
cout << “Total revenue from all seat sales was $” << revTotal << endl;
return 0;
}
$ g++ -o chap3chlg2 chap3chlg2.cc -s
$ chap3chlg2
How many Class A seats ($15) were sold? 1
How many Class B seats ($12) were sold? 1
How many Class C seats ($9) were sold? 1
Class A seats generated a total revenue of $15
Class B seats generated a total revenue of $12
Class C seats generated a total revenue of $9
Total revenue from all seat sales was $36
$ exit
exit
Script done on Thu 20 Sep 2007 09:43:49 AM MDT










