M. 身体评估(类与对象)

题目描述

评估成年人身体健康有多个指标,包括BMI、体脂率BFR等

设计一个身体健康类,包含私有成员:姓名、身高(米)、体重(公斤),腰围(厘米),实现两个公有方法如下:

BMI方法,返回BMI数值(整数),计算公式BMI= 体重 / 身高的平方

体脂率方法,返回体脂率数值(浮点数),计算过程如下:

1)参数a=腰围(cm)×0.74

2)参数b=体重(kg)×0.082+34.89

3)体脂肪重量(kg)=a-b

4)体脂率 = 体脂肪重量÷体重

其它方法根据需要自行定义

输入

第一行输入t表示有t个测试实例

第二行起,每行输入四个参数:姓名、身高、体重,腰围

依次输入t行

输出

输出t行,每行输入一个实例的BMI和体脂率,小数数值精确到小数点后2位,用空格隔开

输入样例1:

2
David 1.85 78.5 85.2
Sara 1.55 67.6 77.3


输出样例1:

David's BMI: 23--BFR: 0.28
Sara's BMI: 28--BFR: 0.25

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;

class health
{
public:
    string name;
    double height;
    double weight;
    double waistline;
public:
    health():name(""),height(0),weight(0),waistline(0){}

    health(string s,double h,double we, double wa):name(s),height(h),weight(we),waistline(wa){}
    int BMI()
    {
        int result=round(weight/(height*height));
        return result;
    }
    double BFR()
    {
        double a=waistline*0.74;
        double b=weight*0.082+34.89;
        return (a-b)/weight;
    }
};
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        string s;
        double h,we,wa;
        cin>>s>>h>>we>>wa;
        health person(s,h,we,wa);
        int result1=person.BMI();
        double result2=person.BFR();
        cout<<fixed<<setprecision(2)<<person.name<<"'s BMI: "<<result1<<"--"<<"BFR: "<<result2<<endl;

    }
    return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值