完整版c++primerplus第六版课后编程练习答案Word格式.docx

上传人:b****2 文档编号:15182135 上传时间:2022-10-28 格式:DOCX 页数:25 大小:20.80KB
下载 相关 举报
完整版c++primerplus第六版课后编程练习答案Word格式.docx_第1页
第1页 / 共25页
完整版c++primerplus第六版课后编程练习答案Word格式.docx_第2页
第2页 / 共25页
完整版c++primerplus第六版课后编程练习答案Word格式.docx_第3页
第3页 / 共25页
完整版c++primerplus第六版课后编程练习答案Word格式.docx_第4页
第4页 / 共25页
完整版c++primerplus第六版课后编程练习答案Word格式.docx_第5页
第5页 / 共25页
点击查看更多>>
下载资源
资源描述

完整版c++primerplus第六版课后编程练习答案Word格式.docx

《完整版c++primerplus第六版课后编程练习答案Word格式.docx》由会员分享,可在线阅读,更多相关《完整版c++primerplus第六版课后编程练习答案Word格式.docx(25页珍藏版)》请在冰豆网上搜索。

完整版c++primerplus第六版课后编程练习答案Word格式.docx

doublefur;

cin>

>

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

Enteryourage:

intage;

age;

intmonth;

month=age*12;

age<

yearsis"

month<

months"

//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

c

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1