C++练习(二)

第三章 处理数据
1,编写一个程序,要求用户使用一个整数指出自己的身高(单位英寸),然后将身高转换为英尺和英寸。该程序使用下划线字符来只是输出位置。另外,使用一个const符号常量来表示转换因子。

#include<iostream>
using namespace std;
const int foot = 12;
int main()
{
    int myHeight;
    cout<<"Enter you height:_____\b\b\b\b\b";
    cin>>myHeight;
    cout<<"Your height is "<<myHeight/foot
    <<" foot "
    <<myHeight-myHeight/foot*12<<" inches\n";
    return 0;
 }

2,编写一个小程序,要求以几英尺几英寸的方式输入其身高,并以榜为单位输入其体重(使用三个变量来存储这些信息)该程序报告其BMI。

#include<iostream>
using namespace std;
const int foot = 12;
const double meter = 0.0254;
const double kilo = 2.2;      //用符号常量表示转换因子
int main()
{
    int myFoot=0,myInch=0;
    double myWeight=0,height_meter;
    double num_BMI;
    cout<<"Enter your height:"<<endl<<"Foot:____\b\b\b\b";
    cin>>myFoot;
    cout<<"Inch:____\b\b\b\b";
    cin>>myInch;                    //输入身高
    cout<<"Enter your weight:____\b\b\b\b"
    <<myWeight;
    cin>>myWeight;                  //输入体重
    height_meter = (myFoot*foot + myInch)*meter;    //换算
    num_BMI = myWeight*kilo/height_meter;           //计算BMI值
    cout<<"Your BMI number is:_____\b\b\b\b\b"<<num_BMI<<endl;
    return 0;
}

3,编写一个程序,要求用户以度、分、秒的方式输入一个纬度,然后以度为单位显示该纬度。1度为60分,1分等于60秒,请以符号常量的方式表示这些值。对于每个输入值,应使用一个独立的变量储存它。
Enter a latitude in degrees, minutes, and seconds:
First, enter the degrees: 37
Next, enter the minutes of arc: 51
Finally, enter the seconds of arc: 19
37 degrees, 51 minutes, 19 seconds = 37.8553 degrees

#include<iostream>
using namespace std;
int main()
{
    int in_degree,in_minute,in_second;
    double lati_degree;
    const int degree = 60;
    const int minute = 60;
    cout<<"Enter a latitude in degrees, minutes, and seconds:"<<endl;
    cout<<"First, enter the degrees: ";
    cin>>in_degree;
    cout<<"Next, enter the minutes of arc:";
    cin>>in_minute;
    cout<<"Finally, enter the seconds of arc:";
    cin>>in_second;
    lati_degree = in_degree + double(in_minute)/degree + double(in_second)/(degree*minute);
    cout<<in_degree<<" degrees,"<<in_minute<<" minute,"<<in_second<<" seconds, "
  <<"="<<lati_degree<<" degrees"<<endl;
    return 0;
}

4,编写一个程序,要求用户以整数方式输入秒数(使用long或long long变量存储),然后以天、小时、分钟和秒的方式显示这段时间。使用符号常量来表示每天有多少小时、每小时有多少分钟以及每分钟有多少秒。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值