Question

1.C++ Write a program that uses a structure named MovieData to store the following information about...

1.C++

Write a program that uses a structure named MovieData to store the following information about a movie: title, director, year released, and running time (in minutes). Include a constructor that allows all four of these member data values to be specified at the time a MovieData variable is created. Your program should do the followings:

A. creates two MovieData variables (namely, movie1 and movie2)

B. creates two pointers to the structure MovieData (namely, movie1Ptr and movie2Ptr) and initializes them with the addresses of the structure variables movie1 and movie2, respectively

C. uses movie1Ptr with the * and the dot operators to display the details of movie1

D. uses movie2Ptr with the -> operator to display the details of movie2

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code Screenshot:

Executable Code:

#include<iostream>
using namespace std;

//MovieData structure
struct MovieData{
//variables
string title, director;
int year, runningTime;
//constructor initializing all fields
MovieData(string titl, string dir, int yr, int time){
title=titl;
director=dir;
year=yr;
runningTime=time;
}
};


int main(){
//creating two MovieData objects named movie1 and movie2
MovieData movie1("Avengers: Endgame", "Joe Russo",2019,182);
MovieData movie2("Avatar", "James Cameron",2009,162);
//creating two MovieData pointers, pointing to each of the above objects
MovieData* movie1Ptr=&movie1;
MovieData* movie2Ptr=&movie2;
//using * and . operators, displaying details of first movie with movie1Ptr
cout<<"Title       : "<<(*movie1Ptr).title<<endl;
cout<<"Director    : "<<(*movie1Ptr).director<<endl;
cout<<"Released    : "<<(*movie1Ptr).year<<endl;
cout<<"Running Time: "<<(*movie1Ptr).runningTime<<endl<<endl;
//using -> operator, displaying details of second movie with movie2Ptr
cout<<"Title       : "<<movie2Ptr->title<<endl;
cout<<"Director    : "<<movie2Ptr->director<<endl;
cout<<"Released    : "<<movie2Ptr->year<<endl;
cout<<"Running Time: "<<movie2Ptr->runningTime<<endl<<endl;
return 0;
}

Sample Output:


Please don't hesitate to contact me if you have any queries. :)

Add a comment
Know the answer?
Add Answer to:
1.C++ Write a program that uses a structure named MovieData to store the following information about...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write a C++ program that uses a class named Movie to store the following information about...

    write a C++ program that uses a class named Movie to store the following information about a movie: - Title - Director - Year Released - Running time (in minutes) + print() : Function that will print the information for this movie in a nice format Include a constructor that allows all four of these member data values to be specified at the time a Movie variable is created. The program should create four Movie variables and call its print()...

  • C++Write a program that uses a class name MovieData to store the following information about a...

    C++Write a program that uses a class name MovieData to store the following information about a movie: create a class not a strcuture please. Title Director Year release Running time Inclue a constructor that allows all four of these memberdata values to be sprcified at the time a MovieData variable is created The program should create two MovieData variable. Do not use user input. Have a stand alone function that displays the information about the movie in a clearly formatted...

  • In C++ write a program; Your goal is to create a structure to store information about...

    In C++ write a program; Your goal is to create a structure to store information about a movie. Your program should have the following: -The name of the program should be Assignment8. -3 comment lines (description of the program, author, and date) -Write a program that uses a structure named MovieData to store the following information about a movie: (3 points) Title, Director, Year released, Running time (in minutes) The program should create 2 MovieData variables, store values in their...

  • Car Class Background: Write a class named Car that will be used to store information and...

    Car Class Background: Write a class named Car that will be used to store information and control the acceleration and brake of a car. Functionality: 1. Write a class named "Car” that has the following member variables: • year Model - an int that holds the car's year model • make-A string that holds the make of the car • speed - an int that holds the car's current speed 2. In addition the class should have the following member...

  • Inventory Program (C++) Write a program that uses a structure to store the following inventory data...

    Inventory Program (C++) Write a program that uses a structure to store the following inventory data in a file: - Item Description -Quantity on Hand -Wholesale cost -Retail cost -Date Added to Inventory The program should have a menu that allows the user to perform the following tasks: -Add new records to file -Display any record in the file -Change any record in the file Input Validation: The program should not accept quantities, or wholesale or retail costs, less than...

  • In C++: Implement a class Polynomial that uses a dynamic array of doubles to store the...

    In C++: Implement a class Polynomial that uses a dynamic array of doubles to store the coefficients for a polynomial. This class does not need the method the overloaded += operator. Your class should have the following methods: Write one constructor that takes an integer n for the degree of a term and a double coefficient c for the coefficient of the term and creates the polynomial c x^n. (This constructor can be given default arguments easily to have a...

  • C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a...

    C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a class named Car that has the following member variables: year. An int that holds the car’s model year. make. A string object that holds the make of the car. speed. An int that holds the car’s current speed. In addition, the class should have the following member functions. Constructor. The constructor should accept the car’s year and make as arguments and assign these values...

  • please write in C++ Write a program that uses a structure to store the following inventory...

    please write in C++ Write a program that uses a structure to store the following inventory data in a file: The data can be either read from a text file or the keyboard Item name (string) Quantity on hand(int) Wholesale cost(double) Retail Cost(double) The program should have a menu that allows the user to perform the following tasks: Add new records to the file Display any record in the file User will provide the name of the item or the...

  • Write a c++ program which uses a structure having the indicated member names to store the...

    Write a c++ program which uses a structure having the indicated member names to store the following data: Name (student name) IDnum (student ID number) Tests (an array of three test scores) Average (average test score) Grade (course grade) The program will keep a list of three test scores for one student. The program may prompt the user for the name, ID number, and test scores, or these may be assigned within the program. The average test score will be...

  • Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director,...

    Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director, Genre, Year Released, Running Time) into a vector of structures and perform the following operations: Search for a specific title Search for movies by a specific director Search for movies by a specific genre Search for movies released in a certain time period Search for movies within a range for running time Display the movies on the screen in a nice, easy to read...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT