此万年历有三点功能
1.显示某一年的日历
2.显示某年中某个月的日历
3.显示某年某月某天是星期几
下面贴上蒟蒻的代码
#include <iostream> #include <iomanip> using namespace std; int key,year,month,day,xingqi,num[15]={0,31,28,31,30,31,30,31,31,30,31,30,31,31,28},temp=1,k1,k2; int three() { if(month==1) { k1=1; year--; month=13; } else if(month==2) { k2=1; year--; month=14; } int W=(day+2*month+3*(month+1)/5+year+year/4-year/100+year/400+1)%7; if(k1==1) { year++; month=1; } else if(k2==1) { year++; month=2; } if(W==0) return 0; else if(W==1) return 1; else if(W==2) return 2; else if(W==3) return 3; else if(W==4) return 4; else if(W==5) return 5; else if(W==6) return 6; } int two() { cout<<setw(6)<<"日"<<setw(6)<<"一"<<setw(6)<<"二"<<setw(6)<<"三"<<setw(6)<<"四"<<setw(6)<<"五"<<setw(6)<<"六"<<endl; if(temp) { cout<<setw(14)<<year<<"."<<1<<"."<<1; if(xingqi==0) cout<<"星期日"<<endl; else if(xingqi==1) cout<<"星期一"<<endl; else if(xingqi==2) cout<<"星期二"<<endl; else if(xingqi==3) cout<<"星期三"<<endl; else if(xingqi==4) cout<<"星期四"<<endl; else if(xingqi==5) cout<<"星期五"<<endl; else if(xingqi==6) cout<<"星期六"<<endl; cout<<"--------------------------------------------"<<endl; } if((year%4==0&&year%100==0)||(year%400==0)) { num[2]=29; num[14]=29; } int t; if(three()==0) t=0; else if(three()==1) t=1; else if(three()==2) t=2; else if(three()==3) t=3; else if(three()==4) t=4; else if(three()==5) t=5; else if(three()==6) t=6; int x=0; while(x<t) { cout<<setw(6)<<" ";; x++; } for(int i=1;i<=num[month];i++) { cout<<setw(6)<<i; t++; if(t==7) { cout<<endl; t=0; } } cout<<endl; if(temp) cout<<"--------------------------------------------"<<endl; return 0; } int main() { ios::sync_with_stdio(false); cout<<" ___________________________________"<<endl; cout<<" * 制作人:Why *"<<endl; cout<<" 欢迎进入万年历查询系统: "<<endl; cout<<" * *"<<endl; cout<<" ___________________________________"<<endl; cout<<endl; cout<<endl; cout<<"请选择您的查询内容:"<<endl; cout<<endl; cout<<" 1.显示一年的日历:"<<endl; cout<<" 2.显示一月的日历:"<<endl; cout<<" 3.显示某一天是星期几:"<<endl; cout<<" 0.退出:"<<endl; cout<<"请选择按键(0-3):"<<endl; cin>>key; if(key==0) return 0; else if(key==3) { cout<<"输入年份:"; cin>>year; cout<<endl; cout<<"输入月份(1-12):"; cin>>month; cout<<endl; cout<<"输入此年此月相应的日期(1-28:29:30:31):"; cin>>day; cout<<endl; cout<<"该天是:"; if(three()==0) cout<<"星期日"<<endl; else if(three()==1) cout<<"星期一"<<endl; else if(three()==2) cout<<"星期二"<<endl; else if(three()==3) cout<<"星期三"<<endl; else if(three()==4) cout<<"星期四"<<endl; else if(three()==5) cout<<"星期五"<<endl; else if(three()==6) cout<<"星期六"<<endl; } else if(key==2) { cout<<"输入年份以及此年的元旦是星期几用(0-6)表示:"; cin>>year>>xingqi; cout<<endl; cout<<"输入此年月份(1-12):"; cin>>month; day=1; two(); } else if(key==1) { temp=0; cout<<"输入年份:"; cin>>year; cout<<endl; for(int i=1;i<=12;i++) { k1=0; k2=0; cout<<i<<"月的年历如下:"<<endl; month=i; day=1; two(); } } return 0; }