#include
#include
#include
using namespace std;
class person {//新建人物类
public:
person();
~person();
void setname(string inputname){
name=inputname;
}
string getname(){
return name;
}
void setbmi(double bmi){
person::bmi=bmi;
}
double getbmi(){
return bmi;
}
private:
string name;//姓名
double bmi;//BMI
};
person::person(){
}
int main(){
person* p1=new person();//人物对象
string text1 = "Type your first name (with no space):";
string text2 = "Type metric for metric system, type standard for standard system:";
string input;
string weight,height;
double bmi;
int choice;
bmi=0.0;
cout<
cin>>input;
p1->setname(input);
cout<
cin>>input;
if(input=="standard")//判断属于那种system
choice=0;
else if (input=="metric")
choice=1;
else if (input=="unknow")
choice=2;
switch(choice){
case 0:
cout
bmi=((atof((weight.c_str())))/((atof(height.c_str()))*(atof(height.c_str()))))*703;//计算bmi
p1->setbmi(bmi);
break;
case 1:
cout
bmi=(atof(weight.c_str()))/((atof(height.c_str()))*(atof(height.c_str())));
p1->setbmi(bmi);
break;
case 2:
cout
bmi=((atof((weight.c_str())))/((atof(height.c_str()))*(atof(height.c_str()))))*703;
p1->setbmi(bmi);
break;
}
cout<
getname() cout< getname() cout<} else if(p1->getbmi()<25.0){ cout<} else if(p1->getbmi()<30.0){ cout<} else { cout<} }基本上行了,你试试,至于system和category,system是关键字,不过用不上,category可以弄成一个变量,我这里没用,也没必要.