Use object oriented design to create a movie class that contains private data for title, profits, a rating, and a review.
Next create a theater class composed of movie objects. The theater class private data should hold the name of the theater and an array of movie objects (movies shown at that theater). Create this array dynamically.
Create a driver program that a theater object and prints a list of the movies shown Your program should then prompt the user for the following:
1) print the name of the theater and all movies titles shown there.
2) find the rating of a particular movie: the user must enter in the name of the movie
3) print the review of a particular movie.
4) find the movie with the largest profit at a particular theater
I need help on the 4th requirment. (I know I am missing the array dynamically)
Also for the title in my 'Movie' class. I need it to be private, but I do, it wont work, so i made it public. any work around on that?
Sorry first time using this place.
Here's my code:
Error: "Expected primary-expression before 'movies' " (Line 131, inside main();
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
Welcome to the site! When posting code, please put code tags around it. Highlight the code and click the "<>" button to the left of the edit window. You might try this by editing your original post and adding code tags.
I think two things are tripping you up here. First is the private data. To use the private data, you will need to add public methods. For the Movie object, make the data private and add these methods:
1 2 3 4
string getTitle();
double getProfit();
int getRate();
string getReview();
For the Cinema class, I think you're getting tripped by the dynamic array. You'll have an easier time attacking this head on so here goes:
1. Create a private pointer to the array, a member to hold the number of items actually in it:
1 2 3
private:
Movie *movies;
size_t numMovies;
Set these in the constructor and destroy them in the destructor:
1 2 3 4 5 6 7 8 9 10
Cinema()
{
...
movies = new Movie[10];
numMovies = 0;
}
~Cinema()
{
delete[] movies;
}
Add a method to add a movie:
1 2 3
addMovie(Movie &m) {
movies[numMovies++] = m;
}
Change Cinema::print1() to print the movies in the array.
For items 2 and 3, create a Cinema() method that takes a movie title and returns a pointer to the movie (or nullptr if it isn't showing: Movie *findMovie(const string *title);
Once you've create this, numbers 2 and 3 are easy: find the movie from the title, and print the rating or review.
For number 4, find the most profitable movie with another method in class Cinema: Movie *findMostProfitable();
This will return nullptr if there are no movies in the cinema.