作业
代码
#include <iostream>
using namespace std;
class Animal
{
private:
string narrator;
public:
Animal(){}
Animal(string narrator):narrator(narrator)
{}
virtual void perform()
{
cout << "讲解员解说中" << endl;
}
};
class Lion:public Animal
{
private:
string animal;
public:
Lion(){}
Lion(string narrator,string animal):Animal(narrator),animal(animal)
{}
void perform()
{
cout << "狮子表演中" << endl;
}
};
class Elephant:public Animal
{
private:
string animal1;
public:
Elephant(){}
Elephant(string narrator,string animal1):Animal(narrator),animal1(animal1)
{}
void perform()
{
cout << "大象表演中" << endl;
}
};
int main()
{
cout << "==================" << endl;
Elephant E("耿2","大象");
E.perform();
Lion L("耿1","狮子");
L.perform();
Animal A1("耿同灏");
A1.perform();
cout << "==================" << endl;
Animal *p=&L;
p->perform();
cout << "==================" << endl;
Animal *q=&E;
q->perform();
return 0;
}