第二周上机实践项目——项目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;
}
运行结果:
知识点总计:
从这个程序中,进一步巩固了对简单程序结构的认识。
相关文章推荐
- 1102. Invert a Binary Tree (25)
- UVa_OJ 489 刽子手的游戏
- 手把手教你做手机婚恋网
- intellij rename module后报错,解决
- What Are You Talking About (HDU_1075) 字典树
- mysql 5.7.11 rpm安装
- 如何合理地估算线程池大小?
- onWindowFocusChanged触发简介
- ggplot2-条形图和折线图
- LeetCode : Generate Parentheses [java]
- Source Insight的安装及使用
- [LeetCode]43 高精度乘法
- GUIForDebug
- (原)hisi3531立体声pcm实现播放方式
- Windows下安装 使用coreseek
- Java集合面试题(40道)
- /etc/sysconfig/authconfig 文件详解
- python的性能优化
- thinking in java 04
- 下载页面