/*
*Copyright (c) 2016,烟台大学计算机学院
*All rights reserved.
*文件名称:text.cpp
*作者:陈腾
*完成日期:2016年6月09日
*版本号:v1.0
*/
class attack
{
public:
attack(double t):
t(t){}
void show()
{
if(t<10)
{
cout<<"饮血,攻击力双倍:";
cout<<"攻击力为"<<2*t;
}
else if(t<100&&t>=10)
{
cout<<"饮魔,攻击力+10:";
cout<<"攻击力为"<<(10+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;
}
*Copyright (c) 2016,烟台大学计算机学院
*All rights reserved.
*文件名称:text.cpp
*作者:陈腾
*完成日期:2016年6月09日
*版本号:v1.0
*/
问题描述:带武器的游戏角色
#include <iostream>
using namespace std;class attack
{
public:
attack(double t):
t(t){}
void show()
{
if(t<10)
{
cout<<"饮血,攻击力双倍:";
cout<<"攻击力为"<<2*t;
}
else if(t<100&&t>=10)
{
cout<<"饮魔,攻击力+10:";
cout<<"攻击力为"<<(10+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;
}