[C++] Consider a class Movie that contains information about a movie. The class
ID: 3877116 • Letter: #
Question
[C++]
Consider a class Movie that contains information about a movie. The class has the following attributes:
The movie name
The MPAA rating (e.g. 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)
Implement the class with accessors and mutators for the movie name and MPAA rating. Write a method addRating that takes an integer as an input parameter. The method should verify that the parameter is a number between 1 and 5, and if so, increment by one the number of people rating the movie that matches 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 one. Write another method, getAverage, that returns the average value for all the movie ratings.
Test the class by writing a main method that creates at least two movie objects, adds at least five ratings for each movie, and output the movie name, MPAA rating, and average rating for each movie object.
AverageGrade that is very similar to the MovieRatings project, but it only is inputting one string (className) instead of both the movie name and the MPAA rating. Another difference is that the AverageGrade program scores grades A to F with point values from 4.0 to 0.0 (highest to lowest) while the MovieRatings scores the rating from 1 to 5 (lowest to highest). When using the AverageGrade program as a reference, make sure that the program for MovieRatings does not use variables such as Acount, Bcount, classSize, etc.
Explanation / Answer
// C++MovieRatings.cpp : Defines the entry point for the console application.
//
// This project implements a program similar to the MovieRatings project. It does not
// provide all of the required 'information' shown on the movie ratings project definition.
// It the movie ratings go from 1 to (bad to worse), but this program has grade from
// A to F (best to worse). These differences need to be taken into account when using
// this program as a reference to build the MovieRatings project.
#include "stdafx.h" // only used by some versions of Microsoft C++
#include "AverageGrade.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
char setmoviname[100],grade=''; //setmoviname- to set moviename entered by user
//grade- to set garde entered by user
int classSize; //grade- to set classsize entered by user
AverageGrade CIS054; // create an object of class AverageGrade
cout << "Enter Name of the Movie" << endl;
cin >> setmoviname;
CIS054.setName(setmoviname);// use mutator to set the class name
cout << "Enter Class Size" <<endl;
cin >> classSize;
cout << "Enter Rating for that Movie " << endl;
for (size_t i = 0; i < classSize; i++)
{
cin >> grade;
CIS054.countGrade(grade);
}
cout << "The average score for " << CIS054.getName() << " is " << CIS054.getAverage() << endl;
#ifdef Second Object
AverageGrade CIS073("Visual Basic Programming"); // create an object of class AverageGrade
CIS073.countGrade('A');
CIS073.countGrade('B');
CIS073.countGrade('A');
CIS073.countGrade('C');
CIS073.countGrade('B');
CIS073.countGrade('A');
CIS073.countGrade('D');
cout << "The average score for " << CIS073.getName() << " is " << CIS073.getAverage() << endl;
#endif
system("PAUSE");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.