Question
PLEASE COVERT THIS TO PYTHON #include using namespace std; class Movie { private: //creates a movie object with the given name and release year //returns
PLEASE COVERT THIS TO PYTHON
#include
using namespace std;
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 = 0, ratings1=0, ratings2=0, ratings3=0, ratings4=0, ratings5=0;
public: Movie(string n, int y) { name = n; release_year= y; }
double averageRating() const { return (float(ratings1*1+ ratings2*2 +ratings3*3 +ratings4*4 +ratings5*5) / ratings_count ); } void addRating(int r) { switch(r){ case 1: ratings_count += 1; ratings1++; break; case 2: ratings_count += 1; ratings2++; break; case 3: ratings_count += 1; ratings3++; break; case 4: ratings_count += 1; ratings4++; break; case 5: ratings_count += 1; ratings5++; break; default: cout<<"Please add a number between 1 to 5:"; } } friend ostream &operator<<( ostream &output, const Movie &M ) {
//OVERLOADED OUTPUT OPERATOR (do not modify) cout << M.name<< ", " << M.release_year < return output; } }; 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++) 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++) for (int i=1; i<=15; i++) { lord1.addRating(4); } //Add 5 ratings of 3stars for (int i=1; i<=5; i++) for (int i=1; i<=5; i++){ lord1.addRating(3); } lord1.addRating(2); lord1.addRating(2); //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++) for (int i=1; i<=3; i++){ lord2.addRating(4); } lord2.addRating(2); //Add 1 ratings of 2stars lord2.addRating(2); lord2.addRating(1); //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; // 3 Movies of my choice Movie turbo("Turbo", 2014); for(int i=1;i<=5;i++) { turbo.addRating(5); } for(int i=1;i<=2;i++) { turbo.addRating(4); } Movie avengers("Avengers", 2012); for(int i=1;i<=50;i++) { avengers.addRating(5); } for(int i=1;i<=20;i++) { avengers.addRating(4); } for(int i=1;i<=30;i++) { avengers.addRating(3); } cout << "FIRST MOVIE" << endl << turbo<< endl << endl; cout << "SECOND MOVIE" << endl << avengers << endl << endl; }
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