Question

Write an entire class called Movie that stores an instance variable named title for the title of the movie as a string. Write the corresponding getter and setter methods (getTitle, setTitle), and a constructor that takes one parameter (string for the title). Include both the class definition and method definitions! Be sure to use appropriate visibility modifiers. Assume all includes and using namespace std are already in the file. Do not try to make header files.

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

Hi

I have created a class named as Movie which will contain two constructor default and parameterized and getter setter methods for title.
I have declared method in class and gives the definition outside the class. Also constructor definition within the class.

If you have any doubt and need to change the code, comment it and also please rate it. Thanks

Here is the code:

#include<iostream>

#include<string>

using namespace std;

// class definition

class Movie

{

// private variable title

    private:

                string title;

    public:

                // default constructor

                Movie() {}

                // parameterized constructor

                Movie(string title)

                {

                                this->title = title;

}

// method declaration which will be defined outside the class

string getTitle();

void setTitle(string);

};

// Definition of getTitle using scope resolution operator ::

string Movie::getTitle()

{

    return this->title;

}

// Definition of setTitle using scope resolution operator ::

void Movie::setTitle(string title)

{

                this->title = title;

}

// main function

int main()

{

                // First Movie object

                Movie firstMovieObj;

               

                // Set Movie title using setter method

                firstMovieObj.setTitle("Avengers");

                // print Movie name using getter method

                cout << "Movie : " << firstMovieObj.getTitle() << endl;

                // Second Movie object using constructor set title

                Movie secondMovieObj("Lord of The Rings");

                // print Movie name using getter method

                cout << "Movie : " << secondMovieObj.getTitle() << endl;

                return 0;

}

Here is the output:
Movie: Avengers Movie Lord of The Rings cess exited after 0.3248 seconds with return value e Press any key to continue 5 6 2 2

Add a comment
Know the answer?
Add Answer to:
Write an entire class called Movie that stores an instance variable named title for the title...
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 class named Book containing: Two instance variables named title and author of type String....

    Write a class named Book containing: Two instance variables named title and author of type String. A constructor that accepts two String parameters. The value of the first is used to initialize the value of title and the value of the second is used to initialize author. A method named toString that accepts no parameters. toString returns a String consisting of the value of title, followed by a newline character, followed by the value of author.

  • c ++ Create a class Book with the data members listed below.     title, which is...

    c ++ Create a class Book with the data members listed below.     title, which is a string (initialize to empty string)     sales, which is a floating point value (as a double, initialize to 0.0) Include the following member functions:     Include a default constructor,     a constructor with parameters for each data member (in the order given above),     getters and setter methods for each data member named in camel-case. For example, if a class had a data...

  • cs55(java) please. Write a class called Book that contains instance data for the title, author, publisher,...

    cs55(java) please. Write a class called Book that contains instance data for the title, author, publisher, price, and copyright date. Define the Book constructor to accept and initialize this data. Include setter and getter methods for all instance data. Include a toString method that returns a nicely formatted, multi-line description of the book. Write another class called Bookshelf, which has name and array of Book objects. Bookself capacity is maximum of five books. Includes method for Bookself that adds, removes,...

  • LAB 7-Movie List Program Goali Your assignment is to write a C++program to implement the ADT...

    LAB 7-Movie List Program Goali Your assignment is to write a C++program to implement the ADT List by creating a list of movies. This assignment will help you practice: multiple file programming, classes, pablic and private methods, dynamie memory, constructors and destructors, arrays and files Implementation the required classes This lab assignment gives you the opportunity to practice creating classes and using dynamic memory in one of There are two classes to implement: Movie and MovieList. As you can see...

  • PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class...

    PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class definition. * * @author David Brown * @version 2019-01-22 */ public class Movie implements Comparable { // Constants public static final int FIRST_YEAR = 1888; public static final String[] GENRES = { "science fiction", "fantasy", "drama", "romance", "comedy", "zombie", "action", "historical", "horror", "war" }; public static final int MAX_RATING = 10; public static final int MIN_RATING = 0; /** * Converts a string of...

  • Python Write the definition of a class Counter containing: An instance variable named counter of type...

    Python Write the definition of a class Counter containing: An instance variable named counter of type int An instance variable named limit of type int. A constructor that takes two int arguments and assigns the first one to counter and the second one to limit A method named increment. It does not take parameters or return a value; if the instance variable counter is less than limit, increment just adds one to the instance variable counter. A method named decrement....

  • Write a class called Shelf that contains instance data that represents the length, breadth, and capacity...

    Write a class called Shelf that contains instance data that represents the length, breadth, and capacity of the shelf. Also include a boolean variable called occupied as instance data that represents whether the shelf is occupied or not. Define the Shelf constructor to accept and initialize the height, width, and capacity of the shelf. Each newly created Shelf is vacant (the constructor should initialize occupied to false). Include getter and setter methods for all instance data. Include a toString method...

  • Java Write a class named CheckingAccount containing: An instance variable named balance of type double, initialized...

    Java Write a class named CheckingAccount containing: An instance variable named balance of type double, initialized to 0. A method named deposit that accepts a parameter of type double. The value of the balance instance variable is increased by the value of the parameter. A method named withdraw that accepts a parameter of type double. The value of the balance instance variable is decreased by the value of the parameter. A method named getBalance that accepts no parameters, returns the...

  • 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()...

  • In C# (sharp) Assuming a string variable named movie Title has already been declared, which one...

    In C# (sharp) Assuming a string variable named movie Title has already been declared, which one of the following statements combines the strings "Hidden" and "Figures" and then assigns the resulting string to the variable? 1. movieTitle="Hidden" + "Figures"; 2. "Hidden" +"Figures" - moveTitle; 3. movie Title("Hidden" +"Figures"); 4. movie title="Hidden" & "Figures": Look at the following code: int distance; // Declare distance as an int double half://Declare half as a double distance = 35; // Assign 35 to distance...

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
ADVERTISEMENT