Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider a class Movie that contains the following information about a movie: *

ID: 3843040 • Letter: C

Question

Consider a class Movie that contains the following information about a movie: * Title * MPAA Rating (e.g. G, PG, PG-13, R) * Number of people who rated this movie as a 1 * Number of people who rated this movie as a 2 * Number of people who rated this movie as a 3 * Number of people who rated this movie as a 4 * Number of people who rated this movie as a 5 Implement the Movie class such that it is able to contain the above information. Include a constructor that would accept two parameters and initialize the movie's title to the value of its first parameter and the movie's MPAA rating to the value of its second parameter, and public rating to 0. Also include accessor member functions for title and MPAA rating. Include a member function to increment the public rating that will only accept integer values between 1 and 5. Finally, write a member function that would return the average public rating of a movie. Write a program that would use your Movie class by first asking the user to input movie title and MPAA rating, then create an object using the constructor, and then allow the user to enter a space-separated list of people ratings, terminating with -1. Finally, the program will output the title of the movie, its MPAA rating, and its average public rating.

Explanation / Answer

#include <iostream>
#include <string>

using namespace std;

class Movie
{
private:
   string movieName, MPAARating;
   int numRate[5];

public:
   Movie(string movie)
   {
       movieName = movie;
       MPAARating=5;
       numRate[0]=0;
       numRate[1]=0;
       numRate[2]=0;
       numRate[3]=0;
       numRate[4]=0;
   }


   Movie() // Default Constructor
   {
       MPAARating=5;
       numRate[0]=0;
       numRate[1]=0;
       numRate[2]=0;
       numRate[3]=0;
       numRate[4]=0;
   }
  
   string getMovieName()
   {
       return movieName;
   }
  
   void setMovieName (string str)
   {
       movieName = str;
   }
  
   string getMPAARating()
   {
       return MPAARating;
   }
  
   void setMPAARating (string str)
   {
       MPAARating = str;
   }
  

void addRating(int num)
   {
       int i = num;
       if( num>0 && num <= 5)
       {
           this->numRate[i-1]++;
       }
      
       else
       {
           cout <<"Number out of range."<<endl;
       }
   }
  
   double getAverage()
   {
       double num = numRate[0]+numRate[1]+numRate[2]+numRate[3]+numRate[4];
       double denom = 5.0;
       double result = num/denom;

       return result;
   }
};

int main()
{  
   string setMovieName;
   int rating;
   char again = 'y';

   cout << "Insert a movie name: ";
   char c = 0;
   while(c !=' ')
   {
       c = cin.get();
       setMovieName.push_back(c);
   }
  
   setMovieName.erase(setMovieName.end() - 1); //setMovieName.erase(setMovieName.begin() + setMovieName.size() - 1);

   Movie obj1(setMovieName);

   while (again == 'y' || again == 'Y')
   {
       cout << "Add the rating of the movie (1-5): ";
       cin >> rating;
       obj1.addRating(rating);

       cout << "Add more ratings? (y/n): ";
       cin >> again;
   }

   cout << " Insert a movie name: ";
   c = 0;
   while(c !=' ')   
   {
       c = cin.get();
       setMovieName.push_back(c);
   }
  
   setMovieName.erase(setMovieName.end() - 1);

   Movie obj2(setMovieName);

   again = 'y';

   while (again == 'y' || again == 'Y')
   {
       cout << "Add the rating of the movie (1-5): ";
       cin >> rating;
       obj2.addRating(rating);

       cout << "Add more ratings? (y/n): ";
       cin >> again;
   }
      
   double ave1 = obj1.getAverage();
   double ave2 = obj2.getAverage();

   cout <<" Average rating for "<< obj1.getMovieName() <<": " <<ave1<<endl;
   cout <<"Average rating for "<< obj2.getMovieName() <<": " <<ave2<<endl;

   system("pause");
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote