fork download
  1. // Torrez, Elaine CS1A
  2. // ----------------------------------------------
  3. // MOVIE DATA
  4. // ----------------------------------------------
  5. //
  6. // This program stores information about a movie using
  7. // a structure called MovieData. It then displays the
  8. // movie information in a clearly formatted manner.
  9. //
  10. // ----------------------------------------------
  11. // INPUT
  12. // (no user input for this program)
  13. //
  14. // PROCESSING
  15. // Create two MovieData variables
  16. // Pass each variable to a function
  17. // Display movie details
  18. //
  19. // OUTPUT
  20. // Movie Title
  21. // Movie Director
  22. // Year Released
  23. // Running Time (minutes)
  24. //
  25. // ----------------------------------------------
  26.  
  27. #include <iostream>
  28. #include <iomanip>
  29. #include <string>
  30. using namespace std;
  31.  
  32. // Structure to hold movie information
  33. struct MovieData {
  34. string title; // Title of the movie
  35. string director; // Director of the movie
  36. int year; // Year released
  37. int minutes; // Movie length in minutes
  38. };
  39.  
  40. // -------------------------------------------------
  41. // Function: displayMovie
  42. // This function displays all the information for one movie.
  43. // -------------------------------------------------
  44. void displayMovie(const MovieData &m)
  45. {
  46. cout << "Title : " << m.title << endl;
  47. cout << "Director : " << m.director << endl;
  48. cout << "Year Released: " << m.year << endl;
  49. cout << "Runtime : " << m.minutes << " minutes" << endl;
  50. cout << "----------------------------------------\n";
  51. }
  52.  
  53. int main()
  54. {
  55. //--------------------------------------------------
  56. // DECLARATIONS
  57. //--------------------------------------------------
  58. MovieData movie1; // First Movie
  59. MovieData movie2; // Second Movie
  60.  
  61. //--------------------------------------------------
  62. // INITIALIZE MOVIE 1
  63. //--------------------------------------------------
  64. movie1.title = "Inception";
  65. movie1.director = "Christopher Nolan";
  66. movie1.year = 2010;
  67. movie1.minutes = 148;
  68.  
  69. //--------------------------------------------------
  70. // INITIALIZE MOVIE 2
  71. //--------------------------------------------------
  72. movie2.title = "Toy Story";
  73. movie2.director = "John Lasseter";
  74. movie2.year = 1995;
  75. movie2.minutes = 81;
  76.  
  77. //--------------------------------------------------
  78. // OUTPUT
  79. //--------------------------------------------------
  80. displayMovie(movie1);
  81. displayMovie(movie2);
  82.  
  83. return 0;
  84. }
  85.  
  86.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Title        : Inception
Director     : Christopher Nolan
Year Released: 2010
Runtime      : 148 minutes
----------------------------------------
Title        : Toy Story
Director     : John Lasseter
Year Released: 1995
Runtime      : 81 minutes
----------------------------------------