如何获取具有共同属性的对象列表?

How to get a list of objects with common attributes?

给定一个 class Movie (id, title, ranking, release date, character number, ticket price, comment etc.)enum type: ACTION, COMEDY, DRAMA, FANTASY etc. 和一个 class Cinema (name, location)。我需要编写一个函数 calculateProfit ( Movie*, day) 来计算电影院在某一天的利润。我还需要编写一种根据某些参数选择电影并根据发行日期对电影进行排序的方法。我已经思考了几天这个问题,但似乎我无法编写正确的代码。

为了能够根据参数选择电影,我需要获取具有相同特定属性的电影 class 的所有对象的列表。我该怎么做?

这是我的 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;

};

给定一个std::vector<std::shared_ptr<Movie>>,你可以按标题查找如下:

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;
}