fork download
  1. //Devin Scheu CS1A Chapter 11, P. 645, #2
  2. //
  3. /**************************************************************
  4. *
  5. * DISPLAY MOVIE INFORMATION WITH PROFIT OR LOSS
  6. * ____________________________________________________________
  7. * This program displays information about two movies, including
  8. * their profit or loss for the first year.
  9. * ____________________________________________________________
  10. * INPUT
  11. * movie1 : The data for the first movie
  12. * movie2 : The data for the second movie
  13. *
  14. * OUTPUT
  15. * movieDetails : The formatted display of movie information and profit/loss
  16. *
  17. **************************************************************/
  18.  
  19. #include <iostream>
  20. #include <iomanip>
  21. #include <string>
  22.  
  23. using namespace std;
  24.  
  25. struct MovieData {
  26. string title;
  27. string director;
  28. int yearReleased;
  29. int runningTime;
  30. double productionCosts;
  31. double firstYearRevenues;
  32. };
  33.  
  34. // Function to display movie information including profit/loss
  35. void displayMovie(const MovieData& movie) {
  36. double profitLoss = movie.firstYearRevenues - movie.productionCosts;
  37. cout << left << setw(25) << "Title:" << right << movie.title << endl;
  38. cout << left << setw(25) << "Director:" << right << movie.director << endl;
  39. cout << left << setw(25) << "Year Released:" << right << movie.yearReleased << endl;
  40. cout << left << setw(25) << "Running Time:" << right << movie.runningTime << " minutes" << endl;
  41. cout << left << setw(25) << "Production Costs:" << right << "$" << fixed << setprecision(2) << movie.productionCosts << endl;
  42. cout << left << setw(25) << "First Year Revenues:" << right << "$" << fixed << setprecision(2) << movie.firstYearRevenues << endl;
  43. cout << left << setw(25) << "First Year Profit/Loss:" << right << "$" << fixed << setprecision(2) << profitLoss << endl;
  44. cout << endl;
  45. }
  46.  
  47. int main () {
  48.  
  49. //Variable Declarations
  50. MovieData movie1; //INPUT - The data for the first movie
  51. MovieData movie2; //INPUT - The data for the second movie
  52. string movieDetails; //OUTPUT - The formatted display of movie information and profit/loss
  53.  
  54. //Initialize Movie 1
  55. movie1.title = "The Shawshank Redemption";
  56. movie1.director = "Frank Darabont";
  57. movie1.yearReleased = 1994;
  58. movie1.runningTime = 142;
  59. movie1.productionCosts = 25000000.00;
  60. movie1.firstYearRevenues = 58000000.00;
  61.  
  62. //Initialize Movie 2
  63. movie2.title = "Inception";
  64. movie2.director = "Christopher Nolan";
  65. movie2.yearReleased = 2010;
  66. movie2.runningTime = 148;
  67. movie2.productionCosts = 160000000.00;
  68. movie2.firstYearRevenues = 825000000.00;
  69.  
  70. //Separator and Output Section
  71. cout << "-------------------------------------------------------" << endl;
  72. cout << "OUTPUT:" << endl;
  73.  
  74. //Display Movie Information
  75. cout << "Movie 1 Details:" << endl;
  76. displayMovie(movie1);
  77.  
  78. cout << "Movie 2 Details:" << endl;
  79. displayMovie(movie2);
  80.  
  81. } //end of main()
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
-------------------------------------------------------
OUTPUT:
Movie 1 Details:
Title:                   The Shawshank Redemption
Director:                Frank Darabont
Year Released:           1994
Running Time:            142 minutes
Production Costs:        $25000000.00
First Year Revenues:     $58000000.00
First Year Profit/Loss:  $33000000.00

Movie 2 Details:
Title:                   Inception
Director:                Christopher Nolan
Year Released:           2010
Running Time:            148 minutes
Production Costs:        $160000000.00
First Year Revenues:     $825000000.00
First Year Profit/Loss:  $665000000.00