Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here's the stuff from my Lab 2. Please put comments. C++. #include #include #include using namespace std; // class definition; class Movie { private: //

image text in transcribed

Here's the stuff from my Lab 2. Please put comments. C++.

#include #include #include

using namespace std;

// class definition; class Movie { private: // private variables only accesible within the class // only declaration should be done here all initialization should be done in constructors string title;// string to store the title of the movie string genre;// string to store the genre of the movie int runtime;// integer to store the running time of the movie (in minutes) double review;// double to store an average review score public: // constructors Movie();// default constructor Movie(string title);// constrcutor with parameter for movie title Movie(string title, string genre, int runtime, double review);// constructor with all parameters

// public functions that can be called upon class instance(out side of class) // Accessors (These can be done inline) string getTitle() { return title; };// returns title of the movie string getGenre() { return genre; };// returns genre of the movie int getRuntime() { return runtime; };// returns running time of the movie double getReview() { return review; };// returns average review score of the movie

// Mutators void setTitle(string title) { this->title = title; };// sets given title to the movie void setGenre(string genre) { this->genre = genre; };// sets given genre to the movie void setRuntime(int runtime) { this->runtime = runtime; };// sets given integer as running time of the movie // for review only declaration should be done here code for implimentation // should be out side of the class definition void setReview(double review);// sets given double value as average review score of the movie void display();// print out all of the information pertaining to the movie };

// code for implementation of class constructors and mutator for review Movie::Movie() { // initialize the strings for title and genre to empty strings (""), // and the integer and double for runtime and rating to 0. this->title = ""; this->genre = ""; this->runtime = 0; this->review = 0.0; }

Movie::Movie(string title) { // initialize the strings for title with given title // and genre to empty strings (""), and the integer and double for runtime and rating to 0. this->title = title; this->genre = ""; this->runtime = 0; this->review = 0.0; }

Movie::Movie(string title, string genre, int runtime, double review) { // initialize all parameters this->title = title; this->genre = genre; this->runtime = runtime; // use the mutator, to make sure that restrictions on review score are preserved this->setReview(review); }

void Movie::setReview(double review) { // The mutator for review score should make sure that the review is set to // a value between 0.0 and 100.0 // If the score is outside that range, display an error message and do not change the value. // Else, update the review score to the new intended value if (review 100.0) { cout review = review; } }

void Movie::display() { cout

// main function to run the program // program execution start from main function int main() { // declare three objects of type Movie Movie movie1;// use the default constructor // prompt the user to enter the title, genre, running time, and score, and use the mutators to set those values cout > genre;// get user input // set movie genre movie1.setGenre(genre); cout > runtime;// get user input // set movie running time movie1.setRuntime(runtime); cout > review;// get user input // set movie review score movie1.setReview(review); // call the objects display() function to print out the information cout

// prompt the user for the other three pieces of information, // then call the display function to print out that movies information Movie movie2("The Dark Knight"); cout > genre;// get user input // set movie genre movie2.setGenre(genre); cout > runtime;// get user input // set movie running time movie2.setRuntime(runtime); cout > review;// get user input // set movie review score movie2.setReview(review); cout

Movie movie3("Inception", "Sci-fi", 148, 88.0); // call the display function to print it out, and see the results cout

system("pause"); return 0; }// end of program

The Movie class created for Lab 2 offers a convenient place to start in this one. We're going to want to start thinking about organizing our code a bit more though, so start by separating the Movie class definition into a separate header file. Once the Movie class is created and moved into its own file(s), I recommend testing it thoroughly to make sure all of the parts are working before moving on. You will need to remember to include the header file in any other file where you intend to make reference to the class. After the Movie class is created, you will create a second new class, Movie Database, this one with its own header AND source files (Movie Database.h and Movie Database.cpp). The Movie Database class will have (at least) the following private attributes: An array, Movies, capable of storing 100 Movie objects. This is inefficient, and limited, but we'll fix it later in the semester. An integer, movieCount, that counts how many movies have been added into our database. o While 100 is the MAX size of the array, the ACTUAL size of the filled part of the array is important to keep track of, and this variable serves that purpose. Besides any accessors and mutators, your Movie Database should include methods designed to accomplish the following tasks: Add a movie to the database o This function will need to allow the user to enter all the required information to set the values of a movie in the array. You will need to know how many movies are already in the array to determine what index of the array you should edit. For instance, if there are 10 movies already, then the new movie would go to the 11th position, or Movies[10]. Display the current number of movies in the database. Print out the titles of all of the movies in the database. In the main, you should declare an instance of your database class, and implement a menu driven program that allows the user to choose to add movies, display the number of movies, or list the titles (by calling the associated methods). Test your program thoroughly, and make sure that it works reliably. The Movie class created for Lab 2 offers a convenient place to start in this one. We're going to want to start thinking about organizing our code a bit more though, so start by separating the Movie class definition into a separate header file. Once the Movie class is created and moved into its own file(s), I recommend testing it thoroughly to make sure all of the parts are working before moving on. You will need to remember to include the header file in any other file where you intend to make reference to the class. After the Movie class is created, you will create a second new class, Movie Database, this one with its own header AND source files (Movie Database.h and Movie Database.cpp). The Movie Database class will have (at least) the following private attributes: An array, Movies, capable of storing 100 Movie objects. This is inefficient, and limited, but we'll fix it later in the semester. An integer, movieCount, that counts how many movies have been added into our database. o While 100 is the MAX size of the array, the ACTUAL size of the filled part of the array is important to keep track of, and this variable serves that purpose. Besides any accessors and mutators, your Movie Database should include methods designed to accomplish the following tasks: Add a movie to the database o This function will need to allow the user to enter all the required information to set the values of a movie in the array. You will need to know how many movies are already in the array to determine what index of the array you should edit. For instance, if there are 10 movies already, then the new movie would go to the 11th position, or Movies[10]. Display the current number of movies in the database. Print out the titles of all of the movies in the database. In the main, you should declare an instance of your database class, and implement a menu driven program that allows the user to choose to add movies, display the number of movies, or list the titles (by calling the associated methods). Test your program thoroughly, and make sure that it works reliably

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions