Question
For this assignment you will work on C++. You are being provided with a class called Movie that stores the following information about a movie:
For this assignment you will work on C++. You are being provided with a class called Movie that stores the following information about a movie:
The movie name
The movie release year
The total number of ratings (total number of people that have rated the movie)
The number of people that have given the movie a 1-star rating
The number of people that have given the movie a 2-star rating
The number of people that have given the movie a 3-star rating
The number of people that have given the movie a 4-star rating
The number of people that have given the movie a 5-star rating
Implement the following member functions for the class:
Movie(string, int);
double averageRating();
void addRating(int);
class Movie { private:
//creates a movie object with the given name and release year //returns the avg. rating for the movie //adds a rating (from 1 to 5) to the movie
string name; int release_year; int ratings_count, ratings1, ratings2, ratings3, ratings4, ratings5;
public: Movie(string n, int y);
double averageRating() const; void addRating(int r); friend ostream &operator<<( ostream &output, const Movie &M ) {
//OVERLOADED OUTPUT OPERATOR (do not modify) cout << M.name<< ", " << M.release_year < } }; Copy the main function provided below in your program. It makes use of the Movie class. Once you have implemented the member functions of the class, it should run and display the following: int main() { //Create Movie objects Movie lord1("Lord of the Rings: The Fellowship of the Ring",2001); Movie lord2("Lord of the Rings: The Return of the King",2003); //lord1 RATINGS //Add 5 ratings of 5stars to lord1 object for (int i=1; i<=5; i++) lord1.addRating(5); //Add 15 ratings of 4stars to lord1 object for (int i=1; i<=15; i++) lord1.addRating(4); //Add 5 ratings of 3stars for (int i=1; i<=5; i++) lord1.addRating(3); //Add 2 ratings of 2stars lord1.addRating(2); lord1.addRating(2); //lord2 RATINGS //Add 3 ratings of 4stars for (int i=1; i<=3; i++) lord2.addRating(4); //Add 1 ratings of 2stars lord2.addRating(2); //Add 1 ratings of 1stars lord2.addRating(1); //PRINT MOVIES AND AVERAGE RATINGS cout << "FIRST MOVIE" << endl << lord1<< endl << endl; cout << "SECOND MOVIE" << endl << lord2 << endl << endl; } Finally, modify the main program to create three more movies of your choice with at least 5 ratings each, and display the movies to screen.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started