fork download
  1. //Sam Trivikraman CS1A Chapter 11, p. 645, #2
  2. //
  3. /*
  4.  ******************************************************************************
  5. Store Movie Data (Question 1 modded)
  6. _______________________________________________________________________________
  7. This program stores user inputted movie data.
  8. _______________________________________________________________________________
  9. INPUT
  10. movie title : The title of the movie
  11. movie director : The director of the movie
  12. movie release year : The movie's release year
  13. movie run time : The movie's run time
  14. movie production cost : The movie's production cost
  15. movie revenue : The movie's revenue
  16.  
  17. OUTPUT
  18. array of movie details : An array that stores all of the details for the movie
  19. _______________________________________________________________________________
  20. *******************************************************************************
  21. */
  22.  
  23. #include <iostream>
  24. using namespace std;
  25.  
  26. //a structure that stores all of the movie data
  27. struct MovieData
  28. {
  29. string title; //INPUT movie title
  30. string director; //INPUT movie director
  31. int yearReleased; //INPUT movie release year
  32. int runTime; //INPUT movie run time
  33. float prodCost; //INPUt movie production cost
  34. float revenue; //INPUT movie revenue
  35. };
  36.  
  37. int main() {
  38.  
  39. MovieData movieOne; //OUTPUT the first movie
  40. MovieData movieTwo; //OUTPUT the second movie
  41. float movieOneMoney; //OUTPUT the profit/loss for movie one
  42. float movieTwoMoney; //OUTPUT the profit/loss for movie two
  43.  
  44. //get the details for movie one and input into the array
  45. cout << "Please enter the title of the first movie" << endl;
  46. cin >> movieOne.title;
  47. cout << "Please enter the director of the first movie" << endl;
  48. cin >> movieOne.director;
  49. cout << "Please enter the year that the first movie was released" << endl;
  50. cin >> movieOne.yearReleased;
  51. cout << "Please enter the first movie's run time (in minutes)" << endl;
  52. cin >> movieOne.runTime;
  53. cout << "Please enter the production cost of the first movie" << endl;
  54. cin >> movieOne.prodCost;
  55. cout << "Please enter the revenue from the first movie" << endl;
  56. cout << "\n" << endl;
  57.  
  58. //calculate and output profit/loss for movie one
  59. movieOneMoney = movieOne.revenue - movieOne.prodCost;
  60. if(movieOneMoney > 0)
  61. {
  62. cout << "This year's profit is: $" << movieOneMoney << endl;
  63. }
  64. else
  65. {
  66. cout << "This year's loss is: $" << movieOneMoney << endl;
  67. }
  68. cout << "\n" << endl;
  69.  
  70. //get the details for movie two and input into the array
  71. cout << "Please enter the title of the second movie" << endl;
  72. cin >> movieTwo.title;
  73. cout << "Please enter the director of the second movie" << endl;
  74. cin >> movieTwo.director;
  75. cout << "Please enter the year that the second movie was released" << endl;
  76. cin >> movieTwo.yearReleased;
  77. cout << "Please enter the second movie's run time (in minutes)" << endl;
  78. cin >> movieTwo.runTime;
  79. cout << "Please enter the production cost of the second move" << endl;
  80. cin >> movieTwo.prodCost;
  81. cout << "Please enter the revenue from the second movie" << endl;
  82. cin >> movieTwo.revenue;
  83. cout << "\n" << endl;
  84.  
  85. //calculate and output profit/loss for movie two
  86. movieTwoMoney = movieTwo.revenue - movieTwo.prodCost;
  87. if(movieTwoMoney > 0)
  88. {
  89. cout << "This year's profit is: $" << movieTwoMoney << endl;
  90. }
  91. else
  92. {
  93. cout << "This year's loss is: $" << movieTwoMoney << endl;
  94. }
  95.  
  96. //output the details for movies one and two
  97. cout << "\n" << endl;
  98. cout << "Movie One details: " << endl;
  99. cout << "Title: " << movieOne.title << endl;
  100. cout << "Director: " << movieOne.director << endl;
  101. cout << "Release Year: " << movieOne.yearReleased << endl;
  102. cout << "Run Time: " << movieOne.runTime << endl;
  103. cout << "Movie Two details: " << endl;
  104. cout << "Title: " << movieTwo.title << endl;
  105. cout << "Director: " << movieTwo.director << endl;
  106. cout << "Release Year: " << movieTwo.yearReleased << endl;
  107. cout << "Run Time: " << movieTwo.runTime << endl;
  108. return 0;
  109. }
Success #stdin #stdout 0.01s 5300KB
stdin
Dune
bob
2022
176
20
167
wee
you
1679
556
300
60
stdout
Please enter the title of the first movie
Please enter the director of the first movie
Please enter the year that the first movie was released
Please enter the first movie's run time (in minutes)
Please enter the production cost of the first movie
Please enter the revenue from the first movie


This year's loss is: $-20


Please enter the title of the second movie
Please enter the director of the second movie
Please enter the year that the second movie was released
Please enter the second movie's run time (in minutes)
Please enter the production cost of the second move
Please enter the revenue from the second movie


This year's loss is: $0


Movie One details: 
Title: Dune
Director: bob
Release Year: 2022
Run Time: 176
Movie Two details: 
Title: 167
Director: wee
Release Year: 0
Run Time: 5425