武器类属性

来源:互联网 发布:淘宝买资源你懂的 编辑:程序博客网 时间:2024/04/29 17:47

/*
*Copyright (c) 2015,烟台大学计算机学院
*All rights reserved.
*文件名称:text.cpp
*作者:汤善晔
*完成日期:2016年6月6日
*版本号:v1.0
*问题描述:赋予武器属性
*/

#include <iostream>

using namespace std;

class attack

{

public:

    attack(double t):

        t(t){}

    void   show()

    {

        if(t<10)

        {

            cout<<"饮血,攻击力三倍:";

            cout<<"攻击力为"<<3*t;

        }

 

        else if(t<100&&t>=10)

        {

            cout<<"暴走,攻击力+20:";

            cout<<"攻击力为"<<(20+t);

        }

 

        else

        {

            cout<<"攻击力加1:";

            cout<<"攻击力为"<<(1+t);

        }

 

    }

private:

    double t;

 

};

class sword

{

public:

    sword(string name,double length,double width,attack a):

        name(name),length(length),width(width),a(a){}

    void putsword()

    {

        cout<<"剑名:"<<name<<endl;

        cout<<"剑长"<<length<<endl;

        cout<<"剑宽"<<width<<endl;

        a.show();

    }

private:

    string name;

    double length;

    double width;

    attack a;

 

};

int main()

{

    sword s("巴鲁姆克之剑",10,4,13);

    s.putsword();

    return 0;

}

很喜欢这种自己创作的过程

0 0
原创粉丝点击