159k views
0 votes
Write a program that uses a structure named MovieData to store the following information about a movie: Title Director Year Released Running Time (in minutes) The program should create two MovieData variables, store values in their members, and pass each one, in turn, to a function that displays the information about the movie in a clearly formatted manner.

User Enzey
by
5.1k points

1 Answer

3 votes

Answer:

#include <iostream>

#include <string>

using namespace std;

struct MovieData {

string Title;

string Director;

unsigned short YearReleased;

unsigned short RunningTime;

};

void displayMovieInfo(MovieData &md) {

cout << "The Title is: " << md.Title << endl

<< "The Director is: " << md.Director << endl

<< "The Year of Release: " << md.YearReleased << endl

<< "The Running Time: " << md.RunningTime << " minutes" << endl;

}

int main() {

MovieData firtMovie, secondMovie;

firtMovie.Title = "Starship Troopers";

firtMovie.Director = "Paul Verhoeven";

firtMovie.YearReleased = 1997;

firtMovie.RunningTime = 129;

secondMovie.Title = "Alien vs. Predator";

secondMovie.Director = "Paul W. S. Anderson";

secondMovie.YearReleased = 2004;

secondMovie.RunningTime = 108;

cout << endl;

displayMovieInfo(movFirst);

cout << endl;

displayMovieInfo(movSecond);

cout << endl;

system("pause");

return 0;

}

Step-by-step explanation:

In this program a structure that contains the class feilds for four attributes of a movie (Title, Director, Year Released and Running Time) we declared this with their appropriate data types.

Next we create a function (Method) called displayMovieInfo that will print a clearly formatted output of the movies when called and given appropriate parameters.

Finally we create the main function where we create two movie objects and make function calls to the displayMovieInfo and pass the two movies to the displayMovieInfo function to display their information

User Michael Mitch
by
5.3k points