C++ Primer Plus edition6 section3

#include <iostream>
#include <climits>
using namespace std;
void eg1();
void eg2();

int main()
{
    //.eg1();
    eg2();
}

void eg1()
{
    const float h = 14;
    float in;
    cout << "请输入您的身高:___\b\b\b";
    cin >> in;
    cout << "\n您的身高是:" << in*h << " 英尺" <<endl;

}

void eg2()
{
    const int yc = 14;//1英尺=14英寸
    const double m = 0.0254;//1英寸=0.0254米
    const double bang = 2.2;//1kg = 2.2磅
    double y, c, z;//y:英尺,c英寸,z磅体重
    cout << "请输入您的身高,英尺:___\b\b\b";
    cin >> y;
    cin.get();
    cout <<"英寸:___\b\b\b";
    cin >> c ;
    cin.get();
    cout << "体重:___\b\b\b";
    cin >> z;
    cin.get();
    cout << "按任意键查看结果:"<<endl;
    cin.get();

    double tz = z/bang;//磅转千克
    double sg = (y/yc + c) * m;//英寸转米

    double BMI = tz/(sg*sg);
    cout << "\nBMI值:"<<BMI<<endl;

}
void eg3()
{
    const int d2f = 60;//度转分
    const int f2m = 60;//分转秒
    double degress, minutes, seconds;
    cout << "Enter a latitude in degress, minutes, and seconds:"<<endl;
    cout << "First, enter the minutes of arc:";
    cin >> degress;
    cin.get();
    cout << "Next, enter the minutes of arc:";
    cin >> minutes;
    cin.get();
    cout << "Finally, enter the seconds of arc:";
    cin >> seconds;
    cin.get();


    double result = degress + minutes/d2f + seconds/(d2f*f2m);
    cout << degress <<" degress, "<<minutes<<" minutes, "<<seconds<<" seconds = "<< result <<" degress"<<endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值