Question

This challenge is designed to reinforce the skills you leamed about classes and objects. In this challenge, youre going to create a movie class. The movie class will ask the user for the name of their top three favorite movies, what year the movie was released, and what was the rating, whether it was G for General Audience, PG for Parental Guidance, R for Restricted, or M for Mature. I want you to also add logic to make sure its a valid year. Add the logic into the movie class, not in the main program. Then, write a main program that will ask the user for there three favorite movies and then print out a list when youre done. C++ language
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the program in C++. A point to note here is that, I've added some default behaviour in case when year is not valid. It will automatically set the releaseYear to 2000 (apart from printing an error on the screen).

Code:

#include <iostream>
#include <string>

using namespace std;

// Movie class
class Movie
{
// private variables to hold movie related info.
private:
string name;
string rating;
int releaseYear;

// public methods to set or get movie info.
public:

void setName(string movieName)
{
name = movieName;
}
  
string getName()
{
return name;
}
  
void setRating(string movieRating)
{
rating = movieRating;
}
  
string getRating()
{
return rating;
}
  
void setReleaseYear(int year)
{
// apparently, first movie was released in the year 1906.
if(year > 1906 && year < 2018)
{
releaseYear = year;
}
  
// if the release year is not valid, we'll print an error and set it to 2000 by default.
else
{
cout<<"Year "<<year<<" is invalid. A default year 2000 is being set instead.";
releaseYear = 2000;
}
}
  
int getReleaseYear()
{
return releaseYear;
}
  
};

int main()
{
// create 3 movie objects.
Movie m1, m2, m3;

// temporary variables to hold data read from input.
string movieName, rating;
int releaseYear;

// take 1st movie date and assign to m1.
cout<<"Enter 3 of your favorite movies:"<<endl;
cout<<"Name of the 1st movie: ";
cin>>movieName;
cout<<"What type of rating it has? (G, PG, R or M): ";
cin>>rating;
cout<<"When (which year) was it released? ";
cin>>releaseYear;

m1.setName(movieName);
m1.setRating(rating);
m1.setReleaseYear(releaseYear);


// take 2nd movie date and assign to m2.
cout<<"Name of the 2nd movie: ";
cin>>movieName;
cout<<"What type of rating it has? (G, PG, R or M): ";
cin>>rating;
cout<<"When (which year) was it released? ";
cin>>releaseYear;

m2.setName(movieName);
m2.setRating(rating);
m2.setReleaseYear(releaseYear);


// take 3rd movie date and assign to m3.
cout<<"Name of the 3rd movie: ";
cin>>movieName;
cout<<"What type of rating it has? (G, PG, R or M): ";
cin>>rating;
cout<<"When (which year) was it released? ";
cin>>releaseYear;

m3.setName(movieName);
m3.setRating(rating);
m3.setReleaseYear(releaseYear);


// display the same information.
cout<<endl<<"Your favorite movies are:"<<endl;

cout<<"Movie: "<<m1.getName()<<endl;
cout<<"Rating: "<<m1.getRating()<<endl;
cout<<"Release Year: "<<m1.getReleaseYear()<<endl;

cout<<"Movie: "<<m2.getName()<<endl;
cout<<"Rating: "<<m2.getRating()<<endl;
cout<<"Release Year: "<<m2.getReleaseYear()<<endl;

cout<<"Movie: "<<m3.getName()<<endl;
cout<<"Rating: "<<m3.getRating()<<endl;
cout<<"Release Year: "<<m3.getReleaseYear()<<endl;

return 0;

}

Sample output:

When (which year) was it released? 2010 Name of the 2nd movie: Movie2 what type of rating it has? (G, PG, R or M): G When (which year) was it released? 2016 Name of the 3rd movie: Movie3 What type of rating it has? (G, PG, R or M): PG when (which year) was it released? 1800 Year 1800 is invalid. A default year 2000 is being set instead.Your favorite movies are: Movie: Movie1 Rating: M Release Year: 2010 Movie: Movie2 Rating:G Release Year: 2016 Movie: Movie3 Rating: PG Release Year: 2000 Program finished with exit code Press ENTER to exit console

Code screenshots:

Add a comment
Know the answer?
Add Answer to:
C++ language This challenge is designed to reinforce the skills you leamed about classes and objects....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this labwork, you are expected to write java program that assigns ratings to the movies (1-5). You are given the main class of the program(See Lectures). You supposed to write two classes that wor...

    In this labwork, you are expected to write java program that assigns ratings to the movies (1-5). You are given the main class of the program(See Lectures). You supposed to write two classes that works with main class. Movie Class has two attributes: title(String) . rating(int) Reviewer Class has one class variable (array of movies) and three methods: Setmovies: Allow the reviewer's movies to be set . . . rateMovie: Let the reviewer rate one of the movies. pickFavorite: pick...

  • C++ Language I have a class named movie which allows a movie object to take the...

    C++ Language I have a class named movie which allows a movie object to take the name, movie and rating of a movie that the user inputs. Everything works fine but when the user enters a space in the movie's name, the next function that is called loops infinetly. I can't find the source of the problem. Down below are my .cpp and .h file for the program. #include <iostream> #include "movie.h" using namespace std; movie::movie() { movieName = "Not...

  • Netflix Database - PROGRAMMED IN JAVA PLEASE :) In this program, you will build a Netflix...

    Netflix Database - PROGRAMMED IN JAVA PLEASE :) In this program, you will build a Netflix movie database using the provided file, netflix.csv. The file contains more than two hundred records of movies and TV programs, with each record consisting a title, a rating, a release year, and a user rated score. There are three classes that you will need to implement: Movie, NetflixHandler, and NetflixApp. Class: Movie Movie - title: String - rating: String - year: int - score:...

  • MEDIA INHERITANCE - C++ You will create an inheritance set of classes. Use proper rules for...

    MEDIA INHERITANCE - C++ You will create an inheritance set of classes. Use proper rules for data types, class definitions, and inheritance (check input/output of data below). You will create a super media class that will define a general form of media. A media properties will consist of the name and price. The media should be able to construct itself out of the arguments sent to it, virtually print both data fields labeled (price to two decimal places) and overload...

  •    moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring>...

       moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring> using namespace std; typedef struct{ int id; char title[250]; int year; char rating[6]; int totalCopies; int rentedCopies; }movie; int loadData(ifstream &infile, movie movies[]); void printAll(movie movies[], int count); void printRated(movie movies[], int count); void printTitled(movie movies[], int count); void addMovie(movie movies[],int &count); void returnMovie(movie movies[],int count); void rentMovie(movie movies[],int count); void saveToFile(movie movies[], int count, char *filename); void printMovie(movie &m); int find(movie movies[], int...

  • C++ program Correctly complete the following assignment. Follow all directions. The main purpose is to show...

    C++ program Correctly complete the following assignment. Follow all directions. The main purpose is to show super and sub class relationships with an array of super media pointers to sub class objects and dynamic binding. The < operator will be overloaded in the super class so all subclasses can use it. The selection sort method will be in the main .cpp file because it will sort the array created in main. The final .cpp file, the three .h header class...

  • Lab Goal : The lab was designed to teach you more about objects and classes. Lab...

    Lab Goal : The lab was designed to teach you more about objects and classes. Lab Description : In this program, you are to create a Roman Numeral class to handle roman numeral operations. How to convert a Roman Numeral to a standard base ten number : : Locate the first individual roman number in the roman number string. Sum up the numeric value of the individual number. Chop of the individual roman numeral from the string and continue the...

  • Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU...

    Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU START: // This homework is built on homework 06. The given program is an updated version of hw06 solution. It begins by displaying a menu to the user // with the add() function from the last homework, as well as some new options: add an actor/actress to a movie, display a list of movies for // an actor/actress, delete all movies, display all movies,...

  • WONT COMPILE ERROR STRAY / TEXT.H AND CPP PROGRAM SAYING NOT DECLARED HAVE A DRIVER WILL...

    WONT COMPILE ERROR STRAY / TEXT.H AND CPP PROGRAM SAYING NOT DECLARED HAVE A DRIVER WILL PASTE AT BOTTOM MOVIES.CPP #include "movies.h" #include "Movie.h" Movies *Movies::createMovies(int max) { //dynamically create a new Movies structure Movies *myMovies = new Movies; myMovies->maxMovies = max; myMovies->numMovies = 0; //dynamically create the array that will hold the movies myMovies->moviesArray = new Movie *[max]; return myMovies; } void Movies::resizeMovieArray() { int max = maxMovies * 2; //increase size by 2 //make an array that is...

  • IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand...

    IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand the Application The assignment is to first create a class calledTripleString.TripleStringwill consist of threeinstance attribute strings as its basic data. It will also contain a few instance methods to support that data. Once defined, we will use it to instantiate TripleString objects that can be used in our main program. TripleString will contain three member strings as its main data: string1, string2, and string3....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT