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

Must be written in C++. Thank you. Problem 3 Overview: You will be writing a pro

ID: 3743842 • Letter: M

Question

Must be written in C++.

Thank you.

Problem 3 Overview: You will be writing a program that defines a class to store movie information. Specifics: 1. Define a class named Movie. It should store three pieces of information the movie title as a string, the year it was released as an integer, and the rating from 0 to 10 as a float. 2. For each of the three members you created in step (1), write a function to get the value (accessor) and a function to set the value (mutator). The accessor function should take no arguments and return the member. The mutator function should take one argument representing the new value for that member, then set the member to be the new value without returning anything. These six accessors and mutators should look like this: std::string Movie: :getTitle(); void Movie::setTitle(std::string newTitle); int Movie: :getYear); void Movie: :setTitle(int newYear); float Movie::getRating(); void Movie::setRating(float newRating); 3. Write two constructors for the class. The first one should take no arguments and set the title to "unknown", the year to 2018, and the rating to 0.0. The second one should take three arguments representing the initial title, year, and rating, then set the class variables to be those arguments. 4. Have the program create three instances of the Movie class, then test all the methods in steps (2) and (3) at least once each.

Explanation / Answer


Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you
Movie.h
--------

#ifndef Movie_h
#define Movie_h
#include <iostream>
class Movie{
private:
std::string title;
int year;
float rating;
public:
Movie();
Movie(std::string newTitle, int newYear, float newRating);
std::string getTitle();
void setTitle(std::string newTitle);
int getYear();
void setYear(int newYear);
float getRating();
void setRating(float newRating);
};
#endif /* Movie_h */

Movie.cpp
--------
#include "Movie.h"
Movie::Movie(){
title = "unknown";
year = 2018;
rating = 0.0;
}
Movie::Movie(std::string newTitle, int newYear, float newRating){
title = newTitle;
year = newYear;
rating = newRating;
}
std::string Movie::getTitle(){
return title;
}
void Movie::setTitle(std::string newTitle){
title = newTitle;
}
int Movie::getYear(){
return year;
}
void Movie::setYear(int newYear){
year = newYear;
}
float Movie::getRating(){
return rating;
}
void Movie::setRating(float newRating){
rating = newRating;
}


MovieTest.cpp
--------
#include <iostream>
#include "Movie.h"
using namespace std;
int main(){
Movie m1;
Movie m2("Avengers: Infinity War", 2018, 9.0);
Movie m3("Jurassic World: Fallen Kingdom", 2018, 7.5);
cout << "Setting values for movie 1" << endl;
m1.setTitle("Captain America: Civil War");
m1.setYear(2016);
m1.setRating(8.2);

cout << "Movie1" << endl;
cout << "Title: " << m1.getTitle() << " Year: " << m1.getYear() << " Rating: " << m1.getRating() << endl << endl;
cout << "Movie2" << endl;
cout << "Title: " << m2.getTitle() << " Year: " << m2.getYear() << " Rating: " << m2.getRating() << endl << endl;
cout << "Movie3" << endl;
cout << "Title: " << m3.getTitle() << " Year: " << m3.getYear() << " Rating: " << m3.getRating() << endl << endl;
}

output
-----
Setting values for movie 1
Movie1
Title: Captain America: Civil War
Year: 2016
Rating: 8.2
Movie2
Title: Avengers: Infinity War
Year: 2018
Rating: 9
Movie3
Title: Jurassic World: Fallen Kingdom
Year: 2018
Rating: 7.5