问题及代码:
/* *Copyright (c)2016,烟台大学计算机与控制工程学院 *All rights reserved. *文件名称:main.cpp *作 者:王艺霖
*完成日期:2016年3月8日 *版 本 号:v1.0 * *问题描述:成年男性的标准体重公式为:标准体重(kg)= 身高(cm)-100, *超标准体重20%为超重,比标准轻20%为超轻。请编写C++程序,输入身高 *和体重,完成下面的任务: *(1)计算并输出标准体重。 *(2)计算出标准体重,当超重时,请给出提示。 *(3)计算出标准体重,当超重时给出提示,不超重时也给出提示。 *(4)计算出标准体重,输出体重状态(正行/超重/超轻)。 *输入描述:根据相应问题输入身高和体重。 *输出描述:根据相应问题,输出相应的提示。 */
(1)
#include <iostream> using namespace std; int main() { cout << "输入身高:"; int height; cin >> height; cout << "标准体重:" << height - 100 << "kg" <<endl; return 0; }
运行结果:
(2)
#include <iostream> using namespace std; int main() { double height ,weight; double stdweight ,a; cout << "输入身高:"; cin >> height; cout << "输入体重:"; cin >> weight; stdweight = height - 100; a = weight/stdweight; cout << "标准体重:" << stdweight << "kg" <<endl; if(a > 1.2) cout << "超重" << endl; return 0; }
运行结果:
(3)
#include <iostream> using namespace std; int main() { double height ,weight; double stdweight ,a; cout << "输入身高:"; cin >> height; cout << "输入体重:"; cin >> weight; stdweight = height - 100; a = weight/stdweight; cout << "标准体重:" << stdweight << "kg" <<endl; if(a > 1.2) cout << "超重" << endl; else cout << "未超重" << endl; return 0; }
运行结果:
(4)
#include <iostream> using namespace std; int main() { double height ,weight; double stdweight ,a; cout << "输入身高:"; cin >> height; cout << "输入体重:"; cin >> weight; stdweight = height - 100; a = weight/stdweight; cout << "标准体重:" << stdweight << "kg" <<endl; if(a > 1.2) cout << "超重" << endl; else if(a < 0.8) cout << "超轻" << endl; else cout << "正常" << endl; return 0; }
运行结果:
知识点总结:
熟练了C++操作过程