6月11号作业

思维导图

cpp 复制代码
#include <iostream>
using namespace std;
class Animal
{
private:
    string name;
public:
    Animal(){}
    Animal(string name):name(name)
    {
        //cout << "Animal;有参" << endl;
    }
    virtual void perform()
      {
          cout << "讲解员的名字是: " << name << endl;
      }
};
class Sun:public Animal
{
private:
    string lion;//狮子
    string Elephant;//大象
    string monkey;//猴子
public:
    Sun()
    {

    }
    Sun(string lion,string Elephant,string monkey,string name):Animal(name),lion(lion),Elephant(Elephant),monkey(monkey)
    {
       // cout << ""
    }
    void perform()
    {
        Animal::perform();
        cout << "狮子的名字叫: " << lion << endl;
        cout << "大象的名字叫: " << Elephant << endl;
        cout << "猴子的名字叫: " << monkey << endl;
    }
};
class Conservator:public Animal
{
private:
    string name;
    //int age;
    //double height;
public:
    Conservator()
    {

    }
    Conservator(string name,string n):Animal(n),name(name)
    {

    }
    void perform()
    {
        cout << "狮子的体重为200公斤,体长1,6米,是肉食性动物,比较凶残" << endl;
        cout << "大象的体重为1吨,体长2米,是饲草性动物,比较温顺" << endl;
        cout << "猴子的体重为30,身高1米,是杂食性动物" << endl;
    }
};
int main()
{
    Sun a1("小黄","大壮","小跳","刘晓颖");
    Animal *p=&a1;
    p->perform();
    Conservator a2("","");
    p=&a2;
    p->perform();
    return 0;
}
相关推荐
luanma1509801 小时前
PHP vs C++:编程语言终极对决
开发语言·c++·php
csdn_aspnet1 小时前
C/C++ 两个凸多边形之间的切线(Tangents between two Convex Polygons)
c语言·c++·算法
yangtuoni3 小时前
vscode调试C++程序
c++·ide·vscode
m0_587958954 小时前
C++中的命令模式变体
开发语言·c++·算法
2501_924952694 小时前
代码生成器优化策略
开发语言·c++·算法
xushichao19895 小时前
C++动态链接库开发
开发语言·c++·算法
fengenrong5 小时前
20260324
c++·算法
qq_416018725 小时前
设计模式在C++中的实现
开发语言·c++·算法
2301_776508725 小时前
C++与机器学习框架
开发语言·c++·算法
ALex_zry6 小时前
现代C++设计模式实战:从AIDC项目看工业级代码架构
c++·设计模式·架构