当前位置: 首页 > news >正文

day7作业

编写一个如下场景: 有一个英雄Hero类,私有成员,攻击(Atx),防御(Defense),速度(Speed),生命值(Blood),以及所有的set get 方法 编写一个 武器 Weapon 类,拥有私有成员攻击力(Atx),以及set get 方法 编写一个 长剑 Sword 类,继承自武器类,拓展属性 生命值(Blood),以及set get 方法 编写一个 匕首Blade类,继承自武器类,拓展属性 速度(Speed),以及set get 方法 编写一个 斧头 Axe类,继承自武器类,拓展属性 防御力(Defense),以及set get 方法 武器Weapon类里面,要求有一个多态函数,叫做 equip 函数 英雄Hero类里面,要求有一个公开函数,equipWeapon(Weapon* w) 实现功能:英雄既可以装备长剑,也可以装备短剑,也可以装备斧头,但是要求装备不同的武器,英雄需要获得不同的属性加成

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <unistd.h>
#include <sstream>
#include <vector>
#include <memory>using namespace std;class Hero{
private:int Atx;int Defense;int Speed;int Blood;
public:Hero(int Atx=0,int Defense=0,int Speed=0,int Blood=0):Atx(Atx),Defense(Defense,Speed(Speed),Blood(Blood){}void setAtx(int atx) { Atx = atx; }int getAtx() const { return Atx; }void setDefense(int defense) { Defense = defense; }int getDefense() const { return Defense; }void setSpeed(int speed) { Speed = speed; }int getSpeed() const { return Speed; }void setBlood(int blood) { Blood = blood; }int getBlood() const { return Blood; }
};class Weapon{
private:int Atx;
public:		Weapon(int Atx=0):Atx(Atx){}virtual ~Weapon() {}virtual void equip(Hero* h) = 0;virtual void unequip(Hero* h) = 0;void setAtx(int atx) { Atx = atx; }int getAtx() const { return Atx; }};
class Sword:public Weapon{private:int Blood;public:Sword(int Blood=50):Defense(Defense){}void equip(Hero* h) {Weapon::equip(h);h->setBlood(h->getBlood() + bloodBonus);}void setBlood(int blood) {Blood = blood; }int getBlood() const { return blood; }
};
}class Blade:public Weapon{
private:int Speed;public:Sword(int Speed=50):Defense(Defense){}void equip(Hero* h) {Weapon::equip(h);h->setSpeed(h->getSpeed() + Speed;}void setSpeed(int speed) { Speed = speed; }int getSpeed() const { return speed; }
};}
class Axe:public Weapon{
private:int Defense;public:Axe(int Defense=50):Defense(Defense){}void equip(Hero* h) {Weapon::equip(h);h->setDefense(h->getDefense() + Defenss);}void setDefenseBonus(int defense) { Denfense = defense; }int getDefense() const { return Defense; }
};
}int main(int argc,const char** argv){Hero hero;Sword sword;Blade blade;Axe axe;
}

http://www.lryc.cn/news/543231.html

相关文章:

  • 图像处理之图像边缘检测算法
  • 第二十五 :搭建 pinia 环境
  • 学习Java数组操作:从基础到高级技巧详解
  • 算法题(79):两个数组的交集
  • TFChat:腾讯大模型知识引擎+飞书机器人实现AI智能助手
  • Linux红帽:RHCSA认证知识讲解(四)修改远程配置文件,取消root禁用,便于使用root身份远程
  • 验证码介绍及生成与验证(HTML + JavaScript实现)
  • 文心一言AI创意画
  • WebRTC解析
  • 升级Office软件后,Windows 系统右键里没有新建Word、Excel、PowerPoint文件的解决办法
  • 车载DoIP诊断框架 --- 连接 DoIP ECU/车辆的故障排除
  • 洛谷每日1题-------Day4__陶陶摘苹果
  • 萌新学 Python 之模块管理
  • 6.3 - UART串口数据发送之中断
  • Fisher信息矩阵(Fisher Information Matrix, FIM)与自然梯度下降:机器学习中的优化利器
  • Mysql基础-多表查询(详细版)
  • 港科大提出开放全曲音乐生成基础模型YuE:可将歌词转换成完整歌曲
  • Python学习第十七天之PyTorch保姆级安装
  • 有关与 WSL 2 的主要区别的信息,请访问 https://aka.ms/wsl2
  • 什么是 Java 中的线程安全?
  • 计算机视觉(opencv-python)入门之图像的读取,显示,与保存
  • QT:Graphics View的坐标系介绍
  • 530 Login fail. A secure connection is requiered(such as ssl)-java发送QQ邮箱(简单配置)
  • vs2015下使用openmp
  • Docker 搭建 Gitlab 服务器 (完整详细版)
  • 【万字长文】开源之播对话白鲸开源CEO郭炜--乐观主义的开源精神走得更远
  • 机试刷题_674. 最长连续递增序列【python】
  • ipe网络安全
  • QT:QPen、QBrush、与图形抗锯齿的关联
  • android keystore源码分析