C++,输入体重,身高,算bmi
来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/29 08:35:14
C++,输入体重,身高,算bmi
1.Ask for the user for his first name.输入你的姓名
\x09\x09\x09\x09
\x09\x09\x09\x09
\x09\x09\x09\x09\x09
2.Ask the user whether he wants to use metric or standard system.选择哪种方式来计算
\x09\x09\x09\x09
\x09\x09\x09\x09
\x09\x09\x09\x09\x09
3.Based on the choice of the system,prompt to ask weight and height.Use the answer
\x09\x09\x09\x09\x09
and the appropriate formula to calculate the user’s bmi.根据选择的方式输入体重和身高(磅和英尺,或千克和米)
\x09\x09\x09
\x09\x09\x09\x09
\x09\x09\x09\x09\x09
4.Prints out to the user (addressed with his name) what his BMI is.输出,用户的姓名和bmi的值
\x09\x09\x09\x09
\x09\x09\x09\x09
\x09\x09\x09\x09\x09
5.Prints out which category of weight he belongs to depending on his BMI.输出,用户的姓名,和更具bmi的值用户的体重属于哪一类的.
BMI = weight (kg) /( (height (m))(height(m))
BMI = weight (lb) / ((height (in)(height(in))*703
\x09\x09\x09
Underweight if BMI < 18.5
Normal if 18.5 ≤ BMI < 25.0
\x09\x09\x09
Overweight if 25.0 ≤ BMI < 30.0
Obese if 30.0 ≤ BMI
\x09\x09
Here are two sample output
\x09\x09\x09
v:\cmpsc101
Type your first name (with no space):
Michael
Type metric for metric system,type standard for standard system:
standard
Type in your weight in pound and your height in inch:
180
70.5
Michael,your BMI is 25.4595
Michael,you are considered to be Overweight.
\x09\x09\x09
v:\cmpsc101
Type your first name (with no space):
John
Type metric for metric system,type standard for standard system:
metric
Type in your weight in kilogram and your height in meter:
25
1
John,your BMI is 25
John,you are considered to be Overweight.
\x09\x09\x09
v:\cmpsc101
Type your first name (with no space):
Dora
Type metric for metric system,type standard for standard system:
unknown
Type in your weight in pound and your height in inch:
100
65.2
Dora,your BMI is 16.5371
Dora,you are considered to be Underweight.
谁知道这个c++的code要怎么写,code中需要用到system和category.
1.Ask for the user for his first name.输入你的姓名
\x09\x09\x09\x09
\x09\x09\x09\x09
\x09\x09\x09\x09\x09
2.Ask the user whether he wants to use metric or standard system.选择哪种方式来计算
\x09\x09\x09\x09
\x09\x09\x09\x09
\x09\x09\x09\x09\x09
3.Based on the choice of the system,prompt to ask weight and height.Use the answer
\x09\x09\x09\x09\x09
and the appropriate formula to calculate the user’s bmi.根据选择的方式输入体重和身高(磅和英尺,或千克和米)
\x09\x09\x09
\x09\x09\x09\x09
\x09\x09\x09\x09\x09
4.Prints out to the user (addressed with his name) what his BMI is.输出,用户的姓名和bmi的值
\x09\x09\x09\x09
\x09\x09\x09\x09
\x09\x09\x09\x09\x09
5.Prints out which category of weight he belongs to depending on his BMI.输出,用户的姓名,和更具bmi的值用户的体重属于哪一类的.
BMI = weight (kg) /( (height (m))(height(m))
BMI = weight (lb) / ((height (in)(height(in))*703
\x09\x09\x09
Underweight if BMI < 18.5
Normal if 18.5 ≤ BMI < 25.0
\x09\x09\x09
Overweight if 25.0 ≤ BMI < 30.0
Obese if 30.0 ≤ BMI
\x09\x09
Here are two sample output
\x09\x09\x09
v:\cmpsc101
Type your first name (with no space):
Michael
Type metric for metric system,type standard for standard system:
standard
Type in your weight in pound and your height in inch:
180
70.5
Michael,your BMI is 25.4595
Michael,you are considered to be Overweight.
\x09\x09\x09
v:\cmpsc101
Type your first name (with no space):
John
Type metric for metric system,type standard for standard system:
metric
Type in your weight in kilogram and your height in meter:
25
1
John,your BMI is 25
John,you are considered to be Overweight.
\x09\x09\x09
v:\cmpsc101
Type your first name (with no space):
Dora
Type metric for metric system,type standard for standard system:
unknown
Type in your weight in pound and your height in inch:
100
65.2
Dora,your BMI is 16.5371
Dora,you are considered to be Underweight.
谁知道这个c++的code要怎么写,code中需要用到system和category.
#include <iostream>
#include <string>
#include <stdlib.h>
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<<text1<<endl;
cin>>input;
p1->setname(input);
cout<<text2<<endl;
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<<"Type in your weight in pound and your height in inch:"<<endl;
cin>>weight>>height;
bmi=((atof((weight.c_str())))/((atof(height.c_str()))*(atof(height.c_str()))))*703;//计算bmi
p1->setbmi(bmi);
break;
case 1:
cout<<"Type in your weight in kilogram and your height in meter:"<<endl;
cin>>weight>>height;
bmi=(atof(weight.c_str()))/((atof(height.c_str()))*(atof(height.c_str())));
p1->setbmi(bmi);
break;
case 2:
cout<<"Type in your weight in pound and your height in inch:"<<endl;
cin>>weight>>height;
bmi=((atof((weight.c_str())))/((atof(height.c_str()))*(atof(height.c_str()))))*703;
p1->setbmi(bmi);
break;
}
cout<<p1->getname()<<", your BMI is "<<p1->getbmi()<<endl;
cout<<p1->getname()<<", you are considered to be ";
if(p1->getbmi()<18.5){//判断category
cout<<"Underweight"<<endl;
}
else if(p1->getbmi()<25.0){
cout<<"Normal"<<endl;
}
else if(p1->getbmi()<30.0){
cout<<"Overweight"<<endl;
}
else {
cout<<"Obese"<<endl;
}
}基本上行了,你试试,至于system和category,system是关键字,不过用不上,category可以弄成一个变量,我这里没用,也没必要.
#include <string>
#include <stdlib.h>
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<<text1<<endl;
cin>>input;
p1->setname(input);
cout<<text2<<endl;
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<<"Type in your weight in pound and your height in inch:"<<endl;
cin>>weight>>height;
bmi=((atof((weight.c_str())))/((atof(height.c_str()))*(atof(height.c_str()))))*703;//计算bmi
p1->setbmi(bmi);
break;
case 1:
cout<<"Type in your weight in kilogram and your height in meter:"<<endl;
cin>>weight>>height;
bmi=(atof(weight.c_str()))/((atof(height.c_str()))*(atof(height.c_str())));
p1->setbmi(bmi);
break;
case 2:
cout<<"Type in your weight in pound and your height in inch:"<<endl;
cin>>weight>>height;
bmi=((atof((weight.c_str())))/((atof(height.c_str()))*(atof(height.c_str()))))*703;
p1->setbmi(bmi);
break;
}
cout<<p1->getname()<<", your BMI is "<<p1->getbmi()<<endl;
cout<<p1->getname()<<", you are considered to be ";
if(p1->getbmi()<18.5){//判断category
cout<<"Underweight"<<endl;
}
else if(p1->getbmi()<25.0){
cout<<"Normal"<<endl;
}
else if(p1->getbmi()<30.0){
cout<<"Overweight"<<endl;
}
else {
cout<<"Obese"<<endl;
}
}基本上行了,你试试,至于system和category,system是关键字,不过用不上,category可以弄成一个变量,我这里没用,也没必要.
C++,输入体重,身高,算bmi
求一个c++程序 要求输入身高和体重,输出BMI值(身体质量指数)
bmi指数怎么算啊体重49KG,身高155厘米
我身高150厘米,体重45公斤.我的BMI值应该怎样算?
体育与健康理论测试?1.BMI 是指(身高M,体重KG) 身高÷体重体重÷身高C身高÷体重的平方2.女性的理想体脂范围为
体质指数BMI怎么算的咧?是身高的平方除以体重还是体重啥啥的?
求翻译 BMI值通过身高体重计算后得到
BMI算法,身高158cm,体重42kg,BMI法算出来是多少?
标准体脂肪:体重指数BMI=体重(kg)/{身高*身高(m)}
bmi怎么算,72体重75
我的体重81千克,身高166厘米.请问我的BMI值是多少?
我身高163 体重102斤 我BMI是多少 请问下