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;
}
相关推荐
clint4563 天前
C++进阶(1)——前景提要
c++
夜悊3 天前
C++代码示例:进制数简单生成工具
c++
郝学胜_神的一滴3 天前
CMake 021: IF 条件判据详诠
c++·cmake
_wyt0014 天前
洛谷 B3930 [GESP202312 五级] 烹饪问题 题解
c++·gesp
玖玥拾4 天前
C/C++ 数据结构(七)栈、容器适配器
c语言·数据结构·c++··容器适配器
один but you4 天前
constexpr函数
c++
凡人叶枫4 天前
Effective C++ 条款41:了解隐式接口和编译期多态
java·开发语言·c++·effective c++
凡人叶枫4 天前
Effective C++ 条款42:了解 typename 的双重意义
java·linux·服务器·c++
小胖xiaopangss4 天前
BRpc使用
c++·rpc
-森屿安年-4 天前
63. 不同路径 II
c++·算法·动态规划