fork download
  1. //Christian Nwogu CSC5 CH.11 Pp.681 #2
  2. /**************************************************************************
  3.  *
  4.  * SHOW MOVIE DATA OF STRUCTURE
  5.  * _______________________________________________________________________
  6.  * This program uses a structure named MovieData to store the following
  7.  * information about a movie.
  8.  * Title
  9.  * Director
  10.  * Year Released
  11.  * Running Time
  12.  * The program creates two MovieData variables, stores values in their
  13.  * members, and pass each one, in turn, to a function that displays the
  14.  * information about the movie in a clearly formatted manner.
  15.  * _______________________________________________________________________
  16.  * INPUT
  17.  * movie1.title
  18.  * movie1.director
  19.  * movie1.year
  20.  * movie1.time
  21.  * movie2.title
  22.  * movie2.director
  23.  * movie2.year
  24.  * movie2.time
  25.  * OUTPUT
  26.   * movie1.title
  27.  * movie1.director
  28.  * movie1.year
  29.  * movie1.time
  30.  * movie2.title
  31.  * movie2.director
  32.  * movie2.year
  33.  * movie2.time
  34.  * **********************************************************************/
  35.  
  36. #include <iostream>
  37. #include <iomanip>
  38. using namespace std;
  39.  
  40.  
  41. /********************************************************************
  42.  * STRUCTURE: MovieData
  43.  * -----------------------------------------------------------------
  44.  * MovieData is a strucre that stores the tile, the director, year released
  45.  *, the running time of movie.
  46.  ********************************************************************/
  47. struct MovieData
  48. {
  49. string title; // The title of the movie
  50. string director; // The name of director
  51. int year; // The year when the movie was released
  52. int time; // The running time of movie in minutes
  53. };
  54.  
  55. /********************************************************************
  56.  * FUNCTION PROTOTYPE: ShowMovieData
  57.  * -----------------------------------------------------------------
  58.  * This function accepts an MovieData as an argument, and it displays
  59.  * the each item of the structure.
  60.  *
  61.  * Return : Nothing
  62.  ********************************************************************/
  63. void ShowMovieData(MovieData);
  64.  
  65. int main ()
  66.  
  67. {
  68. //
  69. // VARIABLES
  70. MovieData movie1;
  71. MovieData movie2;
  72. //
  73. // INPUT for the first movie
  74. cout << "MOVIE #1" << endl;
  75. cout << "Enter the title of movie \n";
  76. getline(cin, movie1.title);
  77. cout << "Enter the director of movie \n";
  78. getline(cin, movie1.director);
  79. cout << "Enter the year when the movie was released \n";
  80. cin >> movie1.year;
  81. cout << "Enter the running time of the movie \n\n";
  82. cin >> movie1.time;
  83. //
  84. // INPUT for the second movie
  85. cout << "MOVIE #2" << endl;
  86. cout << "Enter the title of movie\n";
  87. cin.ignore();
  88. getline(cin, movie2.title);
  89. cout << "Enter the director of movie \n";
  90. getline(cin, movie2.director);
  91. cout << "Enter the year when the movie was released \n";
  92. cin >> movie2.year;
  93. cout << "Enter the running time of the movie \n";
  94. cin >> movie2.time;
  95.  
  96. // OUTPUT
  97. cout << endl;
  98. ShowMovieData(movie1);
  99. ShowMovieData(movie2);
  100.  
  101. return 0;
  102. }
  103.  
  104. /********************************************************************
  105.  * FUNCTION DEFINITION: ShowMovieData
  106.  * -----------------------------------------------------------------
  107.  * This function accepts an structured data of MovieData as an argument,
  108.  * and it displays the elements of the structure on console.
  109.  * This is a void function, and returns nothing.
  110.  ********************************************************************/
  111. void ShowMovieData(MovieData movie)
  112. {
  113. cout << "Title: " << movie.title << endl;
  114. cout << "Director: " << movie.director << endl;
  115. cout << "Year: " << movie.year << endl;
  116. cout << "Time: " << movie.time << "m" << endl;
  117. cout << endl;
  118. }
  119.  
Success #stdin #stdout 0s 15240KB
stdin
TRANSFORMERS 5
Steven spielberg
2017
150
THE AVENGER 2
Idontknow
2015
100
stdout
MOVIE #1
Enter the title of movie 
Enter the director of movie 
Enter the year when the movie was released 
Enter the running time of the movie 

MOVIE #2
Enter the title of movie
Enter the director of movie 
Enter the year when the movie was released 
Enter the running time of the movie 

Title:    TRANSFORMERS 5
Director: Steven spielberg
Year:     2017
Time:     150m

Title:    THE AVENGER 2
Director: Idontknow
Year:     2015
Time:     100m