文档详情

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

桔****
实名认证
店铺
DOC
59KB
约29页
文档ID:483067110
c++primerplus(第六版)课后编程练习答案_第1页
1/29

第二章:开始学习C++//ex2.1--display your name and address#includeint 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<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<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"<>age; int month; month=age*12; cout<<age<<" years is "<<month<<" months"<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:";double light_years;cin>>light_years;double astro_units;astro_units=convert(light_years);cout<>h;cout<<"enter the number of minutes:";cin>>m;cout<<"Time:"<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;}//ex3.2--计算相应的body mass index(体重指数)#includeconst 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<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/minutes_per_degree/seconds_per_minute;ﻩcout<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<<seconds<<"seconds = "<<Day<<" days,"<<Hour<<" hours,"<

下载提示
相似文档
正为您匹配相似的精品文档