-1

Given a class Movie (id, title, ranking, release date, character number, ticket price, comment etc.), enum type: ACTION, COMEDY, DRAMA, FANTASY etc. and a class Cinema (name, location). I need to write a function calculateProfit ( Movie*, day) that would calculate cinema's profit based on some particular day. Also I need to write a method of choosing a movie based on some parameters and sort the movies based on release date. I've been thinking over this problem for a few days already, but it seems like I just can't write the proper code.

In order to be able to choose a movie based on parameters, I need to get a list of all objects of a Movie class that have the same particular attributes. How can I do this?

Here is the brief template for my classes:

using namespace std;

class Movie{
public:
    int ID;
    string Title;
    int Ranking;
    string ReleaseDate;
    int CharacterNumber;
    int TicketPrice;
    string Comment;
    //SortingByDate
    enum type{
        ACTION, COMEDY, DRAMA, FANTASY
    } Type;
    Movie(int, string, int, string, int, int, string, type);
    Movie();
};
Movie::Movie(int ID, string Title,int Ranking,string ReleaseDate,int CharacterNumber, int TicketPrice,string Comment, type Type){
    this->ID=ID;
    this->Title=Title;
    this->Ranking=Ranking;
    this->ReleaseDate=ReleaseDate;
    this->CharacterNumber=CharacterNumber;
    this->TicketPrice=TicketPrice;
    this->Comment=Comment;
    this->Type=Type;  
class Cinema{
private:
    int calculateProfit();
public:
    //Vector with objects of Movie class
    string name;
    string location;

};
Sgg8
  • 135
  • 2
  • 7
  • *"`//Vector with objects of Movie class`"*. `std::vector movies;` seems missing. – Jarod42 Oct 11 '21 at 13:50
  • Sounds like a great question for your class's professor, your class's teacher's assistant, or collaboration with your classmates. – Eljay Oct 11 '21 at 13:51
  • related/dupe: https://stackoverflow.com/questions/15517991/search-a-vector-of-objects-by-object-attribute – NathanOliver Oct 11 '21 at 13:54
  • 1
    Could you at least do the effort to give us an example query? This is the third question you've asked so far today that has zero input from you beyond a generic problem statement. Does your teacher expect you to filter on one attribute? Five? Any attribute? What kind of filtering? Equality or string matching? What are you expected to do with the result? – Botje Oct 11 '21 at 14:01
  • I still dont get the thing about calculating the profit. `Movie` does not contain enough information to calculate the profit for a given day. – 463035818_is_not_an_ai Oct 11 '21 at 14:03
  • @463035818_is_not_a_number i asked in an improper way. A few questions at once. Than I asked the separately, so that I increase my chances to get some sort of response – Sgg8 Oct 11 '21 at 14:17

1 Answers1

0

Given a std::vector<std::shared_ptr<Movie>>, you can find by title as follows:

using MovieCollection = std::vector<std::shared_ptr<Movie>>;
MovieCollection find_by_title(const MovieCollection& collection, const std::string& fragment) {
  MovieCollection ret;
  for (auto movie: collection) {
    if (movie->title.find(fragment) != std::string::npos) {
      ret.push_back(movie);
    }
  }
  return ret;
}
Botje
  • 26,269
  • 3
  • 31
  • 41