// 生命类
class Life
{
protected:
int age; // 年龄
int year; // 寿命
public:
Life(int a, int y):age(a), year(y){}
public:
int getAge() { return age; }
int getYear() { return year; }
void show() { std::cout << "age:"<<age <<" year:"<< year; }
};
// 物体类
class Thing
{
protected:
int weight; // 重量
int size; // 尺寸
public:
Thing(int w, int s) :weight(w), size(s){}
public:
int getWeight() { return weight; }
int getSize() { return size; }
void show() { std::cout << "weight:" << weight << " size:" << size; }
};
// 区域类
class Area
{
protected:
std::string pos; // 地点名字
std::string owner; // 地主名字
public:
Area(std::string p, std::string o) :pos(p), owner(o){}
public:
std::string getPos() { return pos; }
std::string getOwner() { return owner; }
void show() { std::cout << "pos:" << pos << " owner:" << owner; }
};
// 动物类
class Animal : public Life, public Thing
{
protected:
int leg; // 腿的数量
int wing; // 翅膀数量
std::string kind; // 种类名字
public:
Animal(int age, int year, int weight, int size, int le, int wg, std::string kd)
:Life(age, year), Thing(weight, size), leg(le), wing(wg), kind(kd){}
public:
int getLeg() { return leg; }
int getWing() { return wing; }
std::string getKind() { return kind; }
void show()
{
Life::show(); std::cout << endl;
Thing::show(); std::cout << endl;
std::cout << "age:" << weight << " year:" << size << " year:" << size;
}
};
// 宠物类
class Pet : public Animal, public Area
{
protected:
int love; // 亲密度
std::string nickname; // 昵称
public:
Pet(int l, std::string n, int age, int year)
: love(l), nickname(n)
, Animal(age, year, 8, 20, 4, 0, "猫猫")
, Area("家庭","张三"){}
public:
int getlove() { return love; }
std::string getNickname() { return owner; }
void show()
{
Animal::show(); std::cout << endl;
Area::show(); std::cout << endl;
std::cout << "love:" << love << " nickname:" << nickname;
}
};