您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > C语言课程设计实验报告(万年历)
C语言课程设计一、题目及功能描述题目:万年历的设计利用C语言设计出万年历,使其实现如下要求1、输入一个年份,在屏幕上输出该年的年历(包括每月的天数和所对应的星期几),并且在每月的左上角或右上角打印出相应的年份和月份,要求输出界面尽可能整齐、美观,符合年历显示规范。假定输入的年份在1-9999年之间。2、输入年月,输出该月的月历。3、输入年月日,输出距今天还有多少天,是星期几,是否是公历节日。:4、指定键盘的某些键,用于控制变换不同年、月、日的显示。即:当前若正在显示2011年的年历,按下键盘“←”方向键后,年历变为2010年的。二、使用的所有变量的说明变量说明:(以下均为整型变量)year表示年份的变量month表示月份的变量day表示日期的变量select表示菜单选择的变量i表示月份的变量j表示一个月中的某一天的变量sum判断某天是一年中的第几天的变量number判断某天离公元1年1月1日还有几天的变量a[]表示每月天数的数组变量year1系统时间年份的变量month1系统时间月份的变量day1系统时间日期的变量三、程序清单及其说明#includetime.h/*包含的头文件*/#includestdio.h#includemath.h#includewindows.h#includeconio.h#defineKEYNUMUp0x48/*宏定义*/#defineKEYNUMDown0x50#defineKEYNUMLeft0x4b#defineKEYNUMRight0x4d#defineKEYNUMPageUp0x49#defineKEYNUMPageDown0x51inteachyeartotal(intyear,intmonth,intday);/*函数声明*/intcounterdays(intyear,intmonth,intday);intnowtime(intyear,intmonth,intday);intweek(intyear,intmonth,intday);intmaxDay(intyear,intmonth);intisleap(intyear);voidwhatweek(intyear,intmonth,intday);voiddisplay(intyear,intmonth);voiddisplay2(intyear,intmonth);voiddisplay3(intyear,intmonth,intday);voidsetDay1(intyear,intmonth,intday);voidsetDay2(intyear,intmonth,intday);voidsetDay3(intyear,intmonth,intday);voidjieri(intmonth,intday);voiddisplay1(intyear);voidgetmenu();voidmain()/*主函数*/{intyear,month,day,select;while(1){getmenu();printf(请输入相应数字:);/*菜单选择*/scanf(%d,&select);system(cls);switch(select){case1:/*当选择为1时显示年历*/printf(年历显示:输入年(如2011):);scanf(%d,&year);if(year0&&year10000)/*显示年份从0-10000*/{display1(year);/*调用函数*/printf(提示按↑:上一年按↓:下一年按其他键:返回菜单\n\n);setDay1(year,month,day);}elsesystem(cls);printf(输入无效,重新输入!\n);break;case2:/*当选择为2显示月历*/printf(月历显示:输入年月(如2011,6):);scanf(%d,%d,&year,&month);if(year0&&year10000&&month=1&&month=12){display2(year,month);printf(提示按←:上个月按→:下个月按其他键:返回菜单\n\n);setDay2(year,month,day);}elsesystem(cls);printf(输入无效,重新输入!\n);break;case3:/*当选择为3时显示日期*/printf(日期显示:输入年月日(比如2011,6,23):);scanf(%d,%d,%d,&year,&month,&day);if(year0&&year10000&&month=1&&month=12&&day=1&&day=maxDay(year,month)){display3(year,month,day);printf(提示按PageUp:前一天按PageDown:后一天按其他键:返回菜单\n\n);setDay3(year,month,day);}elsesystem(cls);printf(输入无效,重新输入!\n);break;case4:exit(0);default:/*当输入其他数字时,输入无效,重新输入*/system(cls);printf(输入无效,重新输入!\n);}}}intisleap(intyear)/*判断是否为闰年*/{if(year%4==0&&year%100!=0||year%400==0)return1;elsereturn0;}intmaxDay(intyear,intmonth)/*每月的天数*/{inta[]={31,28,31,30,31,30,31,31,30,31,30,31};/*每个月中的天数*/if(isleap(year))a[1]=29;/*闰年2月份有29天*/returna[month-1];}inteachyeartotal(intyear,intmonth,intday)/*判断某天是一年中的第几天*/{inti,sum=0;for(i=1;imonth;i++)sum+=maxDay(year,i);sum+=day;returnsum;}intweek(intyear,intmonth,intday)/*对天数进行判断确定是星期几*/{intnumber=(year-1)+(year-1)/4-(year-1)/100+(year-1)/400+eachyeartotal(year,month,day);number=number%7;returnnumber;}voiddisplay(intyear,intmonth)/*输出年月*/{intmax,number,i,j=1;max=maxDay(year,month);number=week(year,month,1);printf(%4s%4s%4s%4s%4s%4s%4s\n,Sun,Mon,Tue,Wed,Thu,Fri,sat);for(i=0;inumber;i++)printf();/*1号前的星期补空格*/while(j=max){printf(%6d,j);if(i%7==6)printf(\n);/*每7格换一行*/i++;j++;}printf(\n\n);}voiddisplay1(intyear)/*输出年历*/{inti;printf(\n);for(i=1;i=12;i++){printf(%d年%d月\n\n,year,i);display(year,i);}}voiddisplay2(intyear,intmonth)/*输出月历*/{printf(\n%d年%d月\n,year,month);display(year,month);}voiddisplay3(intyear,intmonth,intday)/*输出日历*/{whatweek(year,month,day);jieri(month,day);counterdays(year,month,day);}intcounterdays(intyear,intmonth,intday)/*判断今天距特定日期的天数*/{intyear1,days0,days1,month1,days,day1;time_ttimep;structtm*p;time(&timep);p=gmtime(&timep);year1=(1900+p-tm_year);month1=(1+p-tm_mon);day1=(p-tm_mday);/*获取系统时间year1、month1、day1分别为年、月、日*/days0=(year-1)*365+(year-1)/4-(year-1)/100+(year-1)/400+eachyeartotal(year,month,day);days1=(year1-1)*365+(year1-1)/4-(year1-1)/100+(year1-1)/400+eachyeartotal(year1,month1,day1);days=days0-days1;/*计算出两个日期之间的时间差*/printf(\n今天距%d年%d月%d日还有%d天\n\n,year,month,day,days);returndays;}voidwhatweek(intyear,intmonth,intday)/*判断是星期几*/{intnumber;number=(year-1)+(year-1)/4-(year-1)/100+(year-1)/400+eachyeartotal(year,month,day);number=number%7;switch(number){case0:printf(\n%d年%d月%d日是星期日,year,month,day);break;case1:printf(\n%d年%d月%d日是星期一,year,month,day);break;case2:printf(\n%d年%d月%d日是星期二,year,month,day);break;case3:printf(\n%d年%d月%d日是星期三,year,month,day);break;case4:printf(\n%d年%d月%d日是星期四,year,month,day);break;case5:printf(\n%d年%d月%d日是星期五,year,month,day);break;case6:printf(\n%d年%d月%d日是星期六,year,month,day);break;default:system(cls);printf(出现错误!\n);}}voidjieri(intmonth,intday)/*判断是否公历节日*/{if(month==1)switch(day){case1:printf(,这天是元旦);}if(month==2)switch(day){case14:printf(,这天是情人节);}if(month==3)switch(day){case8:printf(,这天是妇女节);break;case12:printf(,这天是植树节);}if(month==4)switch(day){case1:printf(,这天是愚人节);}if(month==5)switch(day){case1:printf(,这天是劳动节);break;case4:printf(,这天是青年节);}if(month==6)switch(day){case1:printf(,这天是儿童节);}if(month==7)switch(day){case1:printf(,这天是建党节);}if(month==8)switch(day){case1:printf(,这天是建军节);}if(month==9)switch(day){case10:printf(,这天是教师节);}if(month==10)switch(day){case1:printf(,这天是国庆节);}}v
本文标题:C语言课程设计实验报告(万年历)
链接地址:https://www.777doc.com/doc-6059000 .html