Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please Help, I am not understanding the assignment at all. The Movie class created for Lab 2 offers a convenient place to start in this

Please Help, I am not understanding the assignment at all.

The Movie class created for Lab 2 offers a convenient place to start in this one. Were 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, MovieDatabase, this one with its own header AND source files (MovieDatabase.h and MovieDatabase.cpp). The MovieDatabase class will have (at least) the following private attributes:

  • An array, Movies, capable of storing 100 Movie objects.
    • This is inefficient, and limited, but well fix it later in the semester.
  • An integer, movieCount, that counts how many movies have been added into our database.
    • 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 MovieDatabase should include methods designed to accomplish the following tasks:

  • Add a movie to the database
    • 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.

This is what I've done so far (admittedly not much). Please add detailed comments.

Movie.h

#pragma once #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 < 0.0 || review > 100.0) { cout << "Invalid Review Score!" << endl; } else { this->review = review; } }

void Movie::display() { cout << "Title: " << title << endl; cout << "Genre: " << genre << endl; cout << "Runtime: " << runtime << " min" << endl; cout << "Review: " << review << endl << endl; }

MovieDatabase.h

#pragma once #include #include #include

MovieDatabase.cpp

#include #include #include

using namespace std;

int main() { int MoviesVals[100]; }

(This is from the previous lab) Not sure if it is relevant to the current one tho.

Lab3.cpp

#include #include #include #include "Movie.h"

using namespace std;

// 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 << " Enter Movie title: "; string title; getline(cin, title);// get user input // set movie title movie1.setTitle(title); cout << " Enter Movie genre: "; string genre; cin >> genre;// get user input // set movie genre movie1.setGenre(genre); cout << " Enter Movie running time: "; int runtime; cin >> runtime;// get user input // set movie running time movie1.setRuntime(runtime); cout << " Enter Movie review score: "; double review; cin >> review;// get user input // set movie review score movie1.setReview(review); // call the objects display() function to print out the information cout << endl;// print empty line movie1.display();

// 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 << " Enter Movie genre: "; cin >> genre;// get user input // set movie genre movie2.setGenre(genre); cout << " Enter Movie running time: "; cin >> runtime;// get user input // set movie running time movie2.setRuntime(runtime); cout << " Enter Movie review score: "; cin >> review;// get user input // set movie review score movie2.setReview(review); cout << endl;// print empty line movie2.display();

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

return 0; }// end of program

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

More Books

Students also viewed these Databases questions

Question

Solve each equation. 0= (sx) (01 + x)

Answered: 1 week ago

Question

Compose the six common types of social business messages.

Answered: 1 week ago

Question

Describe positive and neutral messages.

Answered: 1 week ago