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...
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 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
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.
Write C++ program Consider the following SimpleString class: class simpleString {     public:          simpleString( );...
Write C++ program Consider the following SimpleString class: class simpleString {     public:          simpleString( );                                 // Default constructor          simpleString(int mVal );                    // Explicit value constructor          ~simpleString() { delete [ ] s;}          // Destructor void readString();                              // Read a simple string          void writeString() const;                    // Display a simple string char at(int pos) const;                       // Return character at (pos)          int getLength() const;                        // Return the string length          int getCapacity() const;...
Write in Java the following: A.  A bank account class that has three protected attributes: account number...
Write in Java the following: A.  A bank account class that has three protected attributes: account number (string), customer name (string), and balance (float). The class also has a parameterized constructor and a method public void withDraw (float amount) which subtracts the amount provided as a parameter from the balance. B. A saving account class that is a child class of the bank account class with a private attribute: penality rate (float). This class also has a parameterized constructor and a...
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score...
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score (int). A constructor expects a name as a parameter. A method getLevel to get the level(char) of the student. score level table: A: score >= 90 B: score >= 80 and < 90 C: score >= 60 and < 80 D: score < 60 Example:          Student student = new Student("Zack"); student.score = 10; student.getLevel(); // should be 'D'. student.score = 60; student.getLevel(); //...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT