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 information about a movie. The class has th

ID: 3700337 • Letter: C

Question

Consider a class Movie that contains information about a movie. The class has the following attributes: 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) Write a program the definition of the class called Movie as following: Create members and member functions for the movie name and MPAA rating. Design a member 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. Design another member function, getAverage( ), that returns the average value for all of the movie ratings. Develop 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 the constructor. In a main program, create at least two movie objects, add at least five ratings for each movie, and output the movie name, MPAA rating, and average rating for each movie object. Use an array to store the movie ratings instead of separate variables. All changes should be internal to the class so the main function to test the class should run identically with either the old Movie class or the new Movie class that uses an array member variable. In the main program, instead of creating separate variables for each Movie object, an array of at least four Movie objects is created with any sample data. Loop through the array and output the name, MPAA rating, and average rating for each of the four movies. (C++)

Explanation / Answer

As mentioned in the question, I have given two class defination.One with rating vriables & another one with rating array. The main() function is same for both the class defination.

1st Part

===========

#include <iostream>
#include <string>
using namespace std;

class Movie{
public:
string name;
string mpaa;
int n1,n2,n3,n4,n5;
float avg;
  
void setName(string s){
name = s;
}
void setMpaa(string s){
mpaa = s;
}
  
string getName(){
return name;
}
string getMpaa(){
return mpaa;
}
  
void addRating(int a){
if (a>=1 && a<=5)
{
if (a == 1)
n1 = n1+ 1;
else if (a == 2)
n2 = n2 + 1;
else if (a == 3)
n3 = n3 + 1;
else if (a == 4)
n4 = n4 + 1;
else
n5 = n5 + 1;
}
}
  
float getAverage(){
avg = (float)(n1+(n2*2)+(n3*3)+(n4*4)+(n5*5))/(float)(n1+n2+n3+n4+n5);
  
return avg;
}
  
Movie(string s1,string s2){
name = s1;
mpaa = s2;
n1 = 0;
n2 = 0;
n3 = 0;
n4 = 0;
n5 = 0;
}
  
Movie(){
n1 = 0;
n2 = 0;
n3 = 0;
n4 = 0;
n5 = 0;
}
};

int main()
{
//here we are creating two movieo bjects
Movie m1("Spiderman","PG");
Movie m2("Superman","G");
  
//adding five ratings for each movie
m1.addRating(4);
m1.addRating(3);
m1.addRating(4);
m1.addRating(5);
m1.addRating(3);
  
m2.addRating(5);
m2.addRating(2);
m2.addRating(4);
m2.addRating(3);
m2.addRating(3);
  
//displaying the output
cout<<"Movie Name : "<<m1.getName()<<endl;
cout<<"MPAA Rating : "<<m1.getMpaa()<<endl;
cout<<"Average Rating : "<<m1.getAverage()<<" "<<endl;
  
cout<<"Movie Name : "<<m2.getName()<<endl;
cout<<"MPAA Rating : "<<m2.getMpaa()<<endl;
cout<<"Average Rating : "<<m2.getAverage()<<" "<<endl;
  
//Again creating array of four movie object
Movie mArray[4];
  
//assigning necessary values to the four movie objects
mArray[0].setName("Avengers");
mArray[0].setMpaa("PG-13");
mArray[0].addRating(5);
mArray[0].addRating(4);
mArray[0].addRating(4);
  
mArray[1].setName("Ironman");
mArray[1].setMpaa("R");
mArray[1].addRating(5);
mArray[1].addRating(3);
mArray[1].addRating(1);
  
mArray[2].setName("Thor");
mArray[2].setMpaa("PG");
mArray[2].addRating(4);
mArray[2].addRating(3);
mArray[2].addRating(3);
  
mArray[3].setName("Captain America");
mArray[3].setMpaa("G");
mArray[3].addRating(4);
mArray[3].addRating(5);
mArray[3].addRating(3);
  
//looping through the movie type array & giving output
for(int i=0;i<4;i++)
{
cout<<"Movie Name : "<<mArray[i].getName()<<endl;
cout<<"MPAA Rating : "<<mArray[i].getMpaa()<<endl;
cout<<"Average Rating : "<<mArray[i].getAverage()<<" "<<endl;
}
  
  
return 0;
}

2nd Part

===========

#include <iostream>
#include <string>
using namespace std;

class Movie{
public:
string name;
string mpaa;
int n[5];//array for storimg the ratings
float avg;
  
void setName(string s){
name = s;
}
void setMpaa(string s){
mpaa = s;
}
  
string getName(){
return name;
}
string getMpaa(){
return mpaa;
}
  
void addRating(int a){
if (a>=1 && a<=5)
{
if (a == 1)
n[0] = n[0] + 1;
else if (a == 2)
n[1] = n[1] + 1;
else if (a == 3)
n[2] = n[2] + 1;
else if (a == 4)
n[3] = n[3] + 1;
else
n[4] = n[4] + 1;
}
}
  
float getAverage(){
avg = (float)(n[0]+(n[1]*2)+(n[2]*3)+(n[3]*4)+(n[4]*5))/(float)(n[0]+n[1]+n[2]+n[3]+n[4]);
  
return avg;
}
  
Movie(string s1,string s2){
name = s1;
mpaa = s2;
n[0] = 0;
n[1] = 0;
n[2] = 0;
n[3] = 0;
n[4] = 0;
}
  
Movie(){
n[0] = 0;
n[1] = 0;
n[2] = 0;
n[3] = 0;
n[4] = 0;
}
};

int main()
{
//here we are creating two movieo bjects
Movie m1("Spiderman","PG");
Movie m2("Superman","G");
  
//adding five ratings for each movie
m1.addRating(4);
m1.addRating(3);
m1.addRating(4);
m1.addRating(5);
m1.addRating(3);
  
m2.addRating(5);
m2.addRating(2);
m2.addRating(4);
m2.addRating(3);
m2.addRating(3);
  
//displaying the output
cout<<"Movie Name : "<<m1.getName()<<endl;
cout<<"MPAA Rating : "<<m1.getMpaa()<<endl;
cout<<"Average Rating : "<<m1.getAverage()<<" "<<endl;
  
cout<<"Movie Name : "<<m2.getName()<<endl;
cout<<"MPAA Rating : "<<m2.getMpaa()<<endl;
cout<<"Average Rating : "<<m2.getAverage()<<" "<<endl;
  
//Again creating array of four movie object
Movie mArray[4];
  
//assigning necessary values to the four movie objects
mArray[0].setName("Avengers");
mArray[0].setMpaa("PG-13");
mArray[0].addRating(5);
mArray[0].addRating(4);
mArray[0].addRating(4);
  
mArray[1].setName("Ironman");
mArray[1].setMpaa("R");
mArray[1].addRating(5);
mArray[1].addRating(3);
mArray[1].addRating(1);
  
mArray[2].setName("Thor");
mArray[2].setMpaa("PG");
mArray[2].addRating(4);
mArray[2].addRating(3);
mArray[2].addRating(3);
  
mArray[3].setName("Captain America");
mArray[3].setMpaa("G");
mArray[3].addRating(4);
mArray[3].addRating(5);
mArray[3].addRating(3);
  
//looping through the movie type array & giving output
for(int i=0;i<4;i++)
{
cout<<"Movie Name : "<<mArray[i].getName()<<endl;
cout<<"MPAA Rating : "<<mArray[i].getMpaa()<<endl;
cout<<"Average Rating : "<<mArray[i].getAverage()<<" "<<endl;
}
  
  
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