day46 0102

2024-01-03 01:21:09

作业1
?

#include <iostream>

using namespace std;

int monster = 10000;

class Hero
{
    string name;
    int hp;
    int attck;
public:
    Hero(string name,int hp,int attack):name(name),hp(hp),attck(attack){}
    virtual void Atk()
    {
        monster -= 0;
    }
    int get_attack();
};
int Hero::get_attack()
{
    return attck;
}

class Master:public Hero
{
    int ap_atk = 50;
public:
    using Hero::Hero;
    void Atk()
    {
        monster -= (get_attack()+ap_atk);
        cout << monster << endl;
    }
};

class Shooter:public Hero
{
    int ap_atk = 100;
public:
    using Hero::Hero;
    void Atk()
    {
        monster -= (get_attack()+ap_atk);
        cout << monster << endl;
    }
};

int main()
{
    Master hero1("zhangsan",100,100);
    Shooter hero2("lisi",100,100);

    hero1.Atk();
    hero2.Atk();
    return 0;
}

思维导图

?

?

?

文章来源:https://blog.csdn.net/weixin_51788918/article/details/135348125
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。