fork(1) download
  1. // Nicolas Ruano CS1A Chapter 3, Pp. 143, #5
  2. /*******************************************************************************
  3.  * CALCULATING THE BOX OFFICE AND THE TICKET PRICES
  4.  * ____________________________________________________________________________
  5.  * This program calculates the revenue from adult and child tickets sold,
  6.  * and determines the theater’s profit and the distributor’s share.
  7.  *
  8.  * FORMULAS:
  9.  * total = (adult_tkt * ADULT_PRICE) + (child_tkt * CHILD_PRICE)
  10.  * theater_profit = total * PROFIT
  11.  * distributor_profit = total - theater_profit
  12.  * ____________________________________________________________________________
  13.  * INPUT
  14.  * adult_tkt : Number of adult tickets sold
  15.  * child_tkt : Number of child tickets sold
  16.  * movie_name : Name of the movie
  17.  *
  18.  * OUTPUT
  19.  * total : Total money earned from ticket sales
  20.  * theater_profit : Profit kept by the theater
  21.  * distributor_profit : Profit given to the distributor
  22.  ******************************************************************************/
  23. #include <iostream>
  24. #include <iomanip>
  25. #include <string>
  26. using namespace std;
  27.  
  28. int main() {
  29. // CONSTANT VARIABLES
  30. const float ADULT_PRICE = 6.00;
  31. const float CHILD_PRICE = 3.00;
  32. const float PROFIT = 0.20; // Theater keeps 20%
  33.  
  34. // Variables
  35. string movie_name;
  36. int adult_tkt, child_tkt; //Var_1
  37. float total, theater_profit, distributor_profit; //Var_2
  38.  
  39. // Ask the name of the movie
  40. cout << "What is the name of the movie? ";
  41. getline(cin, movie_name);
  42.  
  43. // Ask how many tickets are sold
  44. cout << "How many adult tickets were sold? "; //Amount of Adult tkts sold
  45. cin >> adult_tkt;
  46. cout << "How many child tickets were sold? "; //Amount of Child tkts sold
  47. cin >> child_tkt;
  48.  
  49. // INPUT -- Calculate totals
  50. total = (adult_tkt * ADULT_PRICE) + (child_tkt * CHILD_PRICE);
  51. theater_profit = total * PROFIT;
  52. distributor_profit = total - theater_profit;
  53.  
  54. // OUTPUT - Display Results
  55. cout << fixed << setprecision(2);
  56. cout << "\nMovie Name: \"" << movie_name << "\"" << endl;
  57. cout << "Adult Tickets Sold: " << setw(10) << adult_tkt << endl;
  58. cout << "Child Tickets Sold: " << setw(10) << child_tkt << endl;
  59. cout << "Total Box Office: $" << setw(10) << total << endl;
  60. cout << "Theater Profit: $" << setw(10) << theater_profit << endl;
  61. cout << "Distributor Profit: $" << setw(10) << distributor_profit << endl;
  62.  
  63. return 0;
  64. }
  65.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
What is the name of the movie? How many adult tickets were sold? How many child tickets were sold? 
Movie Name: ""
Adult Tickets Sold:               2
Child Tickets Sold:               0
Total Box Office:        $     12.00
Theater Profit:          $      2.40
Distributor Profit:      $      9.60