fork download
  1. //Devin Scheu CS1A Chapter 3, P. 143, #5
  2. //
  3. /**************************************************************
  4. *
  5. * CALCULATE BOX OFFICE PROFIT
  6. * ____________________________________________________________
  7. * This program calculates the gross and net box office profit
  8. * for a movie theater based on adult and child ticket sales.
  9. * The theater keeps 20% of the gross profit, and the rest goes
  10. * to the distributor.
  11. *
  12. * Computation is based on the formulas:
  13. * grossProfit = (adultTickets * 6.00) + (childTickets * 3.00)
  14. * netProfit = grossProfit * 0.20
  15. * distributorProfit = grossProfit - netProfit
  16. * ____________________________________________________________
  17. * INPUT
  18. * movieName : Name of the movie (as a string)
  19. * adultTickets : Number of adult tickets sold (as an integer)
  20. * childTickets : Number of child tickets sold (as an integer)
  21. *
  22. * PROCESSING
  23. * grossProfit : Total revenue from ticket sales (in dollars)
  24. * distributorProfit : Amount paid to the movie distributor (in dollars)
  25. *
  26. * OUTPUT
  27. * netProfit : Theater's profit after distributor's share (in dollars)
  28. *
  29. **************************************************************/
  30.  
  31. #include <iostream>
  32. #include <iomanip>
  33. #include <string>
  34.  
  35. using namespace std;
  36.  
  37. int main () {
  38.  
  39. //Variable Declarations
  40. string movieName; //INPUT - Name of the movie (as a string)
  41. int adultTickets; //INPUT - Number of adult tickets sold (as an integer)
  42. int childTickets; //INPUT - Number of child tickets sold (as an integer)
  43. double grossProfit; //PROCESSING - Total revenue from ticket sales (in dollars)
  44. double netProfit; //OUTPUT - Theater's profit after distributor's share (in dollars)
  45. double distributorProfit; //PROCESSING - Amount paid to the movie distributor (in dollars)
  46.  
  47. //Prompt for Input
  48. cout << "Enter the name of the movie: ";
  49. getline(cin, movieName);
  50. cout << "\nEnter the number of adult tickets sold: ";
  51. cin >> adultTickets;
  52. cout << "\nEnter the number of child tickets sold: ";
  53. cin >> childTickets;
  54.  
  55. //Calculate Gross Profit
  56. grossProfit = (adultTickets * 6.00) + (childTickets * 3.00);
  57.  
  58. //Calculate Net Profit and Distributor Profit
  59. netProfit = grossProfit * 0.20; // 20% of gross profit
  60. distributorProfit = grossProfit - netProfit;
  61.  
  62. //Output Result
  63. cout << fixed << setprecision(2);
  64. cout << "\n";
  65. cout << left << setw(25) << "Movie Name:" << right << setw(15) << "\"" << movieName << "\"" << endl;
  66. cout << left << setw(25) << "Adult Tickets Sold:" << " " << right << setw(12) << adultTickets << endl;
  67. cout << left << setw(25) << "Child Tickets Sold:" << " " << right << setw(12) << childTickets << endl;
  68. cout << left << setw(25) << "Gross Box Office Profit:" << right << setw(15) << "$ " << grossProfit << endl;
  69. cout << left << setw(25) << "Net Box Office Profit:" << right << setw(15) << "$ " << netProfit << endl;
  70. cout << left << setw(25) << "Amount Paid to Distributor:" << right << setw(15) << "$ " << distributorProfit << endl;
  71.  
  72. } //end of main()
Success #stdin #stdout 0.01s 5320KB
stdin
Wheels of Fury
382
127
stdout
Enter the name of the movie: 
Enter the number of adult tickets sold: 
Enter the number of child tickets sold: 
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