Create a class named Movie that can be used with your video rental business. The
ID: 3837709 • Letter: C
Question
Create a class named Movie that can be used with your video rental business. The Movie class should track the Motion Picture Association of America (MPAA) rating (e.g., Rated G, PG-13, R), ID Number, and movie title with appropriate accessor and mutator methods. Also create an equals() method that overrides object's equals() method, where two movies are equal if their ID number is identical. Next, create three additional classes named Action, comedy, and Drama that are derived from Movie. Finally, create an overridden method named calcLateFees that takes as input the number of days a movie is late and returns the late fee for that movie. The default late fee is $2/day. Action movies have a late fee of $3/day, comedies are $2.50/day, and dramas are $2/day. Test your classes from a main method.Explanation / Answer
#include<iostream.h>
#include<string>
using namespace std;
class Movie {
private:
int ID;
string title;
string rating;
public:
void setID(int n){
ID = n;
}
void settitle(string str){
title = str;
}
void setrating(string str){
rating = str;
}
int getID(){
return ID;
}
string gettitle(){
return title;
}
string getrating(){
return rating;
}
bool equals(Movie mov){
if (mov.getID() == ID)
return true;
else
return false;
}
virtual float calcLateFees(int n){
return 2 * n;
}
};
class Action : public Movie {
public:
float calcLateFees(int n){
return 3 * n;
}
};
class Comedy : public Movie {
public:
float calcLateFees(int n){
return 2.5 * n;
}
};
class Drama : public Movie {
public:
float calcLateFees(int n){
return 2 * n;
}
};
void main() {
Movie *ptr;
Action act;
Comedy com;
Drama ds;
string title, rating;
int dayslate;
cout << "Enter action movie title rating" << endl
cin >> title >> rating;
act.setID(1);
act.settitle(title);
act.setrating(rating);
cout << "Enter comedy movie title rating" << endl
cin >> title >> rating;
com.setID(2);
com.settitle(title);
com.setrating(rating);
cout << "Enter Drama movie title rating" << endl
cin >> title >> rating;
dr.setID(3);
dr.settitle(title);
dr.setrating(rating);
cout << "Action Movie details" << endl;
cout << act.getID() << " " << act.gettitle() << " " << act.getrating() << endl;
cout << "Comedy Movie details" << endl;
cout << com.getID() << " " << com.gettitle() << " " << com.getrating() << endl;
cout << "Drama Movie details" << endl;
cout << dr.getID() << " " << dr.gettitle() << " " << dr.getrating() << endl;
ptr = &act;
cout << "Enter no of days for all the movies" << endl;
cin >> dayslate;
cout << "Late Fees for action movies:" << endl;
cout << ptr->calcLateFees(dayslate);
cout << "Late Fees for Comedy movies:" << endl;
ptr = &com;
cout << ptr->calcLateFees(dayslate) << endl;
cout << "Late Fees for Darama movies:" << endl;
ptr = &dr;
cout << ptr->calcLateFees(dayslate) << endl;
cout << act.equals(com);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.