资源预览内容
亲,该文档总共19页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
第二章:开始学习C+/ex2.1-display your name and address#includeint main(void)using namespace std;coutMy name is liao chunguang and I live in hunan chenzhou.n”;/ex2.2-convert the furlong units to yard uints-把浪单位换位码单位#includedouble fur2yd(double);int main()using namespace std;coutfur;coutconvert the furlong to yardendl;double yd;yd=fur2yd(fur);coutfur furlong is yd yardendl;return 0;double fur2yd(double t)return 220*t;/ex2.3-每个函数都被调用两次#includevoid mice();void see();using namespace std;int main()mice();mice();see();see();return 0;void mice()coutthree blind miceendl;void see()coutsee how they runendl;/ex2.4#includeint main() using namespace std; coutage; int month; month=age*12; coutage years is month monthsendl; return 0;/ex2.5-convert the Celsius valve to Fahrenheit value#includedouble C2F(double);int main()using namespace std;coutC;double F;F=C2F(C);coutC 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-把光年转换为天文单位#includedouble convert(double);/函数原型int main()using namespace std;coutlight_years;double astro_units;astro_units=convert(light_years);coutlight_years light_years = astro_units astronomical units.endl;return 0;double convert(double t)return 63240*t;/1 光年=63240 天文单位 /ex2.7-显示用户输入的小时数和分钟数#includevoid show();main()using namespace std;show();return 0;void show()using namespace std;int h,m;couth;coutm;coutTime:h:mendl;第三章:处理数据/ex3.1将身高用英尺(feet)和英寸(inch)表示#includeconst int inch_per_feet=12;/ const常量-1feet=12inches-1英尺=12英寸int main()using namespace std;coutht_inch;int ht_feet=ht_inch/inch_per_feet;/取商int rm_inch=ht_inch%inch_per_feet;/取余coutyour height is ht_feet feet,and rm_inch inchesn;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;coutPlease enter your height:endl;coutht_feet;coutht_inch;coutwt_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;coutendl;coutYour 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);coutyour Body Mass Index(体重指数) is BMIendl;return 0;/ex3.3 以度,分,秒输入,以度输出#includeconst int minutes_per_degree=60;const int seconds_per_minute=60;int main()using namespace std;coutEnter a latitude in degrees,minutes,and seconds:n;coutdegree;coutminute;coutsecond;double show_in_degree;show_in_degree=(double)degree+(double)minute/minutes_per_degree+(double)second/minutes_per_degree/seconds_per_minute;coutdegree degrees,minute minutes,secondseconds =show_in_degree degreesn;return 0;/ex3.4#includeconst int hours_per_day=24;const int minutes_per_hour=60;const int seconds_per_minute=60;int main()using namespace std;coutseconds;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;coutsecondsseconds = Day days,Hour hours,Minute minutes,Second secondsn;return 0;/ex3.5#includeint main() using namespace st
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号