(完整版)c++primerplus(第六版)课后编程练习答案Word文档格式.doc
- 文档编号:13062639
- 上传时间:2022-10-04
- 格式:DOC
- 页数:19
- 大小:85.01KB
(完整版)c++primerplus(第六版)课后编程练习答案Word文档格式.doc
《(完整版)c++primerplus(第六版)课后编程练习答案Word文档格式.doc》由会员分享,可在线阅读,更多相关《(完整版)c++primerplus(第六版)课后编程练习答案Word文档格式.doc(19页珍藏版)》请在冰豆网上搜索。
>
fur;
convertthefurlongtoyard"
endl;
doubleyd;
yd=fur2yd(fur);
fur<
furlongis"
yd<
yard"
return0;
doublefur2yd(doublet)
return220*t;
//ex2.3-每个函数都被调用两次
voidmice();
voidsee();
usingnamespacestd;
mice();
see();
voidmice()
threeblindmice"
voidsee()
seehowtheyrun"
//ex2.4
usingnamespacestd;
cout<
Enteryourage:
intage;
cin>
age;
intmonth;
month=age*12;
age<
yearsis"
month<
months"
return0;
//ex2.5---converttheCelsiusvalvetoFahrenheitvalue
doubleC2F(double);
cout<
pleaseenteraCelsiusvalue:
doubleC;
cin>
C;
doubleF;
F=C2F(C);
C<
degreesCelsiusis"
F<
degreesFahrenheit."
return0;
doubleC2F(doublet)
return1.8*t+32;
}
//ex2.6---convertthelightyearsvalvetoastronomicalunits--把光年转换为天文单位
doubleconvert(double);
//函数原型
Enterthenumberoflightyears:
doublelight_years;
light_years;
doubleastro_units;
astro_units=convert(light_years);
light_years<
light_years="
astro_units<
astronomicalunits."
doubleconvert(doublet)
return63240*t;
//1光年=63240天文单位
//ex2.7--显示用户输入的小时数和分钟数
voidshow();
main()
show();
voidshow()
inth,m;
enterthenumberofhours:
h;
enterthenumberofminutes:
m;
Time:
h<
:
m<
第三章:
处理数据
//ex3.1—将身高用英尺(feet)和英寸(inch)表示
constintinch_per_feet=12;
//const常量--1feet=12inches--1英尺=12英寸
pleaseenteryourheightininches:
___\b\b\b"
//\b表示为退格字符
intht_inch;
ht_inch;
intht_feet=ht_inch/inch_per_feet;
//取商
intrm_inch=ht_inch%inch_per_feet;
//取余
yourheightis"
ht_feet<
feet,and"
<
rm_inch<
inches\n"
//ex3.2--计算相应的bodymassindex(体重指数)
constdoublemeter_per_inch=0.0254;
constdoublepound_per_kilogram=2.2;
Pleaseenteryourheight:
First,enteryourheightoffeetpart(输入你身高的英尺部分):
_\b"
intht_feet;
ht_feet;
Second,enteryourheightofinchpart(输入你身高的英寸部分):
Now,pleaseenteryourweightinpound:
doublewt_pound;
wt_pound;
intinch;
inch=ht_feet*inch_per_feet+ht_inch;
doubleht_meter;
ht_meter=inch*meter_per_inch;
doublewt_kilogram;
wt_kilogram=wt_pound/pound_per_kilogram;
Yourpensonalbodyinformationasfollows:
身高:
inch<
(英尺inch)\n"
ht_meter<
(米meter)\n"
体重:
wt_kilogram<
(千克kilogram)\n"
doubleBMI;
BMI=wt_kilogram/(ht_meter*ht_meter);
yourBodyMassIndex(体重指数)is"
BMI<
//ex3.3以度,分,秒输入,以度输出
constintminutes_per_degree=60;
constintseconds_per_minute=60;
Enteralatitudeindegrees,minutes,andseconds:
\n"
First,enterthedegrees:
intdegree;
degree;
Next,entertheminutesofarc:
intminute;
minute;
Fianlly,enterthesecondsofarc:
intsecond;
second;
doubleshow_in_degree;
show_in_degree=(double)degree+(double)minute/minutes_per_degree+(double)second/minutes_per_degree/seconds_per_minute;
degree<
degrees,"
minute<
minutes,"
second<
seconds="
show_in_degree<
degrees\n"
//ex3.4
constinthours_per_day=24;
constintminutes_per_hour=60;
{
Enterthenumberofseconds:
longseconds;
seconds;
intDay,Hour,Minute,Second;
Day=seconds/seconds_per_minute/minutes_per_hour/hours_per_day;
Hour=seconds/seconds_per_minute/minutes_per_hour%hours_per_day;
Minute=seconds/seconds_per_minute%minutes_per_hour;
Second=seconds%seconds_per_minute;
seconds<
seconds="
Day<
days,"
Hour<
hours,"
Minute<
Second<
seconds\n"
//ex3.5
usingnamespacest
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 完整版 primerplus 第六 课后 编程 练习 答案
![提示](https://static.bdocx.com/images/bang_tan.gif)