您的位置:首页 > 其它

第二周上机实践项目——项目2-就拿胖子说事

2016-03-07 20:51 330 查看
/*
*Copyright (c)2016,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:main.cpp
*作    者:郭永恒
*完成日期:2016年3月7日
*版 本 号: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 = 0.0,weight = 0.0;
double stdweight = 0.0,scale = 0.0;
cout << "输入身高:";
cin >> height;
cout << "输入体重:";
cin >> weight;
stdweight = height - 100;
scale = weight/stdweight;
cout << "标准体重:" << stdweight << "kg" <<endl;
if(scale > 1.2)
cout << "超重" << endl;
return 0;
}运行结果:



问题(3):

#include <iostream>
using namespace std;

int main()
{
double height = 0.0,weight = 0.0;
double stdweight = 0.0,scale = 0.0;
cout << "输入身高:";
cin >> height;
cout << "输入体重:";
cin >> weight;
stdweight = height - 100;
scale = weight/stdweight;
cout << "标准体重:" << stdweight << "kg" <<endl;
if(scale > 1.2)
cout << "超重" << endl;
else
cout << "未超重" << endl;
return 0;
}

运行结果:



问题(4):

#include <iostream>
using namespace std;

int main()
{
double height = 0.0,weight = 0.0;
double stdweight = 0.0,scale = 0.0;
cout << "输入身高:";
cin >> height;
cout << "输入体重:";
cin >> weight;
stdweight = height - 100;
scale = weight/stdweight;
cout << "标准体重:" << stdweight << "kg" <<endl;
if(scale > 1.2)
cout << "超重" << endl;
else if(scale < 0.8)
cout << "超轻" << endl;
else
cout << "正常" << endl;
return 0;
}

运行结果:



知识点总计:

从这个程序中,进一步巩固了对简单程序结构的认识。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: