• BMI指数测量——c++ 1.0.0


    BMI

    身体质量指数(BMI,Body Mass Index)是国际上常用的衡量人体肥胖程度和是否健康的重要标准,主要用于统计分析。肥胖程度的判断不能采用体重的绝对值,它天然与身高有关。因此,BMI 通过人体体重和身高两个数值获得相对客观的参数,并用这个参数所处范围衡量身体质量。

    计算公式

    体重指数BMI=体重/身高的平方(国际单位kg/㎡)
    理想BMI(18.5~23.9) = 体重(单位Kg) ÷ 身高的平方 (单位m)根据世界卫生组织定下的标准,亚洲人的BMI(体重指标Body Mass Index)若高于22.9便属于过重。亚洲人和欧美人属于不同人种,WHO的标准不是非常适合中国人的情况,为此制定了中国参考标准:
    在这里插入图片描述
    来源:百度百科
    程序可以这么写,先创建两个个文本文档:AldBMI.txt
    里面写:


    low 0 18.4
    right 18.5 23.9
    big 24.0 27.9
    large 28.0 100.0


    和StuBMI.txt


    low 10.0 14.6
    right 14.7 21.8
    big 21.9 24.5
    large 24.8 100.0


    代表学生版和成人版BMI数据
    我们把下限设为0,上限设为100,这样以免麻烦

    代码:

    #include <iostream>
    #include <string>
    #include <fstream>
    
    #include <conio.h>
    #include <iomanip>
    #include "windows.h"
    
    using namespace std;
    
    
    
    void OUTlevel(string s)
    {
    	if(s == "low")
    		cout << "您的BMI等级为:" << "偏瘦" << endl;
    	else if(s == "big")
    		cout << "您的BMI等级为:" << "超重" << endl;
    	else if(s == "large")
    		cout << "您的BMI等级为:" << "肥胖" << endl; 
    }
    
    
    void CheckAndOut(double AnsBMI, double high, double weight)//最后检查输出 
    {
    	const double rightWeightB = 21.8 * (high * high);//常量定义,正常重量边界 
    	const double rightWeightS = 14.7 * (high * high);//常量定义,正常重量边界 
    	if(rightWeightS > AnsBMI)
    		cout << "您还需要加" << rightWeightS - AnsBMI << "Kg" << endl;
    	else if(rightWeightB < AnsBMI)
    		cout << "您还需要减" << AnsBMI - rightWeightB << "Kg" << endl; 
    }
    
    
    
    
    
    
    struct BMI_ALL{//结构体定义, 
    	string lv;//等级 
    	double score_small;//小成绩 
    	double score_big;//大成绩 
    };
    
    void BMI_STUDENT();
    void BMI_ALDULT();//提前声明 
    
    void BMI_m()//menu主界面 
    {
    	while(true){
    		cout << "--------BMI test--------" << endl;
    		cout << "aldult               [1]" << endl;
    		cout << "student              [2]" << endl;
    		cout << "exit                 [0]" << endl;
    		cout << "------------------------" << endl;
    		cout << ">>> ";
    		int Choose;
    		cin >> Choose;//无等待输入-conio.h 
    		switch (Choose)
    		{
    		case 1:
    			system("cls");
    			BMI_ALDULT();
    			break;
    	
    		case 2:
    			system("cls");
    			BMI_STUDENT();
    			break;
    			
    		case 0:
    			goto loop;
    		}
    	}
    	loop:
    	return;
    }
    
    void BMI_STUDENT()
    {
    	ifstream fin("StuBMI.txt");
    	double high, weight;
    	cout << "BMI for aldult:" << endl;
    	cout << "tips:输入时如无小数点加.0" << endl;
    	cout << "input your high(M)" << endl;
    	cin >> high;
    	cout << "input your weight(kg)" << endl;
    	cin >> weight;
    	double BMIn = weight / (high * high);//19.65
    	BMI_ALL student[4];
    	for(int i = 0; i < 3; i++){
    		fin >> student[i].lv >> student[i].score_small >> student[i].score_big;//录入等级 
    	}/*
    	for(int i = 0; i < 3; i++){
    		
    		cout << student[i].lv << student[i].score_small << student[i].score_big << endl;
    	}*/
    	for(int i = 0; i < 3; i++)
    		if(BMIn >= student[i].score_small && BMIn <= student[i].score_big){
    			cout << "BMI值=" << BMIn << endl; 
    			OUTlevel(student[i].lv);
    			if(i == 1)
    				cout << "恭喜!达到正常水平!" << endl;//是否达到正常水平 
    			else
    				CheckAndOut(BMIn, high, weight);//否则不正常-二阶查看 
    			//cout << "check loop" << endl;
    		}
    		//cout << "check loop" << endl;
    	system("pause");
    	system("cls");
    	return;
    }
    
    void BMI_ALDULT()
    {
    	ifstream fin("AldBMI.txt");
    	double high, weight;
    	cout << "BMI for aldult:" << endl;
    	cout << "tips:输入时如无小数点加.0" << endl;
    	cout << "input your high(M)" << endl;
    	cin >> high;
    	cout << "input your weight(kg)" << endl;
    	cin >> weight;
    	double BMIn = weight / (high * high);//19.65
    	BMI_ALL student[4];
    	for(int i = 0; i < 3; i++){
    		fin >> student[i].lv >> student[i].score_small >> student[i].score_big;//录入等级 
    	}/*
    	for(int i = 0; i < 3; i++){
    		
    		cout << student[i].lv << student[i].score_small << student[i].score_big << endl;
    	}*/
    	for(int i = 0; i < 3; i++)
    		if(BMIn >= student[i].score_small && BMIn <= student[i].score_big){
    			cout << "BMI值=" << BMIn << endl;
    			OUTlevel(student[i].lv);
    			if(i == 1)
    				cout << "恭喜!达到正常水平!" << endl;//是否达到正常水平 
    			else
    				CheckAndOut(BMIn, high, weight);//否则不正常-二阶查看 
    			//cout << "check loop" << endl;
    		}
    		//cout << "check loop" << endl;
    	system("pause");
    	system("cls");
    	return;
    }
    
    
    
    
    
    
    int main()
    {
    	BMI_m();
    	return 0;
    }
    

    详细文件、代码、exe文件链接:
    https://download.csdn.net/download/cool99781/12149691

  • 相关阅读:
    RocketMQ系列(一)基本概念
    怎样实现登录?| Cookie or JWT
    Hotspot GC研发工程师也许漏掉了一块逻辑
    初级Java工程师也能轻松进行JVM调优了
    自动化不知如何参数化(二)?xlrd来帮你解决
    自动化不知如何参数化(一)?xlrd来帮你解决
    SpringCloud系列之API网关(Gateway)服务Zuul
    SpringCloud系列之客户端负载均衡Netflix Ribbon
    SpringCloud系列之使用Feign进行服务调用
    Spring Security系列之极速入门与实践教程
  • 原文地址:https://www.cnblogs.com/coding365/p/12872351.html
Copyright © 2020-2023  润新知