第2周-项目2-就拿胖子说事

问题及代码:
/*
 *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++操作过程

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值