万年历查询程序 功能要求: (1)提供菜单方式选择 (2)输入年份、月份、日期,计算得到的是这一天 万年历程序查询 要求:提供菜单方式选择 输入年份,月份,日期...

作者&投稿:鱼逃 (若有异议请与网页底部的电邮联系)
计算得到的这一天是星期几吗?? 还是?/* welcome to use the WanNianLi system! */
#include<stdio.h>
#include<stdlib.h>
char* month_str[]={"January","February","March","April","May","June","July","August","September","October","November","December"};
char* week[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

int leap (int year)//判断闰年
{
if(year%4==0&&year%100!=0||year%400==0)
return 1;
else return 0;
}
int month_day(int year,int month) //判断这一个月有多少天
{
int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31}; //初始化每个月的天数
if(leap(year)&&month==2 )
return 29;
else
return(mon_day[month-1]);

}
int firstday(int year,int month,int day)//判断这一个月的第一天是星期几
{
int c=0;
float s;
int m;
for(m=1;m<month;m++)
c=c+month_day(year,m);
c=c+day;
s=year-1+(float)(year-1)/4+(float)(year-1)/100+(float)(year-1)/400-40+c;
return ((int)s%7);
}
int PrintAllYear(int year)/*print the all year*/
{
int a,b;
int i,j=1,n=1,k;
for(k=1;k<=12;k++)
{
j=1,n=1;
b=month_day(year,k);
a=firstday(year,k,1);
printf("\n\n%s(%d)\n",month_str[k-1],k);
printf(" Sun Mon Tue Wed Thu Fri Sat \n**************");
if(a==7)
{
for(i=1;i<=b;i++)
{
printf("%4d",i);
if(i%7==0)
{
printf("**************\n**************");
}
}
}
if(a!=7)
{
while (j<=4*a)
{
printf(" ");
j++;
}
for(i=1;i<=b;i++)
{
printf("%4d",i);
if(i==7*n-a)
{
printf("**************\n**************");
n++;
}
}
}
printf("**************\n");
}
return 1;
}
int main()
{
int option,da;
char ch;
int year,month,day;
while(1)
{
printf("\n请选择你所需要的服务:\n");
printf("\n输入1求某个日期对应的星期");
printf("\n输入2结束程序\n");
scanf("%d",&option);
switch(option)
{
case 1:
while(1)
{
printf("\nPlease input the year,month and day(XXXX,XX,XX):");
scanf("%d,%d,%d,%c",&year,&month,&day);
da=firstday(year,month,day);
printf("\n%d-%d-%d is %s,do you want to continue?(Y/N)",year,month,day,week[da]);
fflush(stdin);
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
}
break;
case 2:
fflush(stdin);
printf("Are you sure?(Y/N)");
scanf("%c",&ch);
if(ch=='Y'||ch=='y')
exit(0);
break;
default:
printf("\nError:Sorry,there is no this service now!\n");
break;
}
}
return 0;
}

万年历查询程序。 功能要求: (1)提供菜单方式选择 (2)输入年份、月份、日期,计算得到的是这一天据今~

#include <windows.h>
#include <winnt.h>
#include<iostream>
#include<iomanip>
using namespace std;
int week(int,int,int); //根据年月日判断星期几
int leap_year(int); //判断闰年
void display_year(int ); //显示某年日历
void demand_day(int,int,int); //查询某天
int main()
{
int y,m,d,es=1;
while(es)
{
HANDLE consolehwnd;
consolehwnd = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(consolehwnd,12);
cout<<"请选择操作:
1→显示某年日历\

2→查询某天
0→退出"<<endl;
char tp[20];cin>>tp;
if(tp[1]!='\0'||tp[0]>'2'||tp[0]<'0')
switch(tp[0]-48)
{
case 1:
case 2:{cout<<"请输入年、月、日,以空格分开:";cin>>y>>m>>d;system("cls");
demand_day(y,m,d);break;}
case 0:
}
}
return 0;
}
//-----根据年月日判断星期几-------------------------
int week(int y,int m, int d)
{
int week1,yy=y;
if(m==1)
if(m==2)
week1=(d+2*m+3*(m+1)/5+yy+yy/4-yy/100+yy/400)%7;
int s;
switch (week1)
{
case 0: s=1; break;
case 1: s=2; break;
case 2: s=3; break;
case 3: s=4; break;
case 4: s=5; break;
case 5: s=6; break;
case 6: s=0; break;
}
return s;
}
//----判断闰年-------------------------------------
int leap_year(int y)
{
int i;
if((y%4==0&&y%100!=0)||y%400==0)i=1;
else i=0;
return i;
}
//--------显示某年日历------------------------
void display_year(int y)
{
int n1,n2,i,j,a[13],c,d;
HANDLE consolehwnd;
consolehwnd = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(consolehwnd,5);
cout<<setw(38)<<y<<"年"<<endl;
cout<<setw(28)<<"*********";
for(i=1;i<=27;i++)cout<<'*';
cout<<endl;
a[1]=a[3]=a[5]=a[7]=a[8]=a[10]=a[12]=31;//
a[4]=a[6]=a[9]=a[11]=30; //确定每月天数
if(leap_year(y))a[2]=29;
else a[2]=28; //
for(i=1;i<=11;i+=2) //六次循环
{
SetConsoleTextAttribute(consolehwnd,1);
cout<<setw(14)<<i<<"月"<<setw(42)<<i+1<<"月"<<endl;
SetConsoleTextAttribute(consolehwnd,2);
cout<<setw(4)<<"日"<<setw(4)<<"一"<<setw(4)<<"二"<<setw(4)<<"三"<<setw(4)\
<<"四"<<setw(4)<<"五"<<setw(4)<<"六";
cout<<setw(16)<<' ';
cout<<setw(4)<<"日"<<setw(4)<<"一"<<setw(4)<<"二"<<setw(4)<<"三"<<setw(4)\
<<"四"<<setw(4)<<"五"<<setw(4)<<"六"<<endl;
SetConsoleTextAttribute(consolehwnd,7);
n1=week(y,i,1);n2=week(y,i+1,1);
if(n1) //-----------
{
for(j=1;j<=n1;j++) //
cout<<setw(4)<<' ';
}
for(j=1;j<=7-n1;j++)
cout<<setw(4)<<j;
cout<<setw(16)<<' ';
if(n2)
{ //-----输出每次循环的第一行---
for(j=1;j<=n2;j++)
cout<<setw(4)<<' ';
}
for(j=1;j<=7-n2;j++)
cout<<setw(4)<<j;
cout<<endl; //--------------
c=8-n1;d=8-n2;
for(int m=1;m<6;m++) //每月日历最多占六行
{
if(c>a[i])cout<<setw(4*7)<<' ';//若c>a[i],则该月的这一行全部输出空格
for(j=c;j<=a[i];j++)
{
cout<<setw(4)<<j;
if((j-c+1)%7==0)
if(j==a[i])
//如果j是该月最后一天,该行剩下的全部补空格
}
cout<<setw(16)<<' ';
if(d>a[i+1])cout<<setw(4*7)<<' ';
for(j=d;j<=a[i+1];j++)
{ //
cout<<setw(4)<<j;
if((j-d+1)%7==0)
if(j==a[i+1])
}
cout<<endl;
}
cout<<endl;
}
cout<<endl;
}
//--------查询某天------------
void demand_day(int y,int m,int d)
{
int n;
HANDLE consolehwnd;
consolehwnd = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(consolehwnd,5);
n=week(y,m,d);
switch(n)
{
case 1:cout<<y<<"年"<<m<<"月"<<d<<"日"<<","<<"星期一"<<endl;break;
case 2:cout<<y<<"年"<<m<<"月"<<d<<"日"<<","<<"星期二"<<endl;break;
case 3:cout<<y<<"年"<<m<<"月"<<d<<"日"<<","<<"星期三"<<endl;break;
case 4:cout<<y<<"年"<<m<<"月"<<d<<"日"<<","<<"星期四"<<endl;break;
case 5:cout<<y<<"年"<<m<<"月"<<d<<"日"<<","<<"星期五"<<endl;break;
case 6:cout<<y<<"年"<<m<<"月"<<d<<"日"<<","<<"星期六"<<endl;break;
case 0:cout<<y<<"年"<<m<<"月"<<d<<"日"<<","<<"星期日"<<endl;break;
default:break;
}
cout<<endl;
}

你这是要什么语言的?我这里有C版本的,当然C++版本也是可以改出来的。包含了农历与节气,基本上能满足你的要求,如果需要,可以追问,源码奉上,另外,我还有个C/C++的农历库,专门为万年历设计,集成了很实用的功能,用起来非常方便。以下是类的声明:
class CLunar {public: virtual long Int(double dDays) const=0; virtual bool GetDayOrdinal(LONGTIME LongTime,int iYear,double &dDays)=0; virtual bool GetDateFromOrdinal(int iYear,double dDays,LONGTIME &LongTime)=0; virtual bool GetEasterSunday(int iYear,unsigned short &wMonth,unsigned short &wDay)=0; virtual bool GetConstellation(int iYear,unsigned short wMonth,unsigned short wDay,unsigned short &wConstellationIndex)=0; virtual bool GetGanZhi(LONGTIME LongTime,GANZHI &GanZhi,bool bYStartLiChun=false)=0; virtual bool GetGregorian(LUNARDATE LunarDate,LONGTIME &LongTime)=0; virtual bool GetLunar(LONGTIME LongTime,LUNARDATE &LunarDate)=0; virtual bool GetLunarMonthInfo(int iYear,LUNARMONTH &MonthInfo)=0; virtual bool GetLunarPhase(int iYear,unsigned short wMonth,LUNARPHASE &LunarPhase)=0; virtual bool GetSolarTerms(int iYear,SOLARTERMS &SolarTerms)=0; virtual bool IsLeapYear(int iYear,bool &bLeapYear)=0; virtual bool GetExtremeSeason(int iYear,EXTREMESEASON &ExtremeSeason)=0; virtual bool GetSheRi(int iYear,SHERI &SheRi)=0; virtual bool GetFengLong(int iYear,unsigned short &wFengLong)=0; virtual bool GetDays(LONGTIME LongTime1,LONGTIME LongTime2,double &dDays)=0; virtual bool GetDate(LONGTIME LongTime,double dDays,LONGTIME &DstLongTime)=0; virtual bool InitTimeStructure(LONGTIME &LongTime,bool bCurrentTime,int iYear=2000,unsigned short wMonth=1,unsigned short wDay=1,unsigned short wHour=0,unsigned short wMinute=0,unsigned short wSecond=0,unsigned short wMilliSecond=0)=0; virtual bool GetDayOfWeek(int iYear,unsigned short wMonth,unsigned short wDay,unsigned short &wDayOfWeek)=0; virtual bool GetEmperorReign(LONGTIME longtime,char *pBuffer,unsigned int BufSize)=0; virtual unsigned short GetDaysOfMonth(int iYear,unsigned short wMonth)=0; virtual unsigned short GetDaysOfYear(int iYear)=0; virtual unsigned short GetLeapMonth(int iYear)=0; virtual unsigned short GetDaysOfLunarMonth(int iLunarYear,unsigned short wLunarMonth,bool bLeapMonth)=0; virtual unsigned short GetDaysOfLunarYear(int iLunarYear)=0; virtual LONGTIME SysTimeToLong(SYSTEMTIME SystemTime) const=0; virtual SYSTEMTIME LongTimeToSys(LONGTIME LongTime) const=0; virtual int Release()=0;protected: CLunar(void); virtual ~CLunar(void);};