fork download
  1. // Torrez, Elaine CS1A
  2. // ----------------------------------------------
  3. // MOVIE PROFIT
  4. // ----------------------------------------------
  5. //
  6. // This program stores information about a movie using
  7. // a structure called MovieData. It includes the movie's
  8. // production cost and first-year revenue, then displays
  9. // the movie information and calculates the first-year
  10. // profit or loss.
  11. //
  12. // ----------------------------------------------
  13. // INPUT
  14. // (no user input for this program)
  15. //
  16. // PROCESSING
  17. // Create two MovieData variables
  18. // Compute first-year profit or loss
  19. // Pass each variable to a function to display data
  20. //
  21. // OUTPUT
  22. // Movie Title
  23. // Movie Director
  24. // Year Released
  25. // Running Time (minutes)
  26. // First-year Profit or Loss
  27. //
  28. // ----------------------------------------------
  29.  
  30. #include <iostream>
  31. #include <iomanip>
  32. #include <string>
  33. using namespace std;
  34.  
  35. // Structure to hold movie information
  36. struct MovieData {
  37. string title; // Title of the movie
  38. string director; // Director of the movie
  39. int year; // Year released
  40. int minutes; // Movie length in minutes
  41. double productionCost; // Cost to produce the movie
  42. double firstYearRev; // First-year revenue
  43. };
  44.  
  45. // -------------------------------------------------
  46. // Function: displayMovie
  47. // This function displays all the information for one
  48. // movie, including the first-year profit or loss.
  49. // -------------------------------------------------
  50. void displayMovie(const MovieData &m)
  51. {
  52. double profitLoss = m.firstYearRev - m.productionCost;
  53.  
  54. cout << "Title : " << m.title << endl;
  55. cout << "Director : " << m.director << endl;
  56. cout << "Year Released: " << m.year << endl;
  57. cout << "Runtime : " << m.minutes << " minutes" << endl;
  58.  
  59. if (profitLoss >= 0)
  60. {
  61. cout << "First-Year Profit : $" << profitLoss << endl;
  62. }
  63. else
  64. {
  65. cout << "First-Year Loss : $" << -profitLoss << endl;
  66. }
  67.  
  68. cout << "----------------------------------------\n";
  69. }
  70.  
  71. int main()
  72. {
  73. //--------------------------------------------------
  74. // DECLARATIONS
  75. //--------------------------------------------------
  76. MovieData movie1; // First Movie
  77. MovieData movie2; // Second Movie
  78.  
  79. //--------------------------------------------------
  80. // INITIALIZE MOVIE 1 (profit example)
  81. //--------------------------------------------------
  82. movie1.title = "Inception";
  83. movie1.director = "Christopher Nolan";
  84. movie1.year = 2010;
  85. movie1.minutes = 148;
  86. movie1.productionCost = 160000000.00; // $160M
  87. movie1.firstYearRev = 825000000.00; // $825M
  88.  
  89. //--------------------------------------------------
  90. // INITIALIZE MOVIE 2 (loss example)
  91. //--------------------------------------------------
  92. movie2.title = "Random Indie Film";
  93. movie2.director = "New Director";
  94. movie2.year = 2024;
  95. movie2.minutes = 95;
  96. movie2.productionCost = 5000000.00; // $5M
  97. movie2.firstYearRev = 2000000.00; // $2M
  98.  
  99. //--------------------------------------------------
  100. // FORMATTING FOR MONEY OUTPUT
  101. //--------------------------------------------------
  102. cout << fixed << setprecision(2);
  103.  
  104. //--------------------------------------------------
  105. // OUTPUT
  106. //--------------------------------------------------
  107. displayMovie(movie1);
  108. displayMovie(movie2);
  109.  
  110. return 0;
  111. }
  112.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Title        : Inception
Director     : Christopher Nolan
Year Released: 2010
Runtime      : 148 minutes
First-Year Profit : $665000000.00
----------------------------------------
Title        : Random Indie Film
Director     : New Director
Year Released: 2024
Runtime      : 95 minutes
First-Year Loss   : $3000000.00
----------------------------------------