1. Movie Data Write a program that uses a structure named Movie Data to store th
ID: 664959 • Letter: 1
Question
1. Movie Data Write a program that uses a structure named Movie Data to store the following information about a movie: Title Director Year Released Running Time (in minutes) The program should create two Movie Data 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. NOTES: Must have at least one dynamic allocation; eg. Movie Data *movie1 = new ... 10 correctness points will be lost if you don?t. Must have at least one static declaration, eg. Movie Data movie1; 10 correctness points will be lost if you don?t. Must set all the fields of the dynamically allocated movie structure. 5 correctness points will be lost if you don?t. Must set all the fields of the statically declared movie structure. 5 correctness points will be lost if you don?t. Must call a FUNCTION to correctly display the dynamically allocated movie structure. 5 correctness points will be lost if you don?t. Must call a FUNCTION (could be the same one) to correctly display the statically allocated movie structure. 5 correctness points will be lost if you don?t.Explanation / Answer
#include <iostream>
#include<string.h>
using namespace std;
struct MovieData {
char title[30];
char director[30];
char released[20];
int runsfor;
};
void displaymovie(MovieData md)
{
cout<<"Movie 1 : ";
cout<<"Movie Title : "<<md.title<<" ";
cout<<"Directed By : "<<md.director<<" ";
cout<<"Released on : "<<md.released<<" ";
cout<<"Running Time : "<<md.runsfor<<" minutes ";
}
void displaymovie(MovieData* md)
{
cout<<"Movie 2 : ";
cout<<"Movie Title : "<<md->title<<" ";
cout<<"Directed By : "<<md->director<<" ";
cout<<"Released on : "<<md->released<<" ";
cout<<"Running Time : "<<md->runsfor<<" minutes ";
}
int main() {
struct MovieData movie1; //static declaration
struct MovieData *movie2 = new MovieData; //dynamic declaration
//Setting all fields of static stuct object
strcpy(movie1.title, "The Dark Knight");
strcpy(movie1.director,"Christopher Nolan");
strcpy(movie1.released,"July 14, 2008");
movie1.runsfor = 152;
displaymovie(movie1); //displaying values of static object
//Setting all fields of dynamically allocated stuct object
strcpy(movie2->title,"The Dark Knight Rises");
strcpy(movie2->director,"Christopher Nolan");
strcpy(movie2->released,"July 16, 2012");
movie2->runsfor = 165;
displaymovie(movie2); //displaying values of dynamically allocated object
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.