QQ网名大全

万年历查询程序。 功能要求: (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 d**play_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<<"请选择操作:\n1→显示某年日历\
\n2→查询某天\n0→退出"<<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 d**play_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;
}
佚名
2024-05-31 19:58:39
最佳回答
类似问题(10)