欢迎来到天天文库
浏览记录
ID:61445984
大小:27.00 KB
页数:17页
时间:2021-01-31
《电子时钟C代码.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、#include#include#includeclassCDateTime{private:intyear;intmonth;intdays;inthour;intminute;intsecond;intwday;//星期private:intYearToDays(inty);intDatesToDays();intMonthToWeek();intYearMonthToDay(inty,intm);public:CDateTime(inty=0,intm=0,
2、intd=0,inth=0,intmt=0,ints=0){year=y;month=m;days=d;hour=h;minute=mt;second=s;wday=DatesToWeek();}~CDateTime(){}voidNow();intDatesToWeek();CDateTimeLastMonth();CDateTimeNextMonth();voidLastTime();voidInputYearMonth();voidPrintMonth();voidInputDates();intWeek(){retu
3、rnwday;}CDateTimeoperator+(constint&n);CDateTimeoperator-(constint&n);intoperator-(CDateTime&dt);friendostream&operator<<(ostream&out,constCDateTime&c);};voidCDateTime::Now(){time_tte;tm*tp;time(&te);tp=localtime(&te);year=tp->tm_year+1900;month=tp->tm_mon+1;days=t
4、p->tm_mday;hour=tp->tm_hour;minute=tp->tm_min;second=tp->tm_sec;wday=tp->tm_wday;}CDateTimeCDateTime::operator-(constint&n){intm=n;intmday;CDateTimedt(*this);mday=YearMonthToDay(dt.year,dt.month);while(dt.days+m>mday){dt.month--;if(dt.month>1){dt.year-=1;dt.month=1
5、2;}m-=mday;mday=YearMonthToDay(dt.year,dt.month);}dt.days+=m;returndt;}CDateTimeCDateTime::operator+(constint&n){intm=n;intmday;CDateTimedt(*this);mday=YearMonthToDay(dt.year,dt.month);while(dt.days+m>mday){dt.month++;if(dt.month>12){dt.year+=1;dt.month=1;}m-=mday;
6、mday=YearMonthToDay(dt.year,dt.month);}dt.days+=m;returndt;}intCDateTime::operator-(CDateTime&dt){inty=dt.year;intm=dt.month;intt1=dt.DatesToDays();intt2=DatesToDays();return(t2-t1);}intCDateTime::YearToDays(inty){intd=0;inti=(y-1900)*365;while(y>1900){if((y-1)%4==
7、0&&(y-1)%100!=0
8、
9、(y-1)%400==0)++d;--y;}return(d+i);}intCDateTime::YearMonthToDay(inty,intm){intmday=0;switch(m){case1:case3:case5:case7:case8:case10:case12:mday=31;break;case2:if(y%4==0&&y%100!=0
10、
11、y%400==0)mday=29;elsemday=28;break;case4:case6:case9:case11:mday=30;
12、break;default:mday=0;}returnmday;}intCDateTime::DatesToDays(){inttotal=0;while(month>1){total+=YearMonthToDay(year,month-1);--month;}intnum=YearT
此文档下载收益归作者所有