资源描述:
《面向对象a面向对象习题(南航皮德常)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、第8章习题:8-1、设计Date类,输出合法日期。#includeusingnamespacestd;//类定义//classDate{intyear;//存储日期的年份intmonth;//存储日期的月份intday;//存储日期的天数public:boolsetDate(constint,constint,constint);voiddisplay(void);char*getMonth(constint);};//类的实现////设置成员变量////mm:月份,dd:天数,yy:年份////返回值:如果成功赋值则返回true
2、,否则返回false。//char*Date::getMonth(constintm){if(m==1)return"January";elseif(m==2)return"February";elseif(m==3)return"March";elseif(m==4)return"April";elseif(m==5)return"May";elseif(m==6)return"June";elseif(m==7)return"July";elseif(m==8)return"August";elseif(m==9)otherstaffoftheC
3、entre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofSta
4、teenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersandreturn"September";elseif(m==10)return"October";elseif(m==11)return"November";elsereturn"December";}//设置成员变量////参数:mm:月份,dd:天数,yy:年
5、份////返回值:如果成功赋值则返回true,否则返回false//boolDate::setDate(constintmm,constintdd,constintyy){if(mm<1
6、
7、mm>12)returnfalse;if(dd<1
8、
9、dd>31)returnfalse;year=yy;month=mm;day=dd;returntrue;}//在屏幕上显示日期//voidDate::display(void){//按照"12-25-2004"的形式输出日期cout<10、"December25,2004"的形式输出日期cout<>year;othersta
11、ffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederat
12、ionofStateenterprisesMinister,ShenmufuguSARmissions,Di