您的位置:首页 > 编程语言 > C语言/C++

【C++ Primer Plus 编程练习】 3.7

2013-05-17 17:18 369 查看
3.7.1

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



#include<iostream>
usingnamespacestd;

intmain()
{
inta;
constintyinzi(12);
cout<<"你的身高:_____英寸。\b\b\b\b\b";
cin>>a;
cout<<"你的身高:"<<a/yinzi<<"英尺"<<a%yinzi<<"英寸。"<<endl;
}




3.7.2



#include<iostream>
usingnamespacestd;

intmain()
{
doublefoot,inch,pound,meter,kilo,bmi;
constdoublef2i(12.0),i2m(0.0254),k2p(2.2);
cout<<"Enteryourheightandweight:"<<endl<<"___feet\b\b\b\b\b\b";
cin>>foot;
cout<<"____inches\b\b\b\b\b\b\b\b\b";
cin>>inch;
cout<<"_____pounds\b\b\b\b\b\b\b\b\b\b";
cin>>pound;
meter=i2m*(f2i*foot+inch);
kilo=pound/k2p;
bmi=kilo/(meter*meter);
cout<<"YourBMIis:"<<bmi;
}




3.7.3



#include<iostream>
usingnamespacestd;

intmain()
{
doubled,m,s;
cout<<"Enteralatitudeindegrees,minutes,andseconds:"<<endl;
cout<<"First,enterthedegrees:";
cin>>d;
cout<<"Next,entertheminutesofarc:";
cin>>m;
cout<<"Finally,enterthesecondsofarc:";
cin>>s;
cout<<d<<"degrees,"<<m<<"minutes,"<<s<<"seconds="
<<d+m/60.0+s/60.0/60.0<<"degrees";
}




3.7.4



#include<iostream>
usingnamespacestd;

intmain()
{
longs,m,h,d;
constintms(60),hm(60),dh(24);
cout<<"Enterthenumberofseconds:";
cin>>s;
cout<<s;
m=s/ms;
s%=ms;
h=m/hm;
m%=hm;
d=h/dh;
h%=dh;
cout<<"seconds="
<<d<<"days,"
<<h<<"hours,"
<<m<<"minutes,"
<<s<<"seconds";
}





                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐
章节导航