【发布时间】:2020-07-15 14:57:17
【问题描述】:
这是我的任务:
我已经完成了一半的代码,但我很挣扎,因为我是 OOP 的初学者,我不确定如何找到 main_actor 是安吉丽娜朱莉的电影。
for (int i = 0; i < n; ++i)
{
string name;
int year;
string prod;
string actor;
cout << "\nenter the film name " ;
cin >> name;
cout << "\nenter the production year ";
cin >> year;
cout << "\nenter the producer name ";
cin >> prod;
cout << "\nenter the actor name ";
cin >> actor;
obs[i].SetName(name);
obs[i].SetYearP(year);
obs[i].SetProducer(prod);
obs[i].SetMaina(actor);
if (actor == "Angelina Jolie")
{
cout << "The movie who has main actor Angelina Jolie is" << name << endl;
} // Тhis is my attempt.
}
}
【问题讨论】:
-
所以要找到演员是安吉丽娜·朱莉的电影,你需要做的第一件事就是编写第二个循环。首先你得到了所有的信息,只有当你得到了这些信息时,你才会尝试用它做点什么。所以删除你已有的
if (actor == "Angelina Jolie")语句并开始一个新的循环。 -
要获取主要演员和电影名称,您应该使用您编写的
GetName和GetMaina的 getter 函数,这就是它们的用途。 -
您是否与您的教授或助教谈过并解释说您在其中一些概念上遇到了问题?他们付钱教你。这确实是他们的工作。
标签: c++ function oop constructor