Question

In: Computer Science

C++ Consider a class Movie that information about a movie. The class has the following attributes:...

C++

Consider a class Movie that information about a movie. The class has the following attributes:

• The movie name

• The MPAA rating (for example, G, PG, PG-13, R)

• Array of size 5 called Ratings, each index will hold the following.

[0] The number of people that have rated this movie as a 1 (Terrible)

[1] The number of people that have rated this movie as a 2 (Bad)

[2] The number of people that have rated this movie as a 3 (OK)

[3]The number of people that have rated this movie as a 4 (Good)

[4]The number of people that have rated this movie as a 5 (Great)

Implement the C ++ class with accessor (getter) and mutator (setter) functions for the movie name and MPAA rating. Write a function addRating that takes an integer as input parameter. The function should verify that the parameter is 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. Write another function, getAverage, that returns the average value for all of the movie ratings. Finally, add a constructor that allows the programmer to create the object with a specific name and MPAA rating. The number of people rating the movie should be set to 0 in the constructor. Test the class by writing a main function that creates at least two movie objects, add at least five ratings for each movie, and outputs the movie name, MPAA rating, and average rating for each movie object.

Solutions

Expert Solution

Program Plan:

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).

An array to store the movie ratings .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).

Implement the class with accessor(getter) and mutator(setter) functions for the movie name and MPAA rating.

Write 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.

Write another function, getAverage, that returns the average value for all of the movie ratings. Finally, add 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. Test the class by writing a main function that creates at least two movie objects, adds at least five ratings for each movie, and outputs the movie name, MPAA rating, and average rating for each movie object.

c++ program:

#include<iostream>
using namespace std;
class Movie
{
private:
string name;
int rating[5], rate;
int terrible = 0, bad = 0, ok = 0, good = 0, great = 0;
string MPAA;
double average = 0;
public:
Movie()
{ }
Movie(string Name, string mpaa)
{
name = "The Adjustment Bureau";
MPAA = "PG-13";
rate = 0;
for(int i = 0; i < 5; i++)
{
rating[i] = 0;
}
}
void setname(string nam)
{
name = nam;
}
string getname()
{
return name;
}
void setrating(string mpaa)
{
MPAA = mpaa;
}
string getrating()
{
return MPAA;
}
void addRating(int rate)
{
if(rate >= 1 && rate <= 5)
{
rating[rate - 1]++;
}
switch(rate)
{
case 1:
terrible++;
break;
case 2:
bad++;
break;
case 3:
ok++;
break;
case 4:
good++;
break;
case 5:
great++;
break;
}
}
double getAverage()
{
int total;
total = 0; rate = 0;
for(int i = 0; i < 5; i++)
{
rate = rate + rating[i];
total = total + rating[i] * (i + 1);
}
if(rate > 0)
{
return (total / rate);
}
else
return 0;
}
int display()
{
cout<<"\n Name: "<<getname();
cout<<"\n MPAA: " <<getrating();
cout<<"\n Average Rating: " <<getAverage();
cout<<"\n The people have rated tihs movie as 1 (Terrible): " <<terrible;
cout<<"\n The people have rated tihs movie as 2 (Bad): " <<bad;
cout<<"\n The people have rated tihs movie as 3 (Ok): " <<ok;
cout<<"\n The people have rated tihs movie as 4 (Good): " <<good;
cout<<"\n The people have rated tihs movie as 5 (Great): " <<great;
return 0;
}
};
int main()
{
Movie m, m1;
string name, rating;
m.setname("Criminal");
m.setrating("PG");
m.getAverage();
  
m.addRating(5);
m.addRating(5);
m.addRating(4);
m.addRating(5);
m.addRating(5);
m.display();
  
cout<<endl;
m1.addRating(3);
m1.addRating(2);
m1.addRating(2);
m1.addRating(4);
m1.addRating(1);
m1.setname("Mr India");
m1.setrating("PG-13");
m1.getAverage();
m1.display();
return 0;
}

Output:

Name: Criminal
MPAA: PG
Average Rating: 3
The people have rated tihs movie as 1 (Terrible): 0
The people have rated tihs movie as 2 (Bad): 0
The people have rated tihs movie as 3 (Ok): 0
The people have rated tihs movie as 4 (Good): 1
The people have rated tihs movie as 5 (Great): 4
Name: Mr India
MPAA: PG-13
Average Rating: 0
The people have rated tihs movie as 1 (Terrible): 1
The people have rated tihs movie as 2 (Bad): 2
The people have rated tihs movie as 3 (Ok): 1
The people have rated tihs movie as 4 (Good): 1
The people have rated tihs movie as 5 (Great): 0



Related Solutions

Consider a class Movie that information about a movie. The class has the following attributes: • ...
Consider a class Movie that 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...
Consider a class Book that contains information about a Book. The class should has the following...
Consider a class Book that contains information about a Book. The class should has the following attributes: • The title of the book • The author of the book • Year of publication (e.g. 1994) • The number of people that have rated this book as a 1 (Terrible) • The number of people that have rated this book as a 2 (Bad) • The number of people that have rated this book as a 3 (OK) • The number...
Code in C# Part 1 Build a Series class that has the following attributes and behaviors:...
Code in C# Part 1 Build a Series class that has the following attributes and behaviors: Attributes 1.) A name -- this can be any string value (i.e. “Firefly”) 2.) A number of episodes -- this can be any non-negative integer value 3.) An episode length -- this can be a double value, in hours, representing the length of an episode (i.e. 0.5 for a half-hour episode, or 0.37 for a 23 minute episode) 4.) A forKids attribute that holds...
C++ The following is a specification of three classes: Class Vehicle:       Attributes:       Age, an...
C++ The following is a specification of three classes: Class Vehicle:       Attributes:       Age, an integer à The age of the vehicle       Price, a float à The price of the vehicle       Behaviors: Vehicle() à default constructor sets age=0, and price=0.0 setAge()   à Takes an integer parameter, returns nothing setPrice() à Takes a float parameter, returns nothing getAge()   à Takes no parameters, returns the vehicle’s age getPrice() à Takes no parameters, returns the vehicle’s price End Class Vehicle...
In C++ Demonstrate inheritance. Create an Airplane class with the following attributes: • manufacturer : string...
In C++ Demonstrate inheritance. Create an Airplane class with the following attributes: • manufacturer : string • speed : float Create a FigherPlane class that inherits from the Airplane class and adds the following attributes: • numberOfMissiles : short
Write a class encapsulating the concept of a student, assuming a student has the following attributes:...
Write a class encapsulating the concept of a student, assuming a student has the following attributes: a name, a Social Security number, and a GPA (for instance, 3.5). Include a constructor, the accessors and mutators, and methods toString and equals. Write a client class (test driver with main method) to test all the methods in your class (create 2 student objects, print the name, social security number and GPA of the 2 students, check if the two student’s GPA is...
Write a class encapsulating a board game. A board game has the following additional attributes: the...
Write a class encapsulating a board game. A board game has the following additional attributes: the number of players and whether the game can end in a tie. Code the constructor and the toString method of the new class. You also need to include a client class(with the main method) to test your code. code in Python
write a C++ program to CREATE A CLASS EMPLOYEE WITH YOUR CHOICE OF ATTRIBUTES AND FUNCTIONS...
write a C++ program to CREATE A CLASS EMPLOYEE WITH YOUR CHOICE OF ATTRIBUTES AND FUNCTIONS COVERING THE FOLLOWING POINTS: 1) COUNTING NUMBER OF OBJECTS CREATED ( NO OBJECT ARRAY TO BE USED) USING ROLE OF STATIC MEMBER 2) SHOWING THE VALID INVALID STATEMENTS IN CASE OF STATIC MEMBER WITH NON STATIC MEMBER FUNCTION, NON STATIC MEMBERS OF CLASS WITH STATIC MEMBER FUNCTION, BOTH STATIC. SHOW THE ERRORS WHERE STATEMENTS ARE INVALID. 3) CALL OF STATIC MEMBER FUNCTION, DECLARATION OF...
The following information pertains to the Big Returns Fund: Cost Class "A" Class "B" Class "C"...
The following information pertains to the Big Returns Fund: Cost Class "A" Class "B" Class "C" Front-end load 5.57 0.00 0.00 Back-end load 0.00 5.34 0.89 Declining 1% per year First year only Management fee 0.80 0.80 0.80 12b-1 fee 0.30 0.60 0.80 For each share class, calculate (1) how much you would pay in initial commissions, (2) how much you would pay in back-end commissions if you sold after two years, (3) how much in value is lost to...
(Rectangle Class) Create class Rectangle. The class has attributes length and width, each of which defaults...
(Rectangle Class) Create class Rectangle. The class has attributes length and width, each of which defaults to 1. It has read-only properties that calculate the Perimeter and the Area of the rectangle. It has properties for both length and width. The set accessors should verify that length and width are each floating-point numbers greater than 0.0 and less than 20.0. Write an app to test class Rectangle. this is c sharp program please type the whole program.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT