编写以下题目所需的代码:假设这个世界上有3大种族:野兽、人类和兽人。所有这些种族都继承于生物类。而且由于兽人可以看作是野兽与人类的结合体,所以兽人类应当同时继承于野兽类和人类。请在头文件命名为"Orcs.h"中手动实现生物类、野兽类、人类和兽人类。 上述四个类的结构如下代码片段所示。class Creature { public: Creature(const int& hands, const int& legs) {} ~Creature() {} int GetHands() const {} int GetLegs() const {} private: int _hands; int _legs; }; class Beast : public Creature { public: Beast(const int& hands, const int& legs, const string& name) {} ~Beast() {} string GetName() const {} private: string _name; }; class Human: public Creature { public: Human(const int& hands, const int& legs, const string& name) {} ~Human() {} string GetName() const {} private: string _name; }; class Orc: public Beast, public Human { public: Orc(const int& hands, const int& legs, const string& beast_name, const string& human_name) {} ~Orc() {} string GetBeastName() const {} string GetHumanName() const {} }; class Orc: public Beast, public Human { public: Orc(const int& hands, const int& legs, const string& beast_name, const string& human_name) {} ~Orc() {} string GetBeastName() const {} string GetHumanName() const {} };
时间: 2023-07-14 13:11:46 浏览: 121
// 生物类
class Creature {
public:
Creature(const int& hands, const int& legs) : _hands(hands), _legs(legs) {}
virtual ~Creature() {}
int GetHands() const { return _hands; }
int GetLegs() const { return _legs; }
private:
int _hands;
int _legs;
};
// 野兽类
class Beast : public Creature {
public:
Beast(const int& hands, const int& legs, const string& name) : Creature(hands, legs), _name(name) {}
virtual ~Beast() {}
string GetName() const { return _name; }
private:
string _name;
};
// 人类
class Human: public Creature {
public:
Human(const int& hands, const int& legs, const string& name) : Creature(hands, legs), _name(name) {}
virtual ~Human() {}
string GetName() const { return _name; }
private:
string _name;
};
// 兽人类
class Orc: public Beast, public Human {
public:
Orc(const int& hands, const int& legs, const string& beast_name, const string& human_name) :
Creature(hands, legs), Beast(hands, legs, beast_name), Human(hands, legs, human_name) {}
virtual ~Orc() {}
string GetBeastName() const { return Beast::GetName(); }
string GetHumanName() const { return Human::GetName(); }
};
阅读全文