struct Problem;
struct Solution;
class Skill {
public:
Skill() = default;
Solution Solve(Problem problem);
}
// Implement class to represent an engineer. Each engineer could have multiple skills.
// Implement class to represent a team. Each team could have multiple engineers.
// A team class needs to provide a Solve function: given a problem, whether it could be solved
// and what is the solution. A problem could be solved if there is an engineer in the team that
// could provide a solution to it.
// My solution:
class Engineer{
public:
Engineer() = default;
void setSkill(const Skill& skill);
Solution Solve(Problem problem) const;
private:
std::set<Skill> skills;
};
Solution Engineer::Slove(Problem problem) const
{
if(skills.empty())
return Solution::NOSOLUTION;
for(auto i : skills{
Solution solution = i.solve(problem);
if (solution != Solution::NOSOLUTION)
return solution;
}
return Solution::NOSOLUTION;
}
Solution Engineer::setSkill(const Skill& skill){
skills.insert(skill);
}
class Team{
public:
Team() = default;
void addMember(const Engineer&);
SolutionSolve(Problem problem) const;
private:
std::set<Engineer> engineers;
}
void Team::addMember(const Engineer& engeineer){
engineers.insert(engeineer);
}
Solution Team::Slove(Problem problem) const
{
if(engineers.empty())
return Solution::NOSOLUTION;
for(auto i : engineers{
Solution solution = i.solve(problem);
if (solution != Solution::NOSOLUTION)
return solution;
}
return Solution::NOSOLUTION;
}