云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > c++primerplus(第六版)课后编程练习答案

c++primerplus(第六版)课后编程练习答案

  • 62 次阅读
  • 3 次下载
  • 2025/5/3 3:31:57

. .

第二章:开始学习C++

//ex2.1--display your name and address #include int main(void) {

using namespace std;

cout<<\”; }

//ex2.2--convert the furlong units to yard uints-把浪单位换位码单位 #include double fur2yd(double); int main() {

using namespace std;

cout<<\ double fur; cin>>fur;

cout<<\

double yd;

yd=fur2yd(fur);

cout<

double fur2yd(double t) {

return 220*t; }

//ex2.3-每个函数都被调用两次 #include void mice(); void see();

using namespace std; int main() {

mice(); mice(); see(); see(); return 0; }

word完美格式

. .

void mice() {

cout<<\}

void see() {

cout<<\ }

//ex2.4

#include int main() {

using namespace std; cout<<\ int age; cin>>age; int month; month=age*12;

cout<

//ex2.5---convert the Celsius valve to Fahrenheit value #include double C2F(double); int main() {

using namespace std;

cout<<\double C; cin>>C; double F; F=C2F(C);

cout<

double C2F(double t) {

return 1.8*t+32; }

word完美格式

. .

//ex2.6---convert the light years valve to astronomical units--把光年转换为天文单位

#include

double convert(double);//函数原型 int main() {

using namespace std;

cout<<\double light_years; cin>>light_years; double astro_units;

astro_units=convert(light_years);

cout<

double convert(double t) {

return 63240*t;//1 光年=63240 天文单位 }

//ex2.7--显示用户输入的小时数和分钟数 #include void show(); main() {

using namespace std; show(); return 0; }

void show() {

using namespace std; int h,m;

cout<<\cin>>h;

cout<<\cin>>m;

cout<<\ }

第三章:处理数据

word完美格式

. .

//ex3.1—将身高用英尺(feet)和英寸(inch)表示 #include

const int inch_per_feet=12;// const常量--1feet=12inches--1英尺=12英寸 int main() {

using namespace std;

cout<<\表示为退格字符 int ht_inch; cin>>ht_inch;

int ht_feet=ht_inch/inch_per_feet;//取商 int rm_inch=ht_inch%inch_per_feet;//取余

cout<<\ <

//ex3.2--计算相应的body mass index(体重指数) #include

const int inch_per_feet=12;

const double meter_per_inch=0.0254; const double pound_per_kilogram=2.2; int main() {

using namespace std;

cout<<\

cout<<\(输入你身高的英尺部分):_\\b\ int ht_feet; cin>>ht_feet;

cout<<\(输入你身高的英寸部分):_\\b\ int ht_inch; cin>>ht_inch;

cout<<\ double wt_pound; cin>>wt_pound; int inch;

inch=ht_feet*inch_per_feet+ht_inch; double ht_meter;

ht_meter=inch*meter_per_inch; double wt_kilogram;

wt_kilogram=wt_pound/pound_per_kilogram; cout<

cout<<\

cout<<\身高:\英尺inch)\\n\身高:\米meter)\\n\ <<\体重:\千克kilogram)\\n\ double BMI;

word完美格式

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

. . 第二章:开始学习C++ //ex2.1--display your name and address #include int main(void) { using namespace std; cout<<\”; } //ex2.2--convert the furlong units to yard uints-把浪单位换位码单位 #include double fur2yd(double); int main() { using namespace std; cout<>fur; cout<<\double yd;

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com