c++已知角色亚瑟arthur的初始血量为3622,物攻为164,孙悟空monkey_king的初始血量为3293,物攻为167,蓝量为430。 请在main函数中创建这两个角色并初始化,输出他们的属性。
时间: 2024-03-01 12:52:04 浏览: 20
好的,以下是代码实现:
```c++
#include <iostream>
#include <string>
using namespace std;
class Role {
public:
string name; // 角色名称
int hp; // 血量
int attack; // 物理攻击力
int mana; // 蓝量
Role(string n, int h, int a, int m) {
name = n;
hp = h;
attack = a;
mana = m;
}
};
int main() {
Role arthur("Arthur", 3622, 164, 0);
Role monkey_king("Monkey King", 3293, 167, 430);
cout << "Arthur: HP " << arthur.hp << ", Attack " << arthur.attack << endl;
cout << "Monkey King: HP " << monkey_king.hp << ", Attack " << monkey_king.attack << ", Mana " << monkey_king.mana << endl;
return 0;
}
```
输出结果为:
```
Arthur: HP 3622, Attack 164
Monkey King: HP 3293, Attack 167, Mana 430
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![crx](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)