体质指数体重身高学生学号

体质指数(Body MassIndexBMI)是评估体重与身高比例的参考指数,计算公式为t=weight/height2,其中weight代表体重(千克),height代表身高(米),成年人体质指数与体型的关系如下图所示。
BMI 说明 函数返回值
BMI<18.5 Underweight
18.5 <= BMI <25.0 Nornal
25.0<=BMI<30.0 Overweight
30.0 <= BMI Obese
试设计类BMI,属性成员包括学生学号number,身高height和体重weight,用成员函数getBMI0计算每个人的体质指数t的值,getStatus()获取对应的状态值(分别用整数12,3,4表示四种状态),主函数进行测试输出BMI值及状态值(可输入学生本人的后四位学号、身高、体重进行测试)。


#include <iostream>
using namespace std;

class studdent
{
private:
    int number;
    float height, weight;

public:
    studdent() : number(0), height(0), weight(0) {}
    studdent(int num, float h, float w) : number(num), height(h), weight(w) {}
    float getBMI();
    int getStatus();
};

float studdent::getBMI()
{
    float bmi = weight / (height * height);
    return bmi;
};
int studdent::getStatus()
{
    float bmi = getBMI();
    int status = 0;
    if (bmi < 18.5)
    {
        status = 1;
    }
    else if (bmi >= 18.5 && bmi < 25)
    {
        status = 2;
    }
    else if (bmi >= 25 && bmi < 30)
    {
        status = 3;
    }
    else if (bmi >= 30)
    {
        status = 4;
    }
    return status;
}

int main()
{
    int num;
    float h, w;
    scanf("%d%f%f", &num, &h, &w);
    studdent stu(num, h, w);
    cout << "BMI:" << stu.getBMI();
    num = stu.getStatus();
    switch (num)
    {
    case 1:
        cout << " Underweight" << endl;
        break;

    case 2:
        cout << " Nornal" << endl;
        break;

    case 3:
        cout << " Overweight" << endl;
        break;

    case 4:
        cout << " Obese" << endl;
        break;
    }

    system("pause");
    return 0;
}