万年历C++:
#include<iostream>
#include<stdlib.h>
#include<iomanip>
using namespace std;
int o;
bool prime=true;
bool prime1=true;
bool prime2=true;
struct {
int year;
int month;
int day;
}date;
int main()
{
void zzl_0835_1();
void zzl_0835_2();
void zzl_0835_3();
void zzl_0835_4();
void zzl_0835_0();
system("mode con cols=45 ");
system("color F0");
cout<<" ——————————————\n";
cout<<" * *\n";
cout<<" 欢迎使用本系统 \n";
cout<<" * *\n";
cout<<" ——————————————\n";
cout<<"1.显示某一年的全年日历\n";
cout<<"2.显示某年某月的月历\n";
cout<<"3.显示某年某月某日是星期几\n";
cout<<"4.显示某年某月某日是该年度的第几天\n";
cout<<"0.退出\n";
int z;
cout<<"请选择(0-4)"<<endl;
cin>>z;
switch(z)
{ case 1: zzl_0835_1();system("pause");return 0;break;
case 2: zzl_0835_2();system("pause");return 0;break;
case 3: zzl_0835_3();system("pause");return 0;break;
case 4: zzl_0835_4();system("pause");return 0;break;
case 0: zzl_0835_0();system("pause");return 0;break;
}
system("pause");
return 0;
}
void zzl_0835_4()
{int days;
cout<<"输入年月日"<<endl;
cin>>date.year>>date.month>>date.day;
switch(date.month)
{
case 1:days=date.day; break;
case 2 :days=date.day+31; break;
case 3:days=date.day+59;break;
case 4:days=date.day+90;break;
case 5:days=date.day+120; break;
case 6:days=date.day+151; break;
case 7:days=date.day+181;break;
case 8:days=date.day+212;break;
case 9:days=date.day+243; break;
case 10:days=date.day+273; break;
case 11:days=date.day+304;break;
case 12:days=date.day+334;break;
}
if(((date.year%4==0&&date.year%100!=0)||date.year%400==0)&&date.month>=3)//判断是否为闫年
cout<<date.year<<"年"<<date.month<<"月"<<date.day<<"日是本年度的第"<<days<<"天"<<endl;
}
void zzl_0835_3()
{int xq,d1,xq1;//xq1每个月的一天的星期
if(prime)
{
cout<<"输入年份"<<endl;
cin>>date.year;
cout<<"输入本月份"<<endl;
cin>>date.month;
cout<<"输入日份"<<endl;
cin>>date.day;
}
else if(prime1)
{
cout<<"输入年份"<<endl;
cin>>date.year;
cout<<"输入本月份"<<endl;
cin>>date.month;
date.day=1;
}
else if(prime2)
{
cout<<"输入年份"<<endl;
cin>>date.year;
}
d1=(date.year-1)*365+(date.year-1)/4-(date.year/100)+(date.year/400);
xq=d1%7+1;
switch(date.month)
{
case 1:date.day=date.day;break;
case 2 :date.day=date.day+31;break;
case 3:date.day=date.day+59;break;
case 4:date.day=date.day+90;break;
case 5:date.day=date.day+120;break;
case 6:date.day=date.day+151;break;
case 7:date.day=date.day+181;break;
case 8:date.day=date.day+212;break;
case 9:date.day=date.day+243;break;
case 10:date.day=date.day+273;break;
case 11:date.day=date.day+304;break;
case 12:date.day=date.day+334;break;
}
if(((date.year%4==0&&date.year%100!=0)||date.year%400==0)&&date.month>=3)
date.day+=1;
xq=(xq+(date.day-1))%7;
if(xq==0) xq=7;
if(prime)
switch(xq)
{
case 1:cout<<"该天是星期一"<<endl;break;
case 2:cout<<"该天是星期二"<<endl;break;
case 3:cout<<"该天是星期三"<<endl;break;
case 4:cout<<"该天是星期四"<<endl;break;
case 5:cout<<"该天是星期五"<<endl;break;
case 6:cout<<"该天是星期六"<<endl;break;
case 7:cout<<"该天是星期日"<<endl;break;
}
}
void zzl_0835_2()
{
prime=false;
zzl_0835_3();
int i,s;
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int m=0,b=0;
if((date.year%4==0&&date.year%100!=0)||date.year%400==0) a[2]=29;
cout<<date.year<<"年"<<date.month<<"月"<<endl;
i=date.month;
cout<<"------------------------------------------"<<endl;
cout<<" 日 一 二 三 四 五 六"<<endl;
cout<<"------------------------------------------"<<endl;
if(o==7) o=0;//控制输出空格
for( m=0;m<o;m++) cout<<" ";//控制输出空格
for( b=1;b<=a[i];b++)
{
cout<<setw(6)<<b;
if((b+o)%7==0) cout<<endl;
}//o~每个月的第一天的星期
if(b<33) cout<<endl;
for(m=0;m<o;m++) cout<<" "<<endl;
prime=true;
}
void zzl_0835_1()
{
prime1=false;
for(date.month=1;date.month<=12;date.month++)
{
zzl_0835_2();
prime2=false;
}
}
void zzl_0835_0()
{
cout<<"再 见\n";
}