#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;
void print(int,int);
int main()
{
int year,month,ch1=0,ch2=0;
cin>>year>>month;
print(year,month);
//识别键盘输入的“上、下”,据此调节year和month
while(1)
{
if(ch1=getch())
{
ch2=getch();
if(ch2==72)
{
if(month<12)
month++;
else
{
year++;
month=1;
}
cout<<year<<' '<<month<<endl;
print(year,month);
}
else if(ch2==80)
{
if(month>=2)
month--;
else
{
year--;
month=12;
}
cout<<year<<' '<<month<<endl;
print(year,month);
}
}
}
getch();
return 0;
}
void print(int year,int month)
{
int c,y,week,i,col=1,num;
cout<<"日\t一\t二\t三\t四\t五\t六\n";
if(month==1||month==3||month==5||month==7|month==8||month==10||month==12)
num=31;
else if(month==4||month==6||month==9||month==11)
num=30;
else if(month==2&&year%4==0&&year%100!=0)
num=29;
else
num=28;
if(month==1)
{
year=year-1;
month=13;
}
if(month==2)
{
year=year-1;
month=14;
}
c=year/100;
y=year%100;
//求当月的第一天是星期几
week = ((c/4)-2*c+y+(y/4)+(26*(month+1)/10)) % 7;
for(i=1;i<=week;i++,col++)
cout<<'\t';
col--;
for(i=1;i<=num;i++)
{
if(col==7)
{
cout<<'\n';
col=1;
}
else
col++;
cout<<i<<'\t';
}
cout<<'\n';
cout<<'\n';
}
C++输入年份月份输出日历,键盘控制月份增减
最新推荐文章于 2023-05-23 06:46:37 发布