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

I need help with C++! Here\'s the program: (OOP: The Movie Class) Design a class

ID: 3767325 • Letter: I

Question

I need help with C++! Here's the program:

(OOP: The Movie Class) Design a class Movie that contains information about a movie. The class has the following attributes (member variables):

• The movie name
• The MPAA 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.
• Accessor and mutator functions for the movie name and MPAA rating
• A function addRating 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

Here is the code for you. If you need any further refinements, just get back to me.

#include <iostream>
using namespace std;

class Movie
{
string movieName;
string MPAARating;
int rating[6];
public:
Movie(string name, string rating)   //Constructor.
{
movieName = name;
MPAARating = rating;
for(int i = 1; i < 6; i++)           //Assigning 0 to each rating.
rating[i] = 0;
}
void setMovieName(string name)           //Mutator for setting the movie name.
{
movieName = name;
}
void setMPAARating(string rating)           //Mutator for setting the movie rating.
{
MPAARating = rating;
}
string getMovieName()                       //Accessor for getting the movie name.
{
return movieName;
}
string getMPAARating()                       //Accessor for getting the movie rating.
{
return MPAARating;
}
void addRating(int rate)
{
if(rate > 0 && rate < 6)
rating[rate]++;
}
double getAverage()
{
int sum = 0, count = 0;
for(int i = 1; i < 6; i++)
{
sum += (rating[i] * i);
count += rating[i];
}
return (double)sum / count;
}
};

int main()
{
Movie mv1 ("Asylum", "PG");
Movie mv2 ("Species", "G");
int mv1Count = 0, mv2Count = 0;
int rating, movie;
while(true)
{
cout<<"Select the movie to rate: 1. Asylum 2. Species: ";
cin>>movie;
cout<<"Enter the rating (1: Terrible. 2: Bad. 3: OK. 4: Good. 5: Great ): ";
cin>>rating;
if(movie == 1)
{
mv1Count++;
mv1.addRating(rating);
}
else if(movie == 2)
{
mv2Count++;
mv2.addRating(rating);
}
else
cout<<"Invalid movie choice."<<endl;
cout<<"Do you want to rate another movie (Y for Yes): ";
char anotherMovie;
cin>>anotherMovie;
if(anotherMovie != 'Y' && anotherMovie != 'y')
break;
}
cout<<mv1.getMovieName()<<" has an MPAA Rating: "<<mv1.getMPAARating()<<" has an average user rating: "<<mv1.getAverage()<<endl;
cout<<mv2.getMovieName()<<" has an MPAA Rating: "<<mv2.getMPAARating()<<" has an average user rating: "<<mv2.getAverage()<<endl;
}

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