




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
VisualC++課程設(shè)計(jì)報(bào)告時(shí)間和日期電子工程與光電技術(shù)學(xué)院通訊工程(1)班Xxx0904220xxx2010年4月一、程序功能簡(jiǎn)介:定義了日期類、時(shí)間類和日期時(shí)間綜合類,重載了+,-,++,--,=,>=,<=,==,!=等運(yùn)算符,能夠設(shè)置時(shí)間、日期,比較時(shí)間和日期的大小,進(jìn)行時(shí)間、日期對(duì)象的運(yùn)算,并輸出多種格式的結(jié)果。二、課程設(shè)計(jì)說明:1、原程序日期類中輸出禮拜幾的函數(shù)有誤,不可以輸出禮拜五,現(xiàn)改正以下:int
cDate_t::GetDayOfWeek( )
//starting
point
:
1/1/1900
was
Monday(Saturday==0,Sunday==1,...)//1/1/1900是禮拜一,依據(jù)這個(gè)日期推測(cè)目前日期是禮拜幾{intweekday=2;//in1/1/1900//從1/1/1900開始計(jì)算for(intTheYear=1900;TheYear<Year;++TheYear)//looptoknowthedayin1/1/thisyear{if(IsLeapYear(TheYear))weekday=(weekday+366)%7;elseweekday=(weekday+365)%7;}//untilherewefoundthecorrectdayin1/1/thisyearfor(intTheMonth=1;TheMonth<Month;++TheMonth)//年份計(jì)算完后,計(jì)算月份天數(shù)weekday=(weekday+GetDaysInMonth(TheMonth,Year))%7;//untilherewefoundthecorrectdayin1/thismonthif((weekday+Day)%7==0)return6;elsereturn((weekday+Day)%7-1);//正確顯示禮拜幾//return(weekday+Day)%7-1;(改正前的,沒法正確顯示禮拜五)//thecorrectdayinTHISday...}2、依據(jù)要求在日期類中修他日期對(duì)象減去日期對(duì)象的重載運(yùn)算符-,使得結(jié)果不是另一個(gè)日期,而是天數(shù):intcDate_t::operator-(cDate_t&D)//
重載-運(yùn)算符//{
改正為日期對(duì)象減去日期對(duì)象,結(jié)果不是另一個(gè)日期對(duì)象,而是天數(shù)intTemp1,Temp2,NewDays=0;Temp1=GetDayOfYear(Year,Month,Day);Temp2=D.GetDayOfYear(D.Year,D.Month,D.Day);if(Year==D.Year){NewDays=max(Temp1,Temp2)-min(Temp1,Temp2);}else{for(intTemp3=min(Year,D.Year);Temp3<max(Year,D.Year);Temp3++){NewDays+=((IsLeapYear(Temp3))?366:365);}if(Year>D.Year)NewDays=NewDays+Temp1-Temp2;elseNewDays=-(NewDays+Temp2-Temp1);}returnNewDays;}//------------------------------------/*constcDate_tcDate_t::operator-(constcDate_t&D)//operator-function
(修改前的函數(shù),結(jié)果為另一個(gè)日期對(duì)象){intYearTemp,MonthTemp,DayTemp,NewDays,Temp1,Temp2;//variablestostoretonewdateobjectif(Error||D.Error)//ifnolessthen1objecthaveorrordata{Error4( );//printorrormessegereturn(cDate_t(-1,-1,-1));//returnerrorclass}YearTemp=Year-D.Year;//substractionofTHISandsecondyearif(YearTemp<1900)//error{Error1( );//printerrormessegereturn(cDate_t(-1,-1,-1));//returnerrorclass}Temp1=GetDayOfYear(Year,Month,Day);//getdaysofyearofTHISobjectif(Temp1<0)//error{Error5( );//printerrormessegereturn(cDate_t(-1,-1,-1));//returnerrorclass}Temp2=GetDayOfYear(D.Year,D.Month,D.Day);//getdaysofyearofsecondobjectif(Temp2<0)//error{Error5( );//printerrormessegereturn(cDate_t(-1,-1,-1));//returnerrorclass}NewDays=Temp1-Temp2;//ifthedataokgettheirsubstractionif(NewDays<0)//thesubstractionislessthenzero{NewDays=NewDays+((IsLeapYear(YearTemp))?366:365);//setdaysforpreviousyearYearTemp-=1;//sub1year}DayTemp=RetriveDay(NewDays,YearTemp);//retrivethecurrentspecificmonthMonthTemp=RetriveMonth(NewDays,YearTemp);//samewithmonthreturn(cDate_t(YearTemp,MonthTemp,DayTemp));//returnlocalclass
day
in
the}*/3、依據(jù)要求在時(shí)間類中改正時(shí)間對(duì)象減去時(shí)間對(duì)象的重載運(yùn)算符
-,使得結(jié)果不是另一個(gè)時(shí)間,而是分鐘數(shù):intcTime_t::operator-(cTime_t&T)//
重載-運(yùn)算符(結(jié)果不是另一個(gè)時(shí)間對(duì)象,而是分鐘數(shù)){intnewhour,newminute;newhour=Hours-T.Hours;newminute=Minutes-T.Minutes;returnnewhour*60+newminute;}//------------------------------------/*constcTime_tcTime_t::operator
-(constcTime_t&T)const//operaor
-function//重載-運(yùn)算符//改正前的,結(jié)果為時(shí)間對(duì)象{intHourTemp,MinuteTemp,SecondTemp;//define3tempvariablestogettimedata//定義三個(gè)時(shí)間變量HourTemp=Hours-T.Hours;if(HourTemp<0)//TclasshourwasbiggerthanTHISclass{FlagLessDay=1;//tocut1dayformdateclass//小時(shí)相減為負(fù)數(shù),將少于1天的標(biāo)記置1HourTemp+=24;//add24hourstopreviousday//加24小時(shí)到前一天}MinuteTemp=Minutes-T.Minutes;if(MinuteTemp<0)//sameforminutes//分鐘相減為負(fù){MinuteTemp+=60;--HourTemp;}SecondTemp=Seconds-T.Seconds;if(SecondTemp<0)//sameforseconds//秒數(shù)相減為負(fù){SecondTemp+=60;--MinuteTemp;}return(cTime_t(HourTemp,MinuteTemp,SecondTemp));//returnlocalclass}*/4、改正綜合類cTDmanage的結(jié)構(gòu),從頭定義為日期類和時(shí)間類的派生類,并定義結(jié)構(gòu)函數(shù)、各樣運(yùn)算符重載函數(shù),重載輸入輸出函數(shù):#ifndefTDmanage_h#defineTDmanage_hclasscTDmanage:publiccTime_t,publiccDate_t{public:cTDmanage( ):cTime_t( ),cDate_t( )//結(jié)構(gòu)函數(shù){}cTDmanage(intyear,intmonth,intday,inthour,intminute,intsecond):cDate_t(year,month,day),cTime_t(hour,minute,second){}cTDmanage(inthour,intminute,intsecond):cTime_t(hour,minute,second){}voidoperator=(constcTDmanage&M);//OK//optiontoputallgetandsetfunctionofdateandtimeclassvoidprint( );//operator:booloperator<(constcTDmanage&M)const;booloperator<=(constcTDmanage&M)const;booloperator>(constcTDmanage&M)const;booloperator>=(constcTDmanage&M)const;booloperator==(constcTDmanage&M)const;booloperator!=(constcTDmanage&M)const;constcTDmanageoperator+(constcTDmanage&M);intoperator-(constcTDmanage&M);constcTDmanageoperator+(intMINUTE);constcTDmanageoperator-(intMINUTE);//usingDateandTime++operator:voidoperator++( ){AddDay( );AddSecond( );}voidAddDay( );voidAddSecond( );voidChangeDateFormat( ){cDate_t::ChangeFormat( );}voidChangeTimeFormat( ){cTime_t::ChangeFormat( );}friendostream&operator<<(ostream&out,cTDmanage&M);friendistream&operator>>(istream&in,cTDmanage&M);};#endif//TDmanage.hEnd5、改正main函數(shù)結(jié)構(gòu),采納菜單項(xiàng)選擇項(xiàng)的方式,逐一測(cè)試三個(gè)類中定義的高中函數(shù)和運(yùn)算符:voidmanuselect(cTime_tT,cDate_tD,cTDmanageL){cout<<"\n***********************************
建
議
菜
單***********************************"<<endl;cout<<endl;cout<<"
"<<"1.
時(shí)間類操作
\n"<<""<<"2.日期類操作\n"<<""<<"3.綜合類操作\n"<<""<<"4.intselect1,select2=0,select3=0,select4=0;cout<<"請(qǐng)選擇:\n";cin>>select1;switch(select1){case1:cout<<"\n---------------------------------------------------\n"
退出\n";<<"時(shí)間類操作\n";cout<<"1.時(shí)間加分鐘
\n"<<"2.
時(shí)間減分鐘
\n"<<"3.
時(shí)間減時(shí)間
\n"<<"4.
兩時(shí)間比較\n"<<"5.返回上一層\n";cout<<"請(qǐng)選擇:";cin>>select2;timeselect(select2,T,D,L);break;case2:cout<<"---------------------------------------------------\n"<<"
日期類操作\n";cout<<"1.日期加天數(shù)\n"<<"2.日期減天數(shù)\n"<<"3.日期減日期\n"<<"4.兩日期比較\n"<<"5.返回上一層\n";cout<<"請(qǐng)選擇:";cin>>select3;dateselect(select3,T,D,L);break;case3:cout<<"---------------------------------------------------\n"<<"
綜合類操作\n";cout<<"1.時(shí)間日期加分鐘\n"<<"2.時(shí)間日期減分鐘\n"<<"3.(結(jié)果為分鐘)\n"<<"4.兩時(shí)間日期比較\n"<<"5.返回上一層\n";
時(shí)間日期減時(shí)間日期cout<<"請(qǐng)選擇:";cin>>select4;manageselect(select4,T,D,L);break;case4:break;}}采納的菜單項(xiàng)選擇項(xiàng)以下:1、時(shí)間類操作2、日期類操作3、綜合類操作時(shí)間類操作的子菜單1、時(shí)間加分鐘2、時(shí)間減分鐘3、時(shí)間減時(shí)間4、兩時(shí)間比較日期類操作的子菜單1、日期加天數(shù)2、日期減天數(shù)3、日期減日期4、兩日期比較綜合類操作的子菜單1、日期時(shí)間加分鐘2、日期時(shí)間減分鐘3、日期時(shí)間減去日期時(shí)間(結(jié)果為分鐘)4、日期時(shí)間比較6、程序在各個(gè)類中均重載了
+,-
,++,
--
,=
,>=
,<=,
==
,!=
等運(yùn)算符
,使時(shí)間,日期對(duì)象能夠進(jìn)行運(yùn)算和比較,下以綜合類中各重載函數(shù)為例:constcTDmanagecTDmanage::operator+(constcTDmanage&M)//{
重載+運(yùn)算符intHourTemp,MinuteTemp,SecondTemp;//define3tempvariablestogettimedataSecondTemp=GetSec( )+M.GetSec( );if(SecondTemp>=60)//morethan1minute{SecondTemp-=60;MinuteTemp=GetMin( )+M.GetMin( )+1;//soaddtominute}elseMinuteTemp=GetMin( )+M.GetMin( );if(MinuteTemp>=60)//morethan1hour{MinuteTemp-=60;HourTemp=GetHour( )+M.GetHour( )+1;//addtohour}elseHourTemp=GetHour( )+M.GetHour( );if(HourTemp>=24){FlagMoreDay=1;//toadddaytodateclassHourTemp-=24;}intYearTemp,MonthTemp,DayTemp,NewDays;YearTemp=GetYear( )+M.GetYear( );NewDays=GetDayOfYear(GetYear( ),GetMonth( ),GetDayOfMonth( ))+GetDayOfYear(M.GetYear( ),M.GetMonth( ),M.GetDayOfMonth( ));if(NewDays>((IsLeapYear(YearTemp))?366:365))//ifthesumismorethaninyear{NewDays=NewDays-((IsLeapYear(YearTemp))?366:365);//cut1yeardaysYearTemp+=1;//andaddayear}MonthTemp=RetriveMonth(NewDays,YearTemp);//samewithmonthDayTemp=RetriveDay(NewDays,YearTemp);//retrivethecurrentdayinthespecificmonthDayTemp+=(cTime_t::FlagMoreDay);DayTemp=RetriveDay(NewDays,YearTemp);//retrivethecurrentdayinthespecificmonthreturncTDmanage(YearTemp,MonthTemp,DayTemp,HourTemp,MinuteTemp,SecondTemp);}intcTDmanage::operator-(constcTDmanage&M)//重載-運(yùn)算符(比較兩個(gè)綜合類時(shí)間對(duì)象,結(jié)果獲得相差的分鐘數(shù)){intNewDays,Temp1,Temp2;Temp1=GetDayOfYear(GetYear( ),GetMonth( ),GetDayOfMonth( ));Temp2=GetDayOfYear(M.GetYear( ),M.GetMonth( ),M.GetDayOfMonth( ));if(GetYear( )==M.GetYear( )){NewDays=max(Temp1,Temp2)-min(Temp1,Temp2);}else{for(intTemp3=min(GetYear( ),M.GetYear( ));Temp3<max(GetYear( ),M.GetYear( ));Temp3++){NewDays+=((IsLeapYear(Temp3))?366:365);}if(GetYear( )>M.GetYear( ))NewDays=NewDays+Temp1-Temp2;elseNewDays=-(NewDays+Temp2-Temp1);}intnewhour,newminute;newhour=GetHour( )-M.GetHour( );newminute=GetMin( )-M.GetMin( );newminute=newminute+60*newhour+24*60*NewDays;returnnewminute;}voidcTDmanage::operator=(constcTDmanage&M)//重載運(yùn)算符={SetSec(M.GetSec( ));SetMin(M.GetMin( ));SetHour(M.GetHour( ));SetDay(M.GetDayOfMonth( ));SetMon(M.GetMonth( ));SetYear(M.GetYear( ));}boolcTDmanage::operator<
(constcTDmanage&M)const//
重載<運(yùn)算符{if(Year<M.GetYear( ))if(Year==M.GetYear( )){
returntrue;if(GetMonth( )<M.GetMonth( ))returntrue;if(GetMonth( )==M.GetMonth( )){if(GetDayOfMonth( )<M.GetDayOfMonth( ))returntrue;if(GetDayOfMonth( )==M.GetDayOfMonth( )){if(GetHour( )<M.GetHour( ))if(GetHour( )==M.GetHour( )){
returntrue;if(GetMin( )<M.GetMin( ))returntrue;if(GetMin( )==M.GetMin( )){return(GetSec( )<M.GetSec( ));}returnfalse;}returnfalse;}returnfalse;}returnfalse;}returnfalse;}boolcTDmanage::operator<=(constcTDmanage&M)const//重載<=運(yùn)算符{if(Year<M.GetYear( ))if(Year==M.GetYear( )){
returntrue;if(GetMonth( )<M.GetMonth( ))returntrue;if(GetMonth( )==M.GetMonth( )){if(GetDayOfMonth( )<M.GetDayOfMonth( ))returntrue;if(GetDayOfMonth( )==M.GetDayOfMonth( )){if(GetHour( )<M.GetHour( ))if(GetHour( )==M.GetHour( )){
returntrue;if(GetMin( )<M.GetMin( ))returntrue;if(GetMin( )==M.GetMin( )){return(GetSec( )<=M.GetSec( ));}returnfalse;}returnfalse;}returnfalse;}returnfalse;}returnfalse;}boolcTDmanage::operator>
(constcTDmanage&M)const//
重載>運(yùn)算符{if(Year>M.GetYear( ))if(Year==M.GetYear( )){
returntrue;if(GetMonth( )>M.GetMonth( ))returntrue;if(GetMonth( )==M.GetMonth( )){if(GetDayOfMonth( )>M.GetDayOfMonth( ))returntrue;if(GetDayOfMonth( )==M.GetDayOfMonth( )){if(GetHour( )>M.GetHour( ))if(GetHour( )==M.GetHour( )){
returntrue;if(GetMin( )>M.GetMin( ))returntrue;if(GetMin( )==M.GetMin( )){return(GetSec( )>M.GetSec( ));}returnfalse;}returnfalse;}returnfalse;}returnfalse;}returnfalse;}boolcTDmanage::operator>=(constcTDmanage&M)const//重載>=運(yùn)算符{if(Year>M.GetYear( ))if(Year==M.GetYear( )){
returntrue;if(GetMonth( )>M.GetMonth( ))returntrue;if(GetMonth( )==M.GetMonth( )){if(GetDayOfMonth( )>M.GetDayOfMonth( ))returntrue;if(GetDayOfMonth( )==M.GetDayOfMonth( )){if(GetHour( )>M.GetHour( ))if(GetHour( )==M.GetHour( )){
returntrue;if(GetMin( )>M.GetMin( ))returntrue;if(GetMin( )==M.GetMin( )){return(GetSec( )>=M.GetSec( ));}returnfalse;}returnfalse;}returnfalse;}returnfalse;}returnfalse;}boolcTDmanage::operator==(constcTDmanage&M)const//
重載==運(yùn)算符{return((GetSec( )==M.GetSec( ))&&(GetMin( )==M.GetMin( ))&&(GetHour( )==M.GetHour( ))&&(GetDayOfMonth( )==M.GetDayOfMonth( ))&&(GetMonth( )==M.GetMonth( ))&&(GetYear( )==M.GetYear( )));}boolcTDmanage::operator!=(constcTDmanage&M)const{return((GetSec( )==M.GetSec( ))||(GetMin( )==M.GetHour( ))||(GetDayOfMonth( )==M.GetDayOfMonth( ))||(GetMonth( )==M.GetYear( )));}constcTDmanagecTDmanage::operator+(intMINUTE)
( )==M.GetMin( ))||(GetHour( )==M.GetMonth( ))||(GetYear//綜合類和分鐘加運(yùn)算符的重載{intHourTemp,MinuteTemp,SecondTemp;SecondTemp=GetSec( );HourTemp=GetHour( );MinuteTemp=GetMin( )+MINUTE;while(MinuteTemp>=60){MinuteTemp-=60;HourTemp+=1;}while(HourTemp>=24){HourTemp-=24;FlagMoreDay+=1;}intYearTemp,DayTemp,MonthTemp,NewDays;YearTemp=GetYear( );MonthTemp=GetMonth( );NewDays=GetDayOfYear(GetYear( ),GetMonth( ),GetDayOfMonth( ))+FlagMoreDay;while(NewDays>((IsLeapYear(YearTemp))?366:365)){NewDays=NewDays-((IsLeapYear(YearTemp))?366:365);YearTemp+=1;}DayTemp=RetriveDay(NewDays,YearTemp);MonthTemp=RetriveMonth(NewDays,YearTemp);FlagMoreDay=0;returncTDmanage(YearTemp,MonthTemp,DayTemp,HourTemp,MinuteTemp,SecondTemp);}constcTDmanagecTDmanage::operator-(intMINUTE)
//綜合類和分鐘減運(yùn)算符的重載{intHourTemp,MinuteTemp,SecondTemp;SecondTemp=GetSec( );HourTemp=GetHour( );MinuteTemp=GetMin( )-MINUTE;while(MinuteTemp<0){MinuteTemp+=60;HourTemp-=1;while(HourTemp<0){HourTemp+=24;FlagLessDay+=1;}}intYearTemp,DayTemp,MonthTemp,NewDays;intTemp=GetDayOfYear(GetYear( ),GetMonth( ),GetDayOfMonth( ));YearTemp=GetYear( );NewDays=Temp-FlagLessDay;while(NewDays<0){NewDays=NewDays+((IsLeapYear(YearTemp))?366:365);}DayTemp=RetriveDay(NewDays,YearTemp)+1;MonthTemp=RetriveMonth(NewDays,YearTemp);FlagLessDay=0;returncTDmanage(YearTemp,MonthTemp,DayTemp,HourTemp,MinuteTemp,SecondTemp);}voidcTDmanage::AddDay( ){if((GetDayOfMonth( )==GetDaysInMonth(GetMonth( ),GetYear( )))&&(GetMonth( )==12))ifreachedtheendoftheyear{SetDay(1);SetMon(1);SetYear(GetYear( )+1);}elseif((GetDayOfMonth( )==GetDaysInMonth(GetMonth( ),GetYear( ))))ifreachedtheendofthemonth(butnotyear){SetDay(1);SetMon(GetMonth( )+1);}elseSetDay(GetDayOfMonth( )+1);//add1day}voidcTDmanage::AddSecond( ){if((GetSec( )==59)&&(GetMin( )==59)&&(GetHour( )==23))//endofaday{FlagMoreDay=1;//toadddaytodayclassSetSec(0);SetMin(0);SetHour(0);}elseif((GetSec( )==59)&&(GetMin( )==59))//endofhour{SetSec(0);SetMin(0);SetHour(GetHour( )+1);}elseif(GetSec( )==59)//endofminute{SetSec(0);SetMin(GetMin( )+1);}elseSetSec(GetSec( )+1);}三、課程設(shè)計(jì)中碰到的困難及心得:這個(gè)課題的程序比較長(zhǎng),需要好多的時(shí)間,這關(guān)于平常學(xué)業(yè)較沉重,社團(tuán)活動(dòng)也許多的我來說,更合理的安排時(shí)間,更有效利用本就有限的課余時(shí)間,成了個(gè)不小的挑戰(zhàn)。于是,把程序分紅好多塊,零落的思慮研究,就成為我常用的方式。在這個(gè)過程中,我發(fā)現(xiàn),程序中有許多同樣結(jié)構(gòu)的內(nèi)容,而各運(yùn)算符重載函數(shù)也存有好多相像之處,加上原程序中類中的成員函數(shù)的功能很全面,這些都讓我省下許多時(shí)間和精力。經(jīng)過c++課程設(shè)計(jì)這個(gè)比較漫長(zhǎng)的過程,我不錯(cuò)的掌握了運(yùn)算符的重載,學(xué)習(xí)了輸入輸出流函數(shù)的重載,同時(shí)對(duì)類間函數(shù)調(diào)用的關(guān)系以及怎樣實(shí)現(xiàn)類間復(fù)雜的有關(guān)調(diào)用也有了更深的理解。經(jīng)過閱讀本課題的程序,我掌握了一些閱讀程序的技巧,養(yǎng)成了仔細(xì)閱讀程序的好習(xí)慣,并能從較長(zhǎng)的程序中找到程序的核心實(shí)現(xiàn)部分。在不停思慮和調(diào)試的過程中,我的意志也獲得必定的磨煉,并且在時(shí)間的合理安排和有效利用方面也有的很大的提升。四、重點(diǎn)原代碼說明:cDate_t( );//缺省結(jié)構(gòu)函數(shù),初始化為目前時(shí)間cDate_t(constcDate_t&D);//拷貝的結(jié)構(gòu)函數(shù)cDate_t(intyear,intmonth,intday);//結(jié)構(gòu)函數(shù)~cDate_t( ){}//析構(gòu)函數(shù)constcDate_t&operator=(constcDate_t&D);//重載=運(yùn)算符inlinevoidSetDay(intday){Day=day;}//設(shè)置日期inlinevoidSetMon(intmon){Month=mon;}//設(shè)置月份inlinevoidSetYear(intyear){Year=year;}//設(shè)置年份voidprint( );voidprint1( );inlineintGetDayOfMonth( )const{returnDay;}//返回月份中的日期inlineintGetMonth( )const{returnMonth;}//返回月份inlineintGetYear( )const{returnYear;}//返回年份intGetDayOfYear(intyear,intmonth,intday);//返回從元旦到所給日期的總天數(shù)intGetDaysInMonth(intmonth,intyear);//返回所給日期那月的總天數(shù)intGetDayOfWeek( );//返回禮拜boolIsLeapYear(intyear);//判斷能否閏年char*GetDayOfWeekName( );//返回禮拜的英文char*GetNameOfMonth( );//返回月份的英文intRetriveDay(intDays,intyear);//將距year年元旦的總天數(shù)變換為詳細(xì)月份中的天數(shù)intRetriveMonth(intDays,intyear);//將距year年元旦的總天數(shù)變換為詳細(xì)月份booloperator<(constcDate_t&D)const;//重載<運(yùn)算符booloperator<=(constcDate_t&D)const;//重載<=運(yùn)算符booloperator>(constcDate_t&D)const;//重載>運(yùn)算符booloperator>=(constcDate_t&D)const;//重載>=運(yùn)算符booloperator==(constcDate_t&D)const;//重載==運(yùn)算符booloperator!=(constcDate_t&D)const;//重載!=運(yùn)算符constcDate_toperator+(constcDate_t&D);//重載+運(yùn)算符intoperator-(cDate_t&D);//重載-運(yùn)算符(結(jié)果不是另一個(gè)日期對(duì)象,而是天數(shù))constcDate_toperator+(intDays);//重載+運(yùn)算符(一個(gè)日期對(duì)象加上天數(shù)獲得一個(gè)新的日期)constcDate_toperator-(intDays);//重載-運(yùn)算符(一個(gè)日期對(duì)象減去天數(shù)獲得一個(gè)新的日期)intgetformat2( ){returnformat;}//返回格式voidoperator++( );//重載++運(yùn)算符voidoperator--( );//重載--運(yùn)算符staticvoidcDate_t::ChangeFormat( )//implementationofstaticfunctionmustbeinheader//設(shè)置日期格式{switch(format){case1:format=2;break;case2:format=3;break;case3:format=1;}}friendostream&operator<<(ostream&out,constcDate_t&D);//重載輸出流friendistream&operator>>(istream&in,cDate_t&D);//重載輸入流voidSetError( ){Error=false;}//設(shè)置犯錯(cuò)標(biāo)記friendclasscTDmanage;//說明綜合類是日期類的友元類staticintFlagMoreDay;//時(shí)間能否超出一天標(biāo)記staticintFlagLessDay;//時(shí)間能否不到一天標(biāo)記staticintformat;//格式cTime_t(constcTime_t&T);//拷貝結(jié)構(gòu)函數(shù)cTime_t(inthour,intmin=0,intsec=0):Seconds(sec),Minutes(min),Hours(hour){};~cTime_t( ){};//析構(gòu)函數(shù)constcTime_t&operator=(constcTime_t&T);//重載=運(yùn)算符inlinevoidSetSec(intsec){Seconds=sec;}//設(shè)置秒數(shù)(內(nèi)聯(lián)函數(shù))inlinevoidSetMin(intmin){Minutes=min;}//設(shè)置分?jǐn)?shù)inlinevoidSetHour(inthour){Hours=hour;}//設(shè)置小時(shí)數(shù)voidprint( )const;//輸出voidprint1( )const;//輸出inlineintGetSec( )const{returnSeconds;}//返回秒數(shù)inlineintGetMin( )const{returnMinutes;}//返回分鐘inlineintGetHour( )const{returnHours;}//返回小時(shí)intgetFlagMoreDay( ){returnFlagMoreDay;}//返回時(shí)間能否超出一天intgetFlagLessDay( ){returnFlagLessDay;}//返回時(shí)間能否不到一天voidresetFlagMoreDay( ){FlagMoreDay=0;}//重設(shè)時(shí)間能否超出一天voidresetFlagLessDay( ){FlagLessDay=0;}//重設(shè)時(shí)間能否不到一天booloperator<(constcTime_t&T)const;//重載<運(yùn)算符booloperator<=(constcTime_t&T)const;//重載<=運(yùn)算符booloperator>(constcTime_t&T)const;//重載>運(yùn)算符booloperator>=(constcTime_t&T)const;//重載>=運(yùn)算符booloperator==(constcTime_t&T)const;//重載==運(yùn)算符booloperator!=(constcTime_t&T)const;//重載!=運(yùn)算符constcTime_toperator+(constcTime_t&T)const;//重載+運(yùn)算符intoperator-(cTime_t&T);//重載-運(yùn)算符(結(jié)果不是另一個(gè)時(shí)間對(duì)象,而是分鐘數(shù))constcTime_toperator+(intNewMinutes);//重載+運(yùn)算符(一個(gè)時(shí)間對(duì)象加上分鐘獲得一個(gè)新的時(shí)間)constcTime_toperator-(intNewMinutes);//重載-運(yùn)算符(一個(gè)時(shí)間對(duì)象減去分鐘獲得一個(gè)新的時(shí)間)intgetformat1( ){returnformat;}//返回格式voidoperator++( );//重載++運(yùn)算符voidoperator--( );//重載--運(yùn)算符staticvoidChangeFormat( ){format=(format==1)?2:1;}//formatcanbeonly1or2//改變時(shí)間格式friendostream&operator<<(ostream&out,constcTime_t&T);//重載輸出流friendistream&operator>>(istream&in,cTime_t&T);//重載輸入流friendclasscTDmanage;//說明綜合類是時(shí)間類的友元類voidcTime_t::print( )const//printfunction//輸出{switch(format){case1://小時(shí)數(shù)為0--23(24)的格式if(Seconds<10&&Minutes<10)cout<<"Thetimeis:"<<Hours<
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 信息系統(tǒng)監(jiān)理師2025年考前沖刺試題及答案
- 稀土金屬加工質(zhì)量改進(jìn)項(xiàng)目策劃與實(shí)施技巧考核試卷
- 微生物肥料在促進(jìn)作物對(duì)養(yǎng)分脅迫適應(yīng)性的生理響應(yīng)研究考核試卷
- 釀造企業(yè)產(chǎn)品創(chuàng)新考核試卷
- 管理學(xué)與行政結(jié)合試題及答案
- 嵌入式系統(tǒng)開發(fā)的商業(yè)機(jī)遇試題及答案
- 行政組織的變革策略探討試題及答案
- 全面關(guān)注公路工程考試的發(fā)展趨勢(shì)試題及答案
- 信息系統(tǒng)監(jiān)理師高級(jí)課程介紹試題及答案
- 嵌入式系統(tǒng)高效遠(yuǎn)程控制試題及答案
- 心理健康專題課件25心理健康
- 口腔癌護(hù)理個(gè)案
- 【生物】魚課件+2024-2025學(xué)年人教版生物七年級(jí)上冊(cè)
- 文化行業(yè)標(biāo)準(zhǔn) WH-T 92-2021 臨時(shí)搭建演出場(chǎng)所舞臺(tái)、看臺(tái)安全監(jiān)督檢驗(yàn)規(guī)范
- 慢性乙型肝炎防治指南(2022年版)
- NB-T+31010-2019陸上風(fēng)電場(chǎng)工程概算定額
- DZ∕T 0450-2023 地質(zhì)災(zāi)害監(jiān)測(cè)數(shù)據(jù)通信技術(shù)要求(正式版)
- 湖南省長(zhǎng)沙市雨花區(qū)2023-2024學(xué)年六年級(jí)下學(xué)期期末考試英語試題
- 2024年全國(guó)甲卷理綜化學(xué)高考真題(答案版)
- 2024年甘肅省天水市中考生物·地理試題卷(含答案)
- DZ∕T 0340-2020 礦產(chǎn)勘查礦石加工選冶技術(shù)性能試驗(yàn)研究程度要求(正式版)
評(píng)論
0/150
提交評(píng)論