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

Design a class Movie that contains information about a movie. The class has the

ID: 3575141 • Letter: D

Question

Design a class Movie that contains information about a movie. The class has the following attributes (member variables): The movie name The MPA A rating (for example, G, PG, PG-13, R) The number of people that have rated this movie as a 1 (Terrible) The number of people that have rated this movie as a 2 (Bad) The number of people that have rated this movie as a 3 (OK) The number of people that have rated this movie as a 4 (Good) The number of people that have rated this movie as a 5 (Great) The class should have the following member functions: A constructor that allows the programmer to create the object with a specified name and MPAA rating. The number of people rating the movie should be set to 0 in this constructor. Accessory and matador functions for the movie name and MPAA rating A function add Rating that takes an integer as an input parameter. The function should verify that the parameter is a number between 1 and 5, and if so, increment the number of people rating the movie that match the input parameter. For example, if 3 is the input parameter, then the number of people that rated the movie as a 3 should be incremented by 1. A function getAverage that returns the average value for all of the movie ratings Test the class by writing a main function that creates at least two movie objects by calling the constructor, adds at least five ratings for each movie (ideally the ratings are from the user input), and outputs the movie name. MPAA rating, and average rating for each movie object.

Explanation / Answer

//Headers used
#include <iostream>

using namespace std;
//class creation movie
class Movie {
   //function and varible declarations
   public:
      void addRating( void );
      double getAverage( void );
      Movie(); // This is the constructor

   private:
      int rating[5];
};

// Member functions definitions including constructor
Movie::Movie(void) {
   //cout << "Object is being created" << endl;
}
//function defination for reading inputs
void Movie::addRating(void) {
   int x;
   cout << "Enter rating : 1- Terrible 2-Bad 3-Ok 4-Good 5-Great" << endl;
   //loop to read five user ratings and store ib rating array
   for (int i=0;i<5;i++)
   {
       cout<<"Enter user"<<i+1<< "rating"<<endl;
       cin >> x;
       //validation of input rating
       if(x<1 || x>5)
       {
           cout << "Inavalid Rating" <<endl;
           cout<<"Enter user"<<i+1<< "rating"<<endl;
           cin >> x;
       }
      
       rating[i]=x;
   }
  

}
//function to calculate average rating
double Movie::getAverage( void ) {
   double sum=0;
   double avg;
  
   for (int i=0;i<5;i++)
   {
      
       sum=sum+rating[i];
   }
  
   avg=sum/5;
   //cout << avg;
   return avg;
}

// Main function for the program
int main( ) {
    Movie m1;
    m1.addRating();
   cout << "Movie1 rating : " << m1.getAverage() <<endl;
   Movie m2;
    m2.addRating();
   cout << "Movie2 rating : " << m2.getAverage() <<endl;

   return 0;
}

Output :


Enter rating : 1- Terrible        2-Bad           3-Ok   4-Good          5-Great
Enter user1rating
5
Enter user2rating
8
Inavalid Rating
Enter user2rating
2
Enter user3rating
3
Enter user4rating
3
Enter user5rating
1
Movie1 rating : 2.8

Enter rating : 1- Terrible        2-Bad           3-Ok   4-Good          5-Great
Enter user1rating
2
Enter user2rating
2
Enter user3rating
2
Enter user4rating
2
Enter user5rating
2
Movie2 rating : 2

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