蒙文门户网站建设深圳个人网站制作
蒙文门户网站建设,深圳个人网站制作,免费建立自己的网站代理,gcms是什么意思#include iostream
//不同种类的动物#xff0c;如狮子、大象、猴子等。现在#xff0c;动物园里有一位讲解员#xff0c;他会为每种动物表演做简单的介
//绍。定义一个基类 Animal#xff0c;其中有一个虛函数perform#xff08;)#xff0c;用于在子类中实现不…#include iostream
//不同种类的动物如狮子、大象、猴子等。现在动物园里有一位讲解员他会为每种动物表演做简单的介
//绍。定义一个基类 Animal其中有一个虛函数perform)用于在子类中实现不同的表演行为
using namespace std;
class Animal
{
private:string name;int weight;string color;
public:Animal(){}Animal(string name,int w,string c):name(name),weight(w),color(c){}virtual void perform(){cout 动物讲解开始...... endl ;}void show(){cout name weight color endl;}void over(){cout 动物讲解结束...... endl ;}
};class Lion :public Animal
{
private:string sound;int age;
public:Lion(){}Lion(string sound,int age,string name,int weight,string color):Animal(name,weight,color),sound(sound),age(age){}void perform(){cout 狮子喷火....... endl;}void show(){cout sound age ;}
};class Elephant :public Animal
{
private:string nose;int high;
public:Elephant(){}Elephant(string nose,int h,string name,int weight, string color):Animal(name,weight,color),nose(nose),high(h){}void perform(){cout 大象跳圈圈....... endl;}void show(){cout nose high ;}
};class Monkey :public Animal
{
private:string breed;int birth;
public:Monkey(){}Monkey(string breed,int birth,string name,int weight, string color):Animal(name,weight,color),breed(breed),birth(birth){}void perform(){cout 猴子蹦极....... endl;}void show(){cout breed birth ;}
};int main()
{ Animal f;f.perform();Animal *p;Lion A(怒吼,5,狮子,300,棕色);Elephant B(大长鼻子,20,大象,500,灰色);Monkey C(金丝猴,2023,猴子,36,金色);cout ________________________ endl;cout endl;A.show();A.Animal::show();pA;p-perform();cout endl;cout endl;B.show();B.Animal::show();pB;p-perform();cout endl;cout endl;C.show();C.Animal::show();pC;p-perform();cout endl;cout ________________________ endl;f.over();
}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/89766.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!