作业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;
}
思维导图
?
?
?