#include"iostream.h" #include"iomanip.h" #include"stdlib.h" leapyear(int a)/*是否是闰年*/ { if((a%4==0&&a%100!=0)||(a%100==0&&a%400==0)) return (1); else return (0); } int aa[12]={31,28,31,30,31,30,31,31,30,31,30,31}; int cc[12]={31,29,31,30,31,30,31,31,30,31,30,31}; char bb[8][8]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"}; ww(int a,int b,int c) { int n=0,m=0,i,j,k=0; for(i=1;i { if(leapyear(i)==1) m=m+366; else m=m+365; } for(j=1;j {if(leapyear(c)==1) k=k+cc[j-1]; else k=k+aa[j-1]; } n=(m+k+a)%7; return n; } void yuefen(int m) { cout<<"最大天数是:"; if(m==2) cout< else cout< } void nianfen(int n)/*打印年份的日历*/ { int i,j,k; if(leapyear(n)==1) { for(j=1;j<=12;j++) { cout< cout<<"月份"< cout<<" 日"<<" 一"<<" 二"<<" 三"<<" 四"<<" 五"<<" 六"< for(i=0;i { cout< } for(k=1;k<=cc[j-1];k++) { cout< if((ww(1,j,n)+k)%7==0) cout< } cout< } } else { for(j=1;j<=12;j++) { cout< cout<<"月份"< cout< cout< for(i=0;i { cout< } for(k=1;k<=aa[j-1];k++) { cout< if((ww(1,j,n)+k)%7==0) cout< } cout< } } } void nianyue(int n,int y)/*打印某年某月的月历*/ { int i,k; if(leapyear(n)==1) { cout<<" 日"<<" 一"<<" 二"<<" 三"<<" 四"<<" 五"<<" 六"< for(i=0;i { cout< } for(k=1;k<=cc[y-1];k++) { cout< if((ww(1,y,n)+k)%7==0) cout< } cout< } else { cout< for(i=0;i { cout< } for(k=1;k<=aa[y-1];k++) { cout< if((ww(1,y,n)+k)%7==0) cout< } cout< } } void main() { int n,m; int day,month ,year; while(1) { cout<<"***********************************:"< cout<<"1查询某年某月某日是星期几"< <<"2是否为闰年"< <<"3查询某月的最大天数"< <<"4打印某年的全年日历"< <<"5打印某年某月的月历"< <<"6exit"< <<"***********************************:"< cout<<"请输入要操作的指令:"< cin>>n; switch(n) { case 1:cout<<"请输入要查询的日期:"; cout<<"year:"; cin>>year; cout< cin>>month; cout< cin>>day; cout<<"星期是:"; cout< switch(ww(day,month,year)) { case 1:cout<<"星期一";break; case 2:cout<<"星期二";break; case 3:cout<<"星期三";break; case 4:cout<<"星期四";break; case 5:cout<<"星期五";break; case 6:cout<<"星期六";break; case 7:cout<<"星期日";break; } cout< case 2:cout<<"请输入要查询的年份:"; cin>>m; if(leapyear(m)==1) cout<<"是闰年"< else cout<<"不是闰年,请返回重新输入"< break; case 3:cout<<"请输入月份:"; cin>>m; yuefen(m);break; case 4:cout<<"请输入所要打印年份:"; cin>>m; nianfen(m);break; case 5:cout<<"请输入年份:"; cin>>n; cout< cin>>m; cout< nianyue(n,m);break; case 6:exit(0); } } }
| | |