Question

In: Computer Science

C++ Assignment 1) Write a C++ program specified below: a) Include a class called Movie. Include...

C++ Assignment

1) Write a C++ program specified below:

a) Include a class called Movie. Include the following attributes with appropriate types:

i. Title

ii. Director

iii. Release Year

iv. Rating (“G”, “PG”, “PG-13”, etc)

- Write code that instantiates a movie object using value semantics as text:

- Write code that instantiates a movie object using reference semantics:

- Write the print_movie method code:

- Write Constructor code:

- Write Entire Movie class declaration

Solutions

Expert Solution

We first define the class attributes(Title, director, etc) in the private part of the class. You can also define it in public section but it's a good practice to keep our attributes in private. Next, in our public section, we define 2 class constructors. The first one is a parameterised constructor in which we pass values of each attribute. The second is a Copy Constructor in which a reference of the object of the Movie class is passed to the constructor. After that, we define the print function which just prints the class attributes. In the main function we can see how to initialise the objects using different constructors.

Source Code:

#include <iostream>
using namespace std;

// Class Definition
class Movie {
   // Data members of class defined in private section
   string Title;
   string Director;
   int ReleaseYear;
   string Rating;

public:
   // Parameterised constructor for the class
   Movie(string title, string director, int releaseYear, string rating) {
       cout << "Parameterised Constructor Called!" << endl;
       Title = title;
       Director = director;
       ReleaseYear = releaseYear;
       Rating = rating;
   }

   // Copy Constructor of the class
   Movie(Movie &obj) {
       cout << "Copy Constructor Called!" << endl;
       Title = obj.Title;
       Director = obj.Director;
       ReleaseYear = obj.ReleaseYear;
       Rating = obj.Rating;
   }

   // Method that prints the data of the object
   void print_movie() {
       cout << "Title: " << Title << endl;
       cout << "Director: " << Director << endl;
       cout << "Release Year " << ReleaseYear << endl;
       cout << "Rating: " << Rating << endl;
   }
};

int main() {
   // Creating our first object using value sematics
   Movie movie1("Avengers", "Russo Brothers", 2019, "PG-13");  
   // Printing the values of our object
   movie1.print_movie();
  
   cout << "==========" << endl;

   // Creating the second object. Here the copy constructor is called
   Movie movie2 = movie1;
   // Printing its data
   movie2.print_movie();
   return 0;
}


Related Solutions

For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
in C++ Requirements: Write a program that creates a new class called Customer. The Customer class...
in C++ Requirements: Write a program that creates a new class called Customer. The Customer class should include the following private data: name - the customer's name, a string. phone - the customer's phone number, a string. email - the customer's email address, a string. In addition, the class should include appropriate accessor and mutator functions to set and get each of these values. Have your program create one Customer objects and assign a name, phone number, and email address...
For this week’s lab assignment, you will write a program called lab9.c. You will write a...
For this week’s lab assignment, you will write a program called lab9.c. You will write a program so that it contains two functions, one for each conversion. The program will work the same way and will produce the same exact output. The two prototypes should be the following: int btod(int size, char inputBin[size]); int dtob(int inputDec); The algorithm for the main() function should be the following: 1. Declare needed variables 2. Prompt user to enter a binary number 3. Use...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This class should contain information of a single student. last name, first name, credits, gpa, date of birth, matriculation date, ** you need accessor and mutator functions. You need a constructor that initializes a student by accepting all parameters. You need a default constructor that initializes everything to default values. write the entire program.
Loop Introduction Assignment Please write a program in c# Using the conditions below, write one program...
Loop Introduction Assignment Please write a program in c# Using the conditions below, write one program that calculates a person’s BMI. Your main() function will call functions 1, 2, and 3. Your program will contain three functions: Function #1: Will ask the user for their weight in pounds and their height in inches.   Your function will convert the weight and height into Body Mass Index (BMI). The formula for converting weight into BMI is as follows: BMI = Weight *...
Write C++ a program that shows a class called gamma that keeps track of how many...
Write C++ a program that shows a class called gamma that keeps track of how many objects of itself there are. Each gamma object has its own identification called ID. The ID number is set equal to total of current gamma objects when an object is created. Test you class by using the main function below. int main()    {    gamma g1;    gamma::showtotal();    gamma g2, g3;    gamma::showtotal();    g1.showid();    g2.showid();    g3.showid();    cout <<...
Write a C++ program that creates a base class called Vehicle that includes two pieces of...
Write a C++ program that creates a base class called Vehicle that includes two pieces of information as data members, namely: wheels (type int) weight (type float) Program requirements (Vehicle class): Provide set and a get member functions for each data member. Your class should have a constructor with two parameters (one for each data member) and it must use the set member functions to initialize the two data members. Provide a pure virtual member function by the name displayData()...
Please write about the documentary movie of (Inside Job) Movie Assignment as following questions below ....
Please write about the documentary movie of (Inside Job) Movie Assignment as following questions below . Don't write about Wall Street . This is the 2nd question posting 1. Discuss the serious ethical concerns for business in the "Inside Job movie". 1. How business was portrayed in the film of Inside Job. What you should find is that business is generally portrayed in negative terms. For example, most business people in these films are motivated by greed. There are exceptions....
For C++ Write a program that opens a specified text file then displays a list of...
For C++ Write a program that opens a specified text file then displays a list of all the unique words found in the file. Hint: Store each word as an element of a set.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT