fork download
  1. //Chloe Yau CIC5 Chapter 3, P. 143, #2
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * COMPUTE STADIUM SEATS
  6.  * _____________________________________________________________________________
  7.  * This program calculates how much money the stadium made from ticket sales for
  8.  * three classes of seats Class A, Class B, and Class C.
  9.  * _____________________________________________________________________________
  10.  * INPUT
  11.  * classA_price : Class A seats cost $15
  12.  * classB_price : Class B seats cost $12
  13.  * classC_price : Class C seats cost $9
  14.  * classA_tickets : Class A seats have 20
  15.  * classB_tickets : Class B seats have 30
  16.  * classC_tickets : Class C seats have 40
  17.  * OUTPUT
  18.  * total_income_A : Sales from section A
  19.  * total_income_B : Sales from section B
  20.  * total_income_C : Sales from section C
  21.  * total_income : Total income generated from ticket sales
  22.  *
  23.  ******************************************************************************/
  24. #include <iostream>
  25. #include <iomanip>
  26.  
  27. using namespace std;
  28.  
  29. int main()
  30. {
  31. // Prices for each class of seats
  32. const float classA_price = 15.00;
  33. const float classB_price = 12.00;
  34. const float classC_price = 9.00;
  35.  
  36. // Number of seats in each class (fixed values)
  37. const int classA_seats = 20;
  38. const int classB_seats = 30;
  39. const int classC_seats = 40;
  40.  
  41. // Number of tickets sold for each class (hard-coded values)
  42. int classA_tickets = 50; // Example value
  43. int classB_tickets = 75; // Example value
  44. int classC_tickets = 100; // Example value
  45.  
  46. // Variables to store the total income from ticket sales for each class
  47. float total_income_A;
  48. float total_income_B;
  49. float total_income_C;
  50. float total_income;
  51.  
  52. // Calculate the total income for each class
  53. total_income_A = classA_tickets * classA_price;
  54. total_income_B = classB_tickets * classB_price;
  55. total_income_C = classC_tickets * classC_price;
  56.  
  57. // Calculate the total income from all tickets sold
  58. total_income = total_income_A + total_income_B + total_income_C;
  59.  
  60. // Display the total income with 2 decimal places
  61. cout << fixed << setprecision(2);
  62. cout << "\nTotal income generated from Class A tickets: $" << total_income_A;
  63. cout << "\nTotal income generated from Class B tickets: $" << total_income_B;
  64. cout << "\nTotal income generated from Class C tickets: $" << total_income_C;
  65. cout << "\nTotal income from all ticket sales: $" << total_income << endl;
  66.  
  67. return 0;
  68. }
  69.  
Success #stdin #stdout 0.01s 5268KB
stdin
Standard input is empty
stdout
Total income generated from Class A tickets: $750.00
Total income generated from Class B tickets: $900.00
Total income generated from Class C tickets: $900.00
Total income from all ticket sales: $2550.00