Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please explain what I did wrong in my movie.cpp file based on the highlighted sentences. Thank you!! Identifiers should be descriptive. Movie.cpp: Unnecessary to check

Please explain what I did wrong in my movie.cpp file based on the highlighted sentences. Thank you!!

Identifiers should be descriptive.

Movie.cpp: Unnecessary to check if the title is empty. Movie.cpp: Inefficient to call functions that belong to the same class. You have direct access to all private data within the class.

Movie.cpp:

#include "Movie.h"

using namespace std;

//Default Constructor Movie::Movie() { title = ""; year = 0; }

//Overloaded Constructor Movie::Movie(string t, int y) { title = t; year = y; }

//Function getMovieTitle string Movie::getMovieTitle() { if(title == "") { return "No name assigned."; } else { return title; } }

//Function getYear int Movie::getYear() { return year; }

//Function setMovieTitle void Movie::setMovieTitle(string t) { title = t; }

//Function setYear void Movie::setYear(int y) { year = y; }

//Function print void Movie::print() { cout

//Function sameYear bool Movie::sameYear(Movie m) { return (year == m.getYear()); }

//Destructor Movie::~Movie(){}

#include "Movie.h"

using namespace std;

//Default Constructor Movie::Movie() { title = ""; year = 0; }

//Overloaded Constructor Movie::Movie(string t, int y) { title = t; year = y; }

//Function getMovieTitle string Movie::getMovieTitle() { if(title == "") { return "No name assigned."; } else { return title; } }

//Function getYear int Movie::getYear() { return year; }

//Function setMovieTitle void Movie::setMovieTitle(string t) { title = t; }

//Function setYear void Movie::setYear(int y) { year = y; }

//Function print void Movie::print() { cout

//Function sameYear bool Movie::sameYear(Movie m) { return (year == m.getYear()); }

//Destructor Movie::~Movie(){}

//Movie.cpp code ends here

--------------------------------------------------------------------------------------------------------------------------------------------------

Original instruction of this problem:

Provided main.cpp:

#include "Movie.h"

#include

#include

using namespace std;

int main()

{

//create an object of the Movie class

//use overloaded constructor

Movie movie1("Jurassic World", 2015);

//test function getName

cout

//test function getYear

if (movie1.getYear() == 0)

cout

else

cout

//test functions setName and setYear

movie1.setMovieTitle("Deadpool");

movie1.setYear(2016);

//create another three objects of the Movie class

Movie movie2("Zootopia", 2016);

Movie movie3("John Wick", 2014);

Movie movie4("John Wick: Chapter 2", 2017);

//test function print

cout

movie1.print();

cout

movie2.print();

cout

movie3.print();

cout

movie4.print();

cout

//test function sameYear

if (movie1.sameYear(movie2))

cout

else

cout

if (movie1.sameYear(movie3))

cout

else

cout

if (movie1.sameYear(movie4))

cout

else

cout

// ---------------------------------------LEAVE A BLANK LINE

//create an object of the Movie class using the default constructor

Movie movie5;

cout

if (movie5.getYear() == 0)

cout

else

cout

movie5.setMovieTitle("Fight Club");

movie5.setYear(1999);

movie5.print();

cout

cout

return 0;

}

Provided main.cpp:

#include "Movie.h"

#include

#include

using namespace std;

int main()

{

//create an object of the Movie class

//use overloaded constructor

Movie movie1("Jurassic World", 2015);

//test function getName

cout

//test function getYear

if (movie1.getYear() == 0)

cout

else

cout

//test functions setName and setYear

movie1.setMovieTitle("Deadpool");

movie1.setYear(2016);

//create another three objects of the Movie class

Movie movie2("Zootopia", 2016);

Movie movie3("John Wick", 2014);

Movie movie4("John Wick: Chapter 2", 2017);

//test function print

cout

movie1.print();

cout

movie2.print();

cout

movie3.print();

cout

movie4.print();

cout

//test function sameYear

if (movie1.sameYear(movie2))

cout

else

cout

if (movie1.sameYear(movie3))

cout

else

cout

if (movie1.sameYear(movie4))

cout

else

cout

// ---------------------------------------LEAVE A BLANK LINE

//create an object of the Movie class using the default constructor

Movie movie5;

cout

if (movie5.getYear() == 0)

cout

else

cout

movie5.setMovieTitle("Fight Club");

movie5.setYear(1999);

movie5.print();

cout

cout

return 0;

--

rite the interface (Movie.h) and the implementation (Movie.cpp) of the class Movie according to the requirements listed below:

Member variables: _Title of the movie stored as a string _Year when the movies was released stored as an int Default constructor Overloaded constructor: Parameter: A string storing a movie title and an int storing the year when the movie was released Function getMovieTitle: Returns the name of the movie. Function getYear: Returns the year when the movie was released. Function setMovieTitle: _Parameter: a string storing a movie title _Replaces the name of the movie stored in the calling object with the name passed by the parameter. Function setYear _Parameter: an int storing a year _Replaces the year of the movie stored in the calling object with the year passed by the parameter. Function print: Prints the movie title and the year in this format: Title (year) Function sameYear: _Parameter: An object of the class Movie _Compares the year of the movie stored in the calling object to the year of the movie passed by the parameter object. _Returns true if the year when they were released are the same, false otherwise. Destructor: Left empty

Output must look exactly as below:

image text in transcribed

Movie 1: Jurassic World Released in: 2015 Movie 1 - Deadpool (2016) Movie 2 - Zootopia (2016) Movie 3 - John Wick (2014) Movie 4 - John Wick: Chapter 2 (2017) Movie 1 and movie 2 were released the same year. Movie 1 and movie 3 were NOT released the same year. Movie 1 and movie 4 were not released the same year. Movie 5: No name assigned. No data available. Fight Club (1999)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

IBM Db2 11 1 Certification Guide Explore Techniques To Master Database Programming And Administration Tasks In IBM Db2

Authors: Mohankumar Saraswatipura ,Robert Collins

1st Edition

1788626915, 978-1788626910

More Books

Students also viewed these Databases questions

Question

Discuss communication challenges in a global environment.

Answered: 1 week ago