//LZ你好花了一整个上午的时间,总算是按你的要求把程序都写好了//原来的程序有点小错误,我都修正了,还有把代码精简了一下,程序在下面//但我在这里要说明一下,按你老师给的算星期的公式,输出的结果是和你照片上的一样,但却和实际不符!//实际的2008年1月1号是星期二,而不是星期日,你可以打开自己的系统时间看一下//我这里的程序输出结果是和你照片上一样的,如果你想改正成和现实一样可以自己改一下date::week(),或者联系我修改也可以/////////////date.h//////////////////////#ifndef_date_h#define_date_h#includeusingnamespacestd;classdate{private:intyear;intmonth;intday;public:date(inty=1,intm=1,intd=1):year(y),month(m),day(d){}voidsetyear(inty){year=y;}voidsetmonth(intm){month=m;}voidsetday(intd){day=d;}intgetyear()const{returnyear;}intgetmonth()const{returnmonth;}intgetday()const{returnday;}dateoperator+(intdays);dateoperator-(intdays);staticboolisleapyear(inty){return(y%4==0&&y%100!=0||y%400==0);}staticintgetyeardays(inty){returnisleapyear(y)?366:365;}staticintgetmonthdays(constdate&d);staticintdatetonum(constdate&d);staticdatenumtodate(intn);staticintweek(constdate&d){return(datetonum(d)+6-1)%7;}};ostream&operator>(istream&in,date&d);#endif/////////////date.cpp//////////////////////#include"date.h"datedate::operator+(intdays){intn=datetonum(*this)+days;returnnumtodate(n);}datedate::operator-(intdays){intn=datetonum(*this)-days;returnnumtodate(n);}intdate::getmonthdays(constdate&d){switch(d.getmonth()){case1:case3:case5:case7:case8:case10:case12:return31;case4:case6:case9:case11:return30;case2:returnisleapyear(d.getyear())?29:28;}}intdate::datetonum(constdate&d){inty,n=0;for(y=1;ygetyeardays(y);y++)rest-=getyeardays(y);for(m=1;rest>getmonthdays(date(y,m,1));m++)rest-=getmonthdays(date(y,m,1));d=rest;returndate(y,m,d);}ostream&operator>(istream&in,date&d){intyear,month,day;cin>>year>>month>>day;d=date(year,month,day);returnin;}/////////////main.cpp//////////////////////#include#include"date.h"inlinevoidprintyear(inty){cout>y;datelz(y);printyear(lz.getyear());for(intm=1;m<=12;++m){lz.setmonth(m);printline();printmonth(m);printweek();printday(lz.getmonthdays(lz),lz.week(lz));printline();}return0;}