曹建平 江雷 什么仇:C语言课程设计——万年历

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/30 15:28:29
一、设计及功能
1.系统封面设计
内容:题目名称(中英文)、进入(中英文)、作者:***、时间:****-**-**
2.输入界面
内容:(1)密码口令输入及容错(3次)
(2)年份的输入及容错(3次)
3.日历计算设计
(1)求某月某日实行奇迹的函数(邱每月一号的星期数)。算法:(y-1)+(y-1)/4-(y-1)/100+(y-1)/400+c 得出S (y为年份,c为某月某日是这一年的第几天,S为总的天数)
(2)邱某月某日至这一年第几天的函数(求c) 闰年的算法: y/400==0 ?或y/400==0&&y/100!=0
根据(1)(2)求出每个月的日期
4、日历格式显示设计
要求:每屏显示4个月。
二、文档资料
系统程序说明书、程序系统函数调用图、每个程序结构的流程图、

(2)

#include<stdio.h>
#include<bios.h>
struct data
{
int year1;
int specialmonth;
int month1[13];
};
struct day{
int year2;
int month2;
int day2;
};

int dis_day1(struct day *op,int *p)
{
int n=0,x;
n+=(op->year2-1980)*365;
for(x=1980;x<op->year2;x++)
if((x%4==0&&x%100!=0)||(x%100==0&&x%400==0))n+=1;
for(x=1;x<(op->month2);x++)
n+=*(p+x-1);
x=op->year2;
if(((x%4==0&&x%100!=0)||(x%100==0&&x%400==0))&&op->month2>2)n+=1;
n+=(op->day2-1);
return n;
}
int dis_day2(struct day *op,struct data *p)
{
int n=0,maxmonth,i,x;
for(x=1980;x<op->year2;x++)
{ if((p+x-1979)->specialmonth==0)maxmonth=12;
else maxmonth=13;
for(i=0;i<maxmonth;i++)
if((p+x-1979)->month1[i]==0)n+=29;
else n+=30;
}
if((p+op->year2-1979)->specialmonth!=0)
if((p+op->year2-1979)->specialmonth<op->month2)op->month2++;
for(i=1;i<op->month2;i++)
{
if((p+op->year2-1979)->month1[i-1]==0)n+=29;
else n+=30;}
n+=(op->day2-1);
n+=46;
return n;
}
void work_out2(struct day *re,struct data *p,int n)
{
int n1=0,maxday,maxmonth,month,day,judge=0;
re->year2=1979;re->month2=11;re->day2=14;
while(1)
{
if(judge==1)break;
if(p->specialmonth==0)maxmonth=12;
else maxmonth=13;
if(p->year1==1979)month=12;
else month=1;
for(;month<=maxmonth;month++)
{
if(p->month1[month-1]==0)maxday=29;
else maxday=30;
if((p->year1==1979)&&(maxday==30))day=14;
else day=1;
for(;day<=maxday;day++)
{
if(n1==n){if(maxmonth==13&&month>p->specialmonth)month-=1;
re->year2=p->year1;re->month2=month;re->day2=day;judge=1;break;}
else n1+=1;
}

if(judge==1)break;}
p++;
}
}

void work_out1(struct day *re,int n,int *p)
{
int year=1980,n1=0,month,day,maxday,judge=0;
re->year2=1980;re->month2=1;re->day2=1;
while(1)
{
*(p+1)=28;
if(judge==1)break;
if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0))*(p+1)=29;
for(month=1;month<=12;month++)
{
maxday=*(p+month-1);
for(day=1;day<=maxday;day++)
{

if(n1==n){re->year2=year;re->month2=month;re->day2=day;judge=1;break;}
else n1++;
}

if(judge==1)break;}
year++;
}
}

main()
{
int n,c;
int sun[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int *p1=sun;
struct day ob,re; struct data *p2;
struct data year[37]={
{1979,6, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0 },
{1980,0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0 },
{1981,0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0 },
{1982,4, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1 },
{1983,0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0 },
{1984,10,1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1 },
{1985,0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 },
{1986,0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0 },
{1987,6, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0 },
{1988,0, 1, 0, 1, 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 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 },
{2011,0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0 },
{2012,4, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
{2013,0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
{2014,9, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 },
{2015,0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0 }
};
p2=year;
printf(" WARNING \n");
printf(" you should take care of it :\n");
printf(" the limted range:\n");
printf(" lunar calendar: 1980.1.1----2015.11.12\n");
printf(" soalr calendar: 1980.1.1-----2015.12.31\n");

while(1)
{ printf(" please choose one way a/b?\n");
printf(" a: soalr calendar---->lunar calendar\n");
printf(" b: lunar calendar---->soalr calendar\n");
do{c=getchar();}while(c!='a'&&c!='b');
do{
printf("your must pay attention to the form\n");
printf("pleae input your date:\n");
scanf("%d.%d.%d",&ob.year2,&ob.month2,&ob.day2);
}while(ob.year2<1980||ob.year2>=2016||ob.month2<1||
ob.month2>12||ob.day2<1||ob.day2>31);
switch©
{
case 'a':

n=dis_day1(&ob, p1);printf("%d\n",n);
work_out2(&re,p2,n);
printf(" the result is %d.%d.%d\n",re.year2,re.month2,re.day2);break;
case 'b':

n=dis_day2(&ob,p2);printf("%d\n",n);
work_out1(&re,n,p1);
printf(" the result is %d.%d.%d\n",re.year2,re.month2,re.day2);
if(ob.month2==(p2+ob.year2-1979)->specialmonth)
{ if((ob.day2!=30)||((p2+ob.year2-1979)->month1[ob.month2]==1))
{ n+=((p2+ob.year2-1979)->month1[ob.month2-1]+29);
work_out1(&re,n,p1);
printf("there is a other result\n:\t%d.%d.%d\n",re.year2,re.month2,re.day2);
}
}

break;
defluat: break;
}
printf("if you want to try again,y/n?\n");
do{c=bioskey(0);}while(c!=0x316e&&c!=0x1579);if(c==0x316e)break;
}
}