219k views
2 votes
Write a program that prompts the user for input and allows all of these member data values to be specified. The program should create two MovieData variables and create/use a method displayMovie(MovieData) to display the information about the movie in a clearly formatted manner.

User ARTLoe
by
4.9k points

1 Answer

3 votes

Answer:

The program to this question can be defined as follows:

Program:

#include <iostream> //defining header file

using namespace std;

struct MovieData //defining structure MovieData

{

//defining structure variables

string Title; //defining string variable

int Year; //defining integer variable

string Timing; //defining string variable

};

void displayMovie(MovieData M_data) //defining method displayMovie

{

//print values

cout << "Title: "<<M_data.Title<<endl;

cout << "year: "<<M_data.year<<endl;

cout << "Timing: "<<M_data.Timing<<endl;

}

int main () //defining main method

{

MovieData z1,z2; //creating structure variables

cout<<"\t \t Enter First Movie Details:"<<endl; //message

cout << "Enter Title: ";//message

cin>>z1.Title; //input value

cout << "Enter Year: "; //message

cin>>z1.Year; //input value

cout << "Enter Timing: "; //message

cin>>z1.Timing;//input value

cout<<"\t \t Enter Second Movie Details: "<<endl;

cout << "Enter Title: "; //message

cin>>z2.Title;//input value

cout << "Enter Year: "; //message

cin>>z2.Year;//input value

cout << "Enter Timing: "; //message

cin>>z2.Timing;//input value

cout<<"\t\t Movies Detail:"<<endl; //message

displayMovie(z1); //calling a method

displayMovie(z2); //calling a method

return 0;

}

Output:

Enter First Movie Details:

Enter Title: DDLJ

Enter Year: 2004

Enter Timing: 9to12am

Enter Second Movie Details:

Enter Title: RRR

Enter Year: 2010

Enter Timing: 12to3am

Movies Detail:

Title: DDLJ

Year: 2004

Timing: 9to12am

Title: RRR

Year: 2010

Timing: 12to3am

Step-by-step explanation:

In the above program a structure "MovieData" is defined, which is used to collect different type of values, inside the structure three variable "Title, Year, and Timing" is declared, in which "Title and Timing" is a string variable and Year is an integer variable.

  • In the next step, a method "displayMovie" is defined, in which we pass a structure object, which is "M_data", that prints the structure details.
  • In the main method two structure variable "z1, and z2" is declared, which take input in the structure variable and call the displayMovie method.
User Giga
by
4.8k points