C++,输入体重,身高,算bmi1.Ask for the user for his first name.输入你的姓名\x09\x09\x09\x09\x09\x09\x09\x09\x09\x09\x09\x09\x092.Ask the user whether he wants to use metric or standard system.选择哪种方式来计算\x09\x09\x09\x09\x09

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/24 11:26:41
C++,输入体重,身高,算bmi1.Askfortheuserforhisfirstname.输入你的姓名\x09\x09\x09\x09\x09\x09\x09\x09\x09\x09\x09\x0

C++,输入体重,身高,算bmi1.Ask for the user for his first name.输入你的姓名\x09\x09\x09\x09\x09\x09\x09\x09\x09\x09\x09\x09\x092.Ask the user whether he wants to use metric or standard system.选择哪种方式来计算\x09\x09\x09\x09\x09
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.

C++,输入体重,身高,算bmi1.Ask for the user for his first name.输入你的姓名\x09\x09\x09\x09\x09\x09\x09\x09\x09\x09\x09\x09\x092.Ask the user whether he wants to use metric or standard system.选择哪种方式来计算\x09\x09\x09\x09\x09
#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可以弄成一个变量,我这里没用,也没必要.