复习题
1
一种整型不能满足编程的需求
2
short shit=80;
unsigned shit=42110;
auto shit=3000000000;
3
没提供措施,自己小心
4
33L是long类型,33是int类型
5
等价
6
(1) int shit=88;std::cout<<(char)shit;
(2) char shit=88;std::cout<<shit;
7
如果浮点型中用于存储小数的位数>=整型的位数,就不会有舍入误差。否则,就会有。
查limits.h和float.h,自己解决。
8
74 4 0 4.5 3
9
(1) int shit=(int)x1+(int)x2;
(2) int shit=x1+x2;
10
int float char char32_t double
编程练习
3.1
#include<iostream>
int main(void)
{
using namespace std;
cout<<"输入你的身高,以英寸为单位\n";
int inch;
cin>>inch;
cout<<"你身高"<<inch/12<<"英尺"<<inch%12<<"英寸\n";
return 0;
}
3.2
#include<iostream>
int main(void)
{
using namespace std;
const int inch_per_foot=12;
const double meter_per_inch=0.0254;
const double pound_per_kg=2.2;
cout<<"输入你的身高,以英尺和英寸的方式\n你身高的英尺数:";
int foot;
cin>>foot;
cout<<"你身高的英寸数:";
int inch;
cin>>inch;
cout<<"输入你的体重,以磅为单位\n你的体重是:";
int pound;
cin>>pound;
inch=foot*12+inch;
double meter=inch*meter_per_inch;
double kg=pound/pound_per_kg;
double BMI=kg/meter/meter;
cout<<"你的身高 "<<meter<<"米\n你的体重 "<<kg<<"公斤\n你的BMI "<<BMI<<endl;
return 0;
}
3.3
#include<iostream>
int main(void)
{
using namespace std;
const int minutes_per_degrees=60;
const int seconds_per_minutes=60;
cout<<"Enter a latitude in degrees,minutes,and seconds:\n";
cout<<"First enter the degrees:";
int degrees;
cin>>degrees;
cout<<"Next,enter the minutes of arc:";
int minutes;
cin>>minutes;
cout<<"Finally,enter the seconds of arc:";
int seconds;
cin>>seconds;
cout<<degrees<<" degrees, "<<minutes<<" minutes, "<<seconds<<" seconds = "
<<degrees+(double)minutes/minutes_per_degrees+(double)seconds/minutes_per_degrees/seconds_per_minutes
<<"degrees";
return 0;
}
3.4
#include<iostream>
int main(void)
{
using namespace std;
const int hpd=24;
const int mph=60;
const int spm=60;
const int spd=hpd*mph*spm;
const int sph=mph*spm;
cout<<"Enter the number of seconds:";
long seconds;
cin>>seconds;
cout<<seconds<<" seconds = "<<seconds/spd<<" days, "<<seconds%spd/sph<<" hours, "
<<seconds%spd%sph/spm<<" minutes, "<<seconds%spd%sph%spm<<" seconds\n";
return 0;
}
3.5
#include<iostream>
int main(void)
{
using namespace std;
cout<<"Enter the world's population:";
long long world;
cin>>world;
cout<<"Enter the population of the US:";
long long US;
cin>>US;
cout<<"The population of the US is "<<(double)US/world*100<<"% of the world population.\n";
return 0;
}
3.6
#include<iostream>
int main(void)
{
using namespace std;
const double mpk=0.6214;
const double lpg=3.785;
cout<<"输入驱车里程(英里) ";
double mile;
cin>>mile;
cout<<"输入耗油量(加仑) ";
double gallon;
cin>>gallon;
cout<<"汽车耗油量为"<<mile/gallon<<"英里每加仑\n";
double km=mile/mpk;
double liter=gallon*lpg;
cout<<"每百公里耗油量为"<<liter/km*100<<"升\n";
return 0;
}
3.7
#include<iostream>
int main(void)
{
using namespace std;
const double mpk=0.6214;
const double lpg=3.785;
cout<<"输入每百公里耗油量(升) ";
double liter;
cin>>liter;
double gallon;
gallon=liter/lpg;
double mile;
mile=mpk*100;
cout<<"每百公里耗油量为"<<liter<<"升\n";
cout<<"汽车耗油量为"<<mile/gallon<<"英里每加仑\n";
return 0;
}
分享到:
相关推荐
《C++ Primer Plus第6版中文版》学习笔记(第十章) 红字内容是有疑问或者没把握的。 绿字部分是比较重要,或者经过确认的
C++primerplus(第6版)中文版编程练习答案汇编.pdf
自己看书练习编写的C++ Primer Plus(第6版)课后题答案
C++Primer Plus(第6版)中文版编程练习答案--第四章.pdf
C++ Primer Plus 编程练习源码工程 第12章 ,这是本人自己学习书籍时写的编程练习的源码工程,供大家参考交流。
C++ primer plus 第六版 中文版课后编程习题解答 C++ primer plus 第六版 中文版课后编程习题解答 C++ primer plus 第六版 中文版课后编程习题解答
C++PrimerPlus6中文版第四章程序
c++ primer plus 答案c++ primer plus 答案c++ primer plus 答案c++ primer plus 答案 c++ primer plus 答案
C++-primer-plus(第6版)中文版-编程练习答案(word版).pdf
C++ Primer Plus 第六版 第6版 中文版 编程练习答案 全面详细,助力深入理解C++精髓
包括第六版的中文思维导图 课后以及代码例程代码
《C++ Primer Plus(第6版)中文版》课后习题编程答案,不乱码版,非常适合学习c++作为参考
C++Primer Plus第六版的课后题练习题
C++ Primer Plus 第6版 中文版-思维导图,超清,5.5M
C++ primer Plus的pdf资源
c++ primer plus 第五版课后习题答案
C++ Primer PLus第六版中文版课后练习编程题答案第二章
C++PrimerPlus第6版第3章程序加课后练习
C++PrimerPlus第五版习题参考答案
c++ primer plus 第六版 课后习题答案