Question: 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 << title << " (" << year << ")"; }
//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 << title << " (" << year << ")"; }
//Function sameYear bool Movie::sameYear(Movie m) { return (year == m.getYear()); }
//Destructor Movie::~Movie(){}
//Movie.cpp code ends here
Update: I don't really understand the given instruction to improve my coding style, especially these parts:
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.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
