復習題
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<
如果浮點型中用於存儲小數的位數>=整型的位數,就不會有捨入誤差。否則,就會有。
查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
#includeint main(void) { using namespace std; cout<<"輸入你的身高,以英寸為單位\n"; int inch; cin>>inch; cout<<"你身高"<
3.2#includeint 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<<"你的身高 "<
3.3#includeint 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<
3.4#includeint 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<
3.5#includeint 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#includeint 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<<"汽車耗油量為"<
3.7#includeint 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<<"每百公裡耗油量為"<