//implmentaion file for Movie class // Author: // date: // known bug: none #include #include using namespace std; #include "Movie.h" Movie::Movie() { cout <<"Default constructor is called\n"; name=string(""); MPAA_rating=string(""); for (int i=0;i<=5;i++) peopleRated[i]=0; } Movie::Movie(string n, string r) { cout <<"Constructor with two parameters is called\n"; name = n; MPAA_rating = r; for (int i=0;i<=5;i++) peopleRated[i]=0; } Movie::~Movie() { cout <<"destructor called\n"; cout <<"Nothing special needs to be done\n"; } //return the movie name of the calling object string Movie::GetName () const{ return name; // return this->name; } //return MPAA rating of the calling object string Movie::GetRating () const { return MPAA_rating; } //set conresponding fields of calling object void Movie::SetName (string newName) { name = newName; // this->name = newName; } void Movie::SetRating (string newRating) { assert (newRating=="R" || newRating=="PG-13"); MPAA_rating = newRating; } //Please finish all above functions..... in 15 mins. // rating is between 1 and 5 // increment the corresponding counter void Movie::AddRating (int rating) { assert (rating >=1 && rating<=5); peopleRated[rating]+=1; } // calculate and return avergage rating of the calling object float Movie::GetAverageRating () const { double totalRating=0.0; int totalPeople=0; for (int i=1;i<=5;i++) { totalRating += i*peopleRated[i]; totalPeople+=peopleRated[i]; } if (totalPeople==0) return 0.0; else return (totalRating/totalPeople); }