没有合适的资源?快使用搜索试试~ 我知道了~
C++-primer-plus(第6版)中文版-编程练习答案(word版).pdf
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 20 下载量 163 浏览量
2022-01-20
23:35:02
上传
评论 1
收藏 83KB PDF 举报
温馨提示
C++ Primer Plus第6版中文版编程练习答案 本资源为C++ Primer Plus第6版中文版编程练习答案,涵盖了C++基础知识的多个方面,包括基本语法、数据类型、函数、输入输出等。 在第二章中,主要介绍了C++的基本语法和数据类型。其中,ex2.1展示了如何使用C++输出姓名和地址。ex2.2展示了如何将英里的单位换算为码单位。ex2.3展示了函数的调用和使用。ex2.4展示了如何输入年龄并将其换算为月份。ex2.5展示了如何将摄氏温度换算为华氏温度。ex2.6展示了如何将光年换算为天文单位。ex2.7展示了如何输入小时和分钟数并将其输出。 在第三章中,主要介绍了C++中的数据处理。其中,ex3.1展示了如何将身高用英尺和英寸表示。 本资源为C++学习者提供了一个系统的学习资源,涵盖了C++基础知识的多个方面。 知识点: 1. C++基本语法:变量、数据类型、运算符、控制结构、函数等。 2. C++中的输入输出:使用cin和cout实现输入输出。 3. 函数的使用:函数的定义、调用和使用。 4. 单位换算:英里的单位换算为码单位、摄氏温度换算为华氏温度、光年换算为天文单位等。 5. 数据处理:将身高用英尺和英寸表示、输入小时和分钟数并将其输出等。 本资源为C++学习者提供了一个系统的学习资源,涵盖了C++基础知识的多个方面。
资源推荐
资源详情
资源评论
.
第二章:开始学习 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. 〞;
}
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;
}
每个函数都被调用两次
#include<iostream>
void mice();
void see();
using namespace std;
int main()
{
mice();
mice();
see();
see();
return 0;
}
.
void mice()
{
cout<<"three blind mice"<<endl;
}
void see()
{
cout<<"see how they run"<<endl;
}
#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;
}
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;
}
.
the light years valve to astronomical units-- 把光年转换为天文单位
#include<iostream>
double convert(double);// 函数原型
int main()
{
using namespace std;
cout<<"Enter the number of light years:";
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 天文单位
}
显示用户输入的小时数和分钟数
#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";
return 0;
}
计算相应的 body mass index〔体重指数〕
#include<iostream>
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<<"Please enter your height:"<<endl;
cout<<"First,enter your height of feet part 〔输入你身高的英尺局部〕 :_\b";
int ht_feet;
cin>>ht_feet;
cout<<"Second,enter your height of inch part 〔输入你身高的英寸局部〕 :_\b";
int ht_inch;
cin>>ht_inch;
cout<<"Now,please enter your weight in pound: \b\b\b";
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<<endl;
cout<<"Your pensonal body information as follows:"<<endl; cout<<" 身
高:"<<inch<<"( 英尺 inch)\n"<<" 身高 :"<<ht_meter<<"( 米 meter)\n"
<<"体重 :"<<wt_kilogram<<"( 千克 kilogram)\n";
double BMI;
BMI=wt_kilogram/(ht_meter*ht_meter);
.
cout<<"your Body Mass Index( 体重指数 ) is "<<BMI<<endl;
return 0;
}
以度,分,秒输入,以度输出
#include<iostream>
const int minutes_per_degree=60;
const int seconds_per_minute=60;
int main()
{
using namespace std;
cout<<"Enter a latitude in degrees,minutes,and seconds:\n";
cout<<"First,enter the degrees:";
int degree;
cin>>degree;
cout<<"Next,enter the minutes of arc:";
int minute;
cin>>minute;
cout<<"Fianlly,enter the seconds of arc:";
int second;
cin>>second;
double show_in_degree;
show_in_degree=(double)degree+(double)minute/minutes_per_degree+(double)second/mi
nutes_per_degree/seconds_per_minute;
cout<<degree<<" degrees,"<<minute<<" minutes,"<<second<<"seconds
="<<show_in_degree<<" degrees\n";
return 0;
}
#include<iostream>
const int hours_per_day=24;
const int minutes_per_hour=60;
const int seconds_per_minute=60;
int main()
{
using namespace std;
cout<<"Enter the number of seconds:";
long seconds;
cin>>seconds;
int Day,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;
剩余49页未读,继续阅读
月亮677
- 粉丝: 9
- 资源: 17万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页