C培训第11课作业-万年历
本来以为12点之前可以完事的,不过不知不觉的就到了凌晨3点...
又熬夜了!!! 杯具
用了将近20个小时.终于把这个作业完成了.
虽然可能还不够完善,不过beta1版的万年历也算成型了.
以后会进行必要的修正的.
源码:void error()
{
char a = 0;
clrscr();
printf("Input Error!!!\n");
printf("Sorry,\n");
printf("inorder to ensure the normal operation of the program.\n");
printf("Please enter a character.\n");
scanf(" %c",&a);
return;
}
int leap(int y)
{
int a = 0;
if( ( !(y%4) && (y%100) ) || !(y%400) )
{
a = 1;
}
return a;
}
int month(int y,int m)
{
int a = 0;
if( !(m-4) || !(m-6) || !(m-9) || !(m-11) )
{
a = 30;
}else if( (m-2) )
{
a = 31;
}else
{
if(leap(y))
{
a = 29;
}
else
{
a = 28;
}
}
return a;
}
int ymd(int y,int m,int d)
{
int a = 0;
if(y<1901 || y>2099 || m<1 || m>12 || d<1 || d>month(y,m))
{
error();
}else
{
a = 1;
}
return a;
}
int year( int y )
{
int i = 1901;
int b = 0;
unsigned int c = 0;
char d = 0;
for ( ; i<y ; i++)
{
if( leap(i) )
{
b = 366;
}
else
{
b = 365;
}
c += b;
}
d = (c+2) % 7;
return d;
}
int moon(int y,int m)
{
int i = 0;
int a = 0;
int b = 0;
int c = 0;
for ( i=1 ; i<m ; i++ )
{
a = month(y,i);
b += a;
}
c = year( y );
c = (c+b) % 7;
return c;
}
int algorithm(int y,int m,int d)
{
int a;
if( !ymd(y,m,d) )
{
main();
}else
{
a = moon(y,m);
}
return a;
}
void output(int a,int y,int m,int d)
{
int b = 0;
int c = 0;
int e = 0;
int f = 0;
int g = 0;
clrscr();
printf("A Perpetual Calendar Beta1. By:LShang\n\n");
printf(" The current date is:%d-%d-%d\n",y,m,d,a);
gotoxy(1,6);
printf(" Sun Mon Tue Wed Thu Fri Sat\n\n");
while( c < a )
{
printf(" ");
c++;
}
for( b = 1 ; b <= month(y,m) ; b++)
{
if( !(c % 7) && c )
{
printf("\n\n");
f++;
}
printf(" %02d",b);
if(!(b-d))
{
e = c;
g = f;
}
c++;
}
gotoxy(1,22);
printf("You can use the '%c' or '%c' to adjust the year.",0x1e,0x1f);
printf("\nYou can use the '%c' or '%c' to adjuse the month.",0x11,0x10);
printf("\nIf you want to re-define the date ,press the space bar.");
printf("\nIf you want to exit,press the number key '0'");
gotoxy( ( 6*(e%7)+4 ),( 6+2*(g+1) ) );
return;
}
void smile(int x,int u,int v)
{
int a = 0;
int b = 0;
a = 1;
gotoxy(u,v);
for(b=1 ; b<=10;b++)
{
if(a == (5+x-1) || a == (5-x+1))
{
printf("*");
}else
{
printf(" ");
}
a++;
}
return;
}
main()
{
int y = 0;
int m = 0;
int d = 0;
int b = {0};
int x = 0;
int u = 0;
int v = 0;
clrscr();
printf("A Perpetual Calendar Beta1. By:LShang\n\n");
printf("Press 'ctrl' + 'c' to exit.\n\n");
printf("Please enter a date,For example(2011-1-9):");
scanf("%d-%d-%d",&y,&m,&d);
go: output(algorithm(y,m,d),y,m,d);
while(*b != 0x30)
{
*b = getch();
if(*b == 0x48)
{
if(!(y-1901))
{
y = 2099;
}else
{
y--;
}
}else if(*b == 0x50)
{
if(!(y-2099))
{
y = 1901;
}else
{
y++;
}
}else if(*b == 0x4b)
{
if(!(m-1))
{
y--;
m = 12;
}else
{
m--;
}
}else if(*b == 0x4d)
{
if(!(m-12))
{
y++;
m = 1;
}else
{
m++;
}
}else if(*b == 0x20)
{
main();
}
goto go;
}
clrscr();
gotoxy(20,1);
printf("Thank you for you use,Bye.%c",0x01);
v = 5;
for(x=1 ; x<=5 ; x++)
{
u = 19;
smile(x,u,v);
u = 39;
smile(x,u,v);
v++;
}
v = 13;
for(x=5 ; x>=1 ; x--)
{
u = 29;
smile(x,u,v);
v++;
}
}
截图:
开始界面:
运行界面:
退出界面:
源码附件:
学习学习
页:
[1]