1、fur;convert the furlong to yardendl;double yd;yd=fur2yd(fur);fur furlong is yd yardreturn 0;double fur2yd(double t)return 220*t;/ex2.3-每个函数都被调用两次void mice();void see();using namespace std;mice();see();void mice()three blind micevoid see()see how they run/ex2.4 using namespace std; coutage; int month
2、; month=age*12;age years is month months return 0;/ex2.5-convert the Celsius valve to Fahrenheit valuedouble C2F(double);coutC;double F;F=C2F(C);C degrees Celsius is F degrees Fahrenheit.return 0;double C2F(double t)return 1.8*t+32; /ex2.6-convert the light years valve to astronomical units-把光年转换为天文
3、单位double convert(double);/函数原型Enter the number of light years:double light_years;light_years;double astro_units;astro_units=convert(light_years);light_years light_years = astro_units astronomical units.double convert(double t)return 63240*t;/1 光年=63240 天文单位/ex2.7-显示用户输入的小时数和分钟数void show();main()show
4、();void show()int h,m;enter the number of hours:h;enter the number of minutes:m;Time:h:m第三章:处理数据/ex3.1将身高用英尺(feet)和英寸(inch)表示const int inch_per_feet=12;/ const常量-1feet=12inches-1英尺=12英寸please enter your height in inches:_bbb/ b表示为退格字符int ht_inch;ht_inch;int ht_feet=ht_inch/inch_per_feet;/取商int rm_in
5、ch=ht_inch%inch_per_feet;/取余your height is ht_feet feet,and rm_inch inchesn/ex3.2-计算相应的body mass index(体重指数)const double meter_per_inch=0.0254;const double pound_per_kilogram=2.2;Please enter your height:First,enter your height of feet part(输入你身高的英尺部分):_bint ht_feet;ht_feet;Second,enter your height
6、of inch part(输入你身高的英寸部分):Now,please enter your weight in pound:double wt_pound;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;Your pensonal body information as follows:身高:inch(英尺inch)nht_met
7、er(米meter)n体重:wt_kilogram(千克kilogram)ndouble BMI;BMI=wt_kilogram/(ht_meter*ht_meter);your Body Mass Index(体重指数) is BMI/ex3.3 以度,分,秒输入,以度输出const int minutes_per_degree=60;const int seconds_per_minute=60;Enter a latitude in degrees,minutes,and seconds:nFirst,enter the degrees:int degree;degree;Next,en
8、ter the minutes of arc:int minute;minute;Fianlly,enter the seconds of arc:int second;second;double show_in_degree;show_in_degree=(double)degree+(double)minute/minutes_per_degree+(double)second/minutes_per_degree/seconds_per_minute;degree degrees,minute minutes,secondseconds =show_in_degree degreesn/
9、ex3.4const int hours_per_day=24;const int minutes_per_hour=60;Enter the number of seconds:long seconds;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;secondsseconds = Day days,Hour hours,MinuteSecond secondsn/ex3.5 using namespace st
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1