fork download
  1. //Amari Mosley CSC5 Chapter 3, P. 143, #5
  2. //
  3. /**************************************************************
  4.  *
  5.  * Box Office
  6.  * ____________________________________________________________
  7.  * This program calculates a theater's gross and net box office
  8.  * profit for a night based on ticket sales.
  9.  *
  10.   Computation is based on the following formulas:
  11.  * Gross Profit = (Adult Tickets * 6.00) + (Child Tickets * 3.00)
  12.  * Net Profit = Gross Profit * 0.20
  13.  * Amount Paid to Distributor = Gross Profit - Net Profit
  14.  * ____________________________________________________________
  15.  * INPUT
  16.  * movieName, adultTickets, childTickets
  17.  * OUTPUT
  18.  * grossProfit, netProfit, amountPaidToDistributor
  19.  *
  20.  **************************************************************/
  21. #include <iostream>
  22. #include <iomanip>
  23. #include <string>
  24. using namespace std;
  25.  
  26. // Defining Main Function
  27. int main() {
  28. // Define variables
  29. string movieName;
  30. int adultTickets, childTickets;
  31. double grossProfit, netProfit, amountPaidToDistributor;
  32.  
  33. // Constants for ticket prices and theater percentage
  34. const double ADULT_TICKET_PRICE = 6.00;
  35. const double CHILD_TICKET_PRICE = 3.00;
  36. const double THEATER_PERCENTAGE = 0.20;
  37.  
  38. // Ask for the name of the movie
  39. cout << "Enter the name of the movie: ";
  40. getline(cin, movieName);
  41.  
  42. // Ask for the number of adult and child tickets sold
  43. cout << "Enter the number of adult tickets sold: ";
  44. cin >> adultTickets;
  45.  
  46. cout << "Enter the number of child tickets sold: ";
  47. cin >> childTickets;
  48.  
  49. // Calculate profits
  50. grossProfit = (adultTickets * ADULT_TICKET_PRICE) + (childTickets * CHILD_TICKET_PRICE);
  51. netProfit = grossProfit * THEATER_PERCENTAGE;
  52. amountPaidToDistributor = grossProfit - netProfit;
  53.  
  54. // Display the report formatted to match the required output[cite: 4]
  55. cout << "\n";
  56. cout << left << setw(30) << "Movie Name:" << "\"" << movieName << "\"" << endl;
  57. cout << left << setw(30) << "Adult Tickets Sold:" << adultTickets << endl;
  58. cout << left << setw(30) << "Child Tickets Sold:" << childTickets << endl;
  59.  
  60. // Format numeric output for currency and align the decimals[cite: 4]
  61. cout << fixed << setprecision(2);
  62. cout << left << setw(30) << "Gross Box Office Profit:" << "$ " << right << setw(7) << grossProfit << endl;
  63. cout << left << setw(30) << "Net Box Office Profit:" << "$ " << right << setw(7) << netProfit << endl;
  64. cout << left << setw(30) << "Amount Paid to Distributor:" << "$ " << right << setw(7) << amountPaidToDistributor << endl;
  65.  
  66. return 0;
  67. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Enter the name of the movie: Enter the number of adult tickets sold: Enter the number of child tickets sold: 
Movie Name:                   ""
Adult Tickets Sold:           2
Child Tickets Sold:           0
Gross Box Office Profit:      $   12.00
Net Box Office Profit:        $    2.40
Amount Paid to Distributor:   $    9.60