fork download
  1. //Devin Scheu CS1A Chapter 11, P. 645, #1
  2. //
  3. /**************************************************************
  4. *
  5. * DISPLAY MOVIE INFORMATION
  6. * ____________________________________________________________
  7. * This program displays information about two movies using
  8. * a structure.
  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
  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. };
  31.  
  32. // Function to display movie information
  33. void displayMovie(const MovieData& movie) {
  34. cout << left << setw(25) << "Title:" << right << movie.title << endl;
  35. cout << left << setw(25) << "Director:" << right << movie.director << endl;
  36. cout << left << setw(25) << "Year Released:" << right << movie.yearReleased << endl;
  37. cout << left << setw(25) << "Running Time:" << right << movie.runningTime << " minutes" << endl;
  38. cout << endl;
  39. }
  40.  
  41. int main () {
  42.  
  43. //Variable Declarations
  44. MovieData movie1; //INPUT - The data for the first movie
  45. MovieData movie2; //INPUT - The data for the second movie
  46. string movieDetails; //OUTPUT - The formatted display of movie information
  47.  
  48. //Initialize Movie 1
  49. movie1.title = "The Shawshank Redemption";
  50. movie1.director = "Frank Darabont";
  51. movie1.yearReleased = 1994;
  52. movie1.runningTime = 142;
  53.  
  54. //Initialize Movie 2
  55. movie2.title = "Inception";
  56. movie2.director = "Christopher Nolan";
  57. movie2.yearReleased = 2010;
  58. movie2.runningTime = 148;
  59.  
  60. //Separator and Output Section
  61. cout << "-------------------------------------------------------" << endl;
  62. cout << "OUTPUT:" << endl;
  63.  
  64. //Display Movie Information
  65. cout << "Movie 1 Details:" << endl;
  66. displayMovie(movie1);
  67.  
  68. cout << "Movie 2 Details:" << endl;
  69. displayMovie(movie2);
  70.  
  71. } //end of main()
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
-------------------------------------------------------
OUTPUT:
Movie 1 Details:
Title:                   The Shawshank Redemption
Director:                Frank Darabont
Year Released:           1994
Running Time:            142 minutes

Movie 2 Details:
Title:                   Inception
Director:                Christopher Nolan
Year Released:           2010
Running Time:            148 minutes