c语言详解第五版第四章程序设计项目答案Word文档格式.docx
《c语言详解第五版第四章程序设计项目答案Word文档格式.docx》由会员分享,可在线阅读,更多相关《c语言详解第五版第四章程序设计项目答案Word文档格式.docx(22页珍藏版)》请在冰点文库上搜索。
system("
pause"
return(0);
}
voidinstruct_purchase(void)
{printf("
Thisprogramfigureatotalbill."
Thetaxrateis$%.2f.\n"
tax_rate);
Thediscountoftotalpurchasewhichismorethan100dollarsis$%.2f.\n"
discount_1);
Thediscountoftotalpurchasewhichislessthan100dollarsis$%.2f.\n"
discount_2);
Pleasepress<
return>
or<
enter>
buttonaftertypingineachnumber.\n\n\n"
doubletotal(doubletotal_purchase,chara)
{doublediscount_total,total_payment,tax;
if(a=='
t'
)
if(total_purchase>
100)
{discount_total=total_purchase*discount_1;
tax=total_purchase*tax_rate;
total_payment=total_purchase+tax-discount_total;
}
else
{discount_total=total_purchase*discount_2;
else
{tax=total_purchase*tax_rate;
total_payment=total_purchase+tax;
return(total_payment);
3.罗盘的度数换算为罗盘的方位。
voiddirection(doubleangle_degree);
{doubleangle_degree;
printf("
Pleaseentertheangleofthetotalstation.>
scanf("
angle_degree);
Theangleofthetotalstationis%.2f°
?
.\n\n\n"
angle_degree);
direction(angle_degree);
system("
return(0);
voiddirection(doubleangle_degree)
{doubleangle;
if(angle_degree==0)
{printf("
Thedirectioniseast(E).\n\n"
if(0<
angle_degree&
&
angle_degree<
90)
Thedirectionisnorth(N)%.2feast(E).\n\n"
if(angle_degree==90)
Thedirectionisnorth(N)."
if(90<
180)
{angle=180-angle_degree;
Thedirectionisnorth(N)%.2fwest(W).\n\n"
angle);
if(angle_degree==180)
Thedirectioniswest(W).\n\n"
if(180<
270)
{angle=angle_degree-180;
Thedirectionissouth(S)%.2fwest(W).\n\n"
if(angle_degree==270)
Thedirectionissouth(S).\n\n"
if(270<
360)
{angle=angle_degree-270;
4.编写一个程序根据压缩气囊颜色的第一个字母确定压缩罐的内容。
voidcolor(charfa);
{charfa;
Pleaseenterthefirstalphabetofthecontainer.>
fa);
color(fa);
voidcolor(charfa)
{switch(fa)
{case'
O'
:
case'
o'
Thecolorsuggestthecontentisammoniagas.\n\n"
break;
case'
B'
b'
ThecolorsuggestthecontentisCO.\n\n"
Y'
y'
Thecolorsuggestthecontentishydrogen.\n\n"
G'
g'
Thecolorsuggestthecontentisoxygen.\n\n"
default:
Thereisnotthecontainer."
}}
5.对地震的理氏数进行描述。
voidRichter_scale(doublea);
{doublea;
PleaseentertheRichterscaleoftheearthquake.>
"
Richter_scale(a);
voidRichter_scale(doublea)
{if(a>
0&
a<
5.0)
破?
坏¦
Ì
很¨
¹
小?
或¨
°
者?
没?
有®
D.\n"
elseif(a<
5.5)
printf("
一°
些?
.\n"
6.5)
严?
重?
;
ê
墙?
会¨
¢
倒Ì
1塌¨
²
7.5)
灾?
难?
房¤
屋Y或¨
建¡
§
筑t物?
elseif(a>
=7.5)
大ä
¨
®
部?
分¤
被À
Thereisnotthismagnititudeofearthquake.\n"
(2)switch函数编写
charRichter_scale(doublea);
voidsf(charb);
charb;
b=Richter_scale(a);
sf(b);
charRichter_scale(doublea)
{charc;
if(a>
{c='
A'
;
return(c);
}
C'
D'
E'
=0)
F'
voidsf(charb)
{switch(b)
D。
¡
break;
。
屋Y和¨
ª
无T该?
地Ì
震e等Ì
级?
6.判断一个点在哪个象限
voidquadrant(doublea,doubleb);
{doublea,b;
Pleaseenterthecoordinateofthedot.>
%lf%lf"
a,&
b);
quadrant(a,b);
voidquadrant(doublea,doubleb)
{if(a==0&
b!
(%.2f,%.2f)isontheyaxis.\n"
a,b);
if(a!
=0&
b==0)
(%.2f,%.2f)isonthexaxis.\n"
b>
0)
(%.2f,%.2f)isinquadrantⅠ.\n"
b<
(%.2f,%.2f)isinthequadrantⅣ.\n"
if(a<
(%.2f,%.2f)isinthequadrantⅡ.\n"
(%.2f,%.2f)isinthequadrantⅢ.\n"
7.一年中的某一天问题。
voidorder(intyear,intmonth,intday,inte);
intleap(intyear);
{voidorder(int,int,int,int);
intleap(int);
intyear,month,day,e;
Pleaseenterthedate(yearmonthday).>
%d%d%d"
year,&
month,&
day);
e=leap(year);
order(year,month,day,e);
intleap(intyear)
{inta,b,c,d;
a=year%4;
b=year%100;
c=year%400;
if((a==0&
b==0)||c==0)
{d=1;
{d=0;
return(d);
voidorder(intyear,intmonth,intday,inte)
{intdayth;
if(e==1)
{if(month==1)
{dayth=day;
Thisdayisthe%ddayof%dyear.\n"
dayth,year);
if(month==2)
{dayth=31+day;
if(month==3)
{dayth=31+29+day;
if(month==4)
{dayth=31+29+31+day;
if(month==5)
{dayth=31+29+31+30+day;
if(month==6)
{dayth=31+29+31+30+31+day;
if(month==7)
{dayth=31+29+31+30+31+30+day;
if(month==8)
{dayth=31+29+31+30+31+30+31+day;
if(month==9)
{dayth=31+29+31+30+31+30+31+31+day;
if(month==10)
{dayth=31+29+31+30+31+30+31+31+30+day;
if(month==11)
{dayth=31+29+31+30+31+30+31+31+30+31+day;
if(month==12)
{dayth=31+29+31+30+31+30+31+31+30+31+30+day;
{dayth=31+28+day;
{dayth=31+28+31+day;
{dayth=31+28+31+30+day;
{dayth=31+28+31+30+31+day;
{dayth=31+28+31+30+31+30+day;
{dayth=31+28+31+30+31+30+31+day;
{dayth=31+28+31+30+31+30+31+31+day;
{dayth=31+28+31+30+31+30+31+31+30+day;
{dayth=31+28+31+30+31+30+31+31+30+31+day;
{dayth=31+28+31+30+31+30+31+31+30+31+30+day;
9.居民用电
#defineR_price0.052
#defineC_price0.045
#defineI_price_P0.065
#defineI_price_NP0.028
voidtype_consumption(chartype,doublee_consumption);
voidR_consumption(doublee_consumption);
voidC_consumption(doublee_consumption);
voidI_consumption(doublee_consumption);
{doublee_consumption;
chartype;
ThealphabetRmeansreside,Cmeanscommercial,Imeansindustry.>
Pleaseentertheapplicationtype(R,CorI).>
type);
Pleaseentertheconsumptionofelectricity.>
e_consumption);
type_consumption(type,e_consumption);
return0;
voidtype_consumption(chartype,doublee_consumption)
{
if(type=='
R'
{R_consumption(e_consumption);
elseif(type=='
{C_consumption(e_c