Help on Programmning

closed account (jihpDjzh)
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;

class Movie{

public:
string title;
double profit;
int rate;
string review;
public:
Movie(string t, double p, int r, string rev)
{
title = t;
profit = p;
rate = r;
review = rev;
}
Movie()
{
title = "";
profit = 0;
rate = 0;
review = "";

}
void print()
{
cout << "Movie: " << title << endl;
cout << "Profit: " << profit << endl;
cout << "Rate: " << rate << endl;
cout << "Review: " << review << endl;

}


};
class Cinema{
private:
string name1;
string movie1;
string movie2;
int name;
public:
Cinema(string n, string m1, string m2)
{
name1 = n;
movie1 = m1;
movie2 = m2;
}

Cinema()
{
name1= "";
movie1 = "";
movie2 = "";
}
void print1()
{

cout << name1 << ": " << movie1 << ", " << movie2 << endl;
cout << endl;

}


};
//void FindProfit(Movie movies[]);
void FindProfit(Movie test[])
{
int profit;
cout << endl;
profit = test[0].profit;

for (int x = 1; x < 6; x++)
{
if (test[x].profit > profit)
{
cout << test[x].title << " has a profit of : " << test[x].profit << endl;
}
}
}
int main()
{
unsigned found;
Cinema names[3] = {Cinema("Cinema1", "Batman", "Smurfs"),
Cinema("Cinema2", "Flash", "Fantastic 4"),
Cinema("Cinema3", "21 Jump Street", "Jurassic Park")};


Movie movies[6] = {Movie("Batman", 1500, 8, "Great movie."),
Movie("Smurfs", 1200, 7, "Extremely Cute."),
Movie("Flash", 1100, 8, "Close to the Original Comics."),
Movie("Fantastic 4", 1350, 7, "Very creative."),
Movie("21 Jump Street", 1800, 9, "Extremely funny!"),
Movie("Jurassic Park", 2100, 9,"Greatest of its time!")};

cout << "Theater: " << " " << "Movies: " << endl;
cout << endl;
for (int i = 0; i < 3; i++)
{
names[i].print1();
}
cout << endl;

string choice;
cout << "What movie do you want to see?" << endl;
getline(cin, choice);
cout << endl;

for (int x = 0; x < 6; x++)
{
found = movies[x].title.find(choice);
if (found != string::npos)
{
movies[x].print();
}

}
cout << endl;
cout << "Movie with the greatest profit : " << endl;
FindProfit(Movie movies[6]);
return 0;
}
Last edited on
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.


closed account (jihpDjzh)
Thank you very much!
Topic archived. No new replies allowed.