logo资料库

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

第1页 / 共19页
第2页 / 共19页
第3页 / 共19页
第4页 / 共19页
第5页 / 共19页
第6页 / 共19页
第7页 / 共19页
第8页 / 共19页
资料共19页,剩余部分请下载后查看
第二章:开始学习 C++ //ex2.1--display your name and address #include int main(void) { using namespace std; cout<<"My name is liao chunguang and I live in hunan chenzhou.\n ”; } //ex2.2--convert the furlong units to yard uints- 把浪单位换位码单位 #include 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"< void mice(); void see(); using namespace std; int main() { mice(); mice(); see(); see(); return 0; }
void mice() { cout<<"three blind mice"< int main() { using namespace std; cout<<"Enter your age:"; int age; cin>>age; int month; month=age*12; cout< double C2F(double); int main() { using namespace std; cout<<"please enter a Celsius value:"; double C; cin>>C; double F; F=C2F(C); cout<
//ex2.6---convert the light years valve to astronomical units-- 把光年转换为天文单位 #include 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< 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:"<
#include const int inch_per_feet=12;// int main() { const 常量 --1feet=12inches--1 英尺 =12 英寸 \b 表示为退格字符 using namespace std; cout<<"please enter your height in inches:___\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 "< 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:"<>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<
cout<<"your Body Mass Index( 体重指数 ) is "< 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< 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;
Second=seconds%seconds_per_minute; cout< int main() { using namespace std; cout<<"Enter the world population:"; long long world_population; cin>>world_population; cout<<"Enter the population of the US:"; long long US_population; cin>>US_population; double percentage; percentage=(double)US_population/world_population*100; cout<<"The population of the US is "< int main() { using namespace std; cout<<"Enter the miles of distance you have driven:"; double m_distance; cin>>m_distance; cout<<"Enter the gallons of gasoline you have used:"; double m_gasoline; cin>>m_gasoline; cout<<"Your car can run "<>k_distance; cout<<"Enter the petrol in liters:"; double k_gasoline; cin>>k_gasoline; cout<<"In European style:"<<"your can used "<<100*k_gasoline/k_distance<<" per 100 kilometers\n"; liters of petrol
return 0; } automobile gasoline consumption- 耗油量 --欧洲风格 (L/100Km)转换成美国风格 (mpg) //ex3.7 #include int main() { using namespace std; cout<<"Enter the automobile gasoline consumption figure in\n" <<"European style(liters per 100 kilometers):"; double Euro_style; cin>>Euro_style; cout<<"Converts to U.S. style(miles per gallon):"< int main() { using namespace std; cout<<"Enter the automobile gasoline consumption figure in\n" <<"U.S. style(miles per gallon):"; double US_style; cin>>US_style; cout<<"Converts to European style(miles per gallon):"<
//ex4.1 display the information of student #include const int Asize=20; using namespace std; struct student// 定义结构描述 { char firstname[Asize]; char lastname[Asize]; char grade; int age; }; void display(student);// 函数原型放在结构描述后 int main() { cout<<"what is your first name?"<>lcg.grade; cout<<"what is your age?"<>lcg.age; display(lcg); return 0; } void display(student name) { cout<<"Name: "< #include int main() { using namespace std; string name,dessert; cout<<"Enter your name: \n"; getline(cin,name);
分享到:
收藏