题目:
代码:
#include <iostream>using namespace std;class Animals
{
private:string name;
public:Animals(){}Animals(string name):name(name){}virtual void perform() = 0;void show(){cout << "这个动物是" << name << endl;}
};class Kind:public Animals
{
private:string habit;
public:Kind(){}Kind(string name,string habit):Animals(name),habit(habit){}void perform(){Animals::show();cout << "它是" << habit << endl;}
};int main()
{Animals *p = nullptr;Kind lion("狮子","食肉目猫科豹属的大型猛兽。成年雄狮的体重要比母狮重,外形上也更大,并且雄狮具有很长的鬣毛。被称为百兽之王");p = &lion;lion.perform();Animals *q = nullptr;Kind panda("熊猫","杂食性动物,大熊猫已在地球上生存了至少800万年,被誉为“活化石”和“中国国宝”,世界自然基金会的形象大使,是世界生物多样性保护的旗舰物种。");q = &panda;panda.perform();return 0;
}
效果图:
思维导图: