没有合适的资源?快使用搜索试试~ 我知道了~
(完整word版)c++primerplus(第六版)课后编程练习答案.doc
0 下载量 189 浏览量
2022-11-20
13:41:20
上传
评论
收藏 68KB DOC 举报
温馨提示
试读
17页
(完整word版)c++primerplus(第六版)课后编程练习答案.doc
资源推荐
资源详情
资源评论
(完整 word 版)c++primerplus(第六版)课后编程练习答案
第二章:开始学习 C++
//ex2.1-—display your name and address
#include<iostream>
int main(void)
{
using namespace std;
cout<<"My name is liao chunguang and I live in hunan chenzhou。";
}
//ex2.2-—convert the furlong units to yard uints-把浪单位换位码单位
#include<iostream〉
double fur2yd(double);
int main()
{
using namespace std;
cout〈〈"enter the distance measured by furlong units:";
double fur;
cin>>fur;
cout<〈”convert the furlong to yard”<〈endl;
double yd;
yd=fur2yd(fur);
cout〈<fur〈<” furlong is ”<〈yd<〈" yard"〈<endl;
return 0;
}
double fur2yd(double t)
{
return 220*t;
}
//ex2。3-每个函数都被调用两次
#include〈iostream〉
void mice();
void see();
using namespace std;
int main()
{
mice();
mice();
see();
see();
return 0;
}
void mice()
{
cout<<”three blind mice”<<endl;
(完整 word 版)c++primerplus(第六版)课后编程练习答案
}
void see()
{
cout〈<"see how they run”〈<endl;
}
//ex2.4
#include〈iostream〉
int main()
{
using namespace std;
cout〈〈”Enter your age:";
int age;
cin>>age;
int month;
month=age*12;
cout<〈age<〈” years is "〈〈month〈<" months”<〈endl;
return 0;
}
//ex2。5---convert the Celsius valve to Fahrenheit value
#include<iostream〉
double C2F(double);
int main()
{
using namespace std;
cout〈<”please enter a Celsius value:";
double C;
cin>>C;
double F;
F=C2F(C);
cout〈〈C<<" degrees Celsius is "<<F<<” degrees Fahrenheit."〈<endl;
return 0;
}
double C2F(double t)
{
return 1.8*t+32;
}
//ex2。6--—convert the light years valve to astronomical units-—把光年转换为天文单位
#include〈iostream〉
double convert(double);//函数原型
int main()
{
using namespace std;
cout<〈"Enter the number of light years:";
(完整 word 版)c++primerplus(第六版)课后编程练习答案
double light_years;
cin〉>light_years;
double astro_units;
astro_units=convert(light_years);
cout<<light_years〈〈" light_years = "<〈astro_units<<" astronomical units."<〈endl;
return 0;
}
double convert(double t)
{
return 63240*t;//1 光年=63240 天文单位
}
//ex2.7——显示用户输入的小时数和分钟数
#include〈iostream〉
void show();
main()
{
using namespace std;
show();
return 0;
}
void show()
{
using namespace std;
int h,m;
cout<〈”enter the number of hours:";
cin〉〉h;
cout〈<”enter the number of minutes:”;
cin>>m;
cout〈〈"Time:"〈<h<<”:”<〈m<〈endl;
}
第三章:处理数据
//ex3。1—将身高用英尺(feet)和英寸(inch)表示
#include〈iostream〉
const int inch_per_feet=12;// const 常量-—1feet=12inches-—1 英尺=12 英寸
int main()
{
using namespace std;
cout〈〈"please enter your height in inches:___\b\b\b";// \b 表示为退格字符
int ht_inch;
cin>>ht_inch;
int ht_feet=ht_inch/inch_per_feet;//取商
int rm_inch=ht_inch%inch_per_feet;//取余
cout〈<"your height is "〈<ht_feet<〈” feet,and "
<〈rm_inch〈<" inches\n”;
剩余16页未读,继续阅读
资源评论
yyyyyyhhh222
- 粉丝: 415
- 资源: 6万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功