您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > C语言万年历设计报告
C语言课程设计报告题目:编写万年历系统年级:专业:班级:姓名:学号:目录第1章设计目的第2章需求分析第3章概要设计第4章源程序清单第5章执行结果1)登陆界面2)显示当前日月历3)显示具体日期信息第6章程序问题调试与课程设计心得第1章设计目的设计目的(实验要求):1.模仿现实生活中的挂历.2.当前页以系统当前日期的月份为准显示当前月的每一天(显示出日及对应的星期几).3.当系统日期变到下一月时,系统自动翻页到下一月.第2章需求分析(1)程序运行时,首先给出菜单选项和输入提示:(2)用户可以通过主菜单选择不同选项。输入1,通过输入当前日期可显示当前月的日历;输入2,通过输入具体日期(中间以空格分开)可显示该日具体信息;输入3,则退出查询系统。第3章概要设计1.菜单选择界面可通过下面所示函数时现;主要思路:通过while语句与swich…case以及if条件语句实现菜单的循环功能和不同选项的功能实现。闰年与平年的判断:代码如下:voidmain(){intyear,month,day,a,b;while(1){printf(\n\n\n\n);printf(**********************************************************\n\n);printf(**\n);输入具体日期开始输入指令3.退出出、、判断是否为闰年1.当前日期月2.具体日期信息输入要查询的当前日期printf(Welcometoentercalendarsystem\n);printf(**\n\n);printf(**********************************************************\n\n\n);printf(1Themonthofcurrentdate2Date3Exit\n);printf(pleaseimportyourchoose1~3,pressEntertodefine:);scanf(%d,&b);switch(b){case1:printf(\nPleaseimporttheyear,monthanddaywhichyouwanttocheck,theyear,monthanddayseparationbyblankspace:);scanf(%d%d%d,&year,&month,&day);a=x3(year,month,1);if(a==0){printf(Error!Pleaseimportagain.\n);break;}yueli(year,month,day);break;case2:printf(\nPleaseimporttheyear,monthanddaywhichyouwanttocheck,theyear,monthanddayseparationbyblankspace:);scanf(%d%d%d,&year,&month,&day);a=x3(year,month,day);if(a==0){printf(Error!Pleaseimportagain.\n);break;}rili(year,month,day);break;case3:exit(0);default:printf(Error!Pleaseimportagain.\n\n);}}2.闰年的判断:计算所输入的年份是否可被4整除,若不能被整除,为平年。若可被4整除,计算此年份能否被100整除,不能被100整除则为闰年。既能被4整除,也能被100整除的年份,若也能被400整除,则为闰年,否则为平年。闰年366天,平年365天代码:intrunnian(intyear){if(year%4==0&&year%100!=0||year%400==0)return1;elsereturn0;}3.判断某月的天数;通过函数:intday1(intyear,intmonth){inta[12]={31,28,31,30,31,30,31,31,30,31,30,31};若为闰,则二月为29天。第4章源程序清单#includestdio.h#includestdlib.h/*定义头文件*/intrunnian(intyear){if(year%4==0&&year%100!=0||year%400==0)/*利用函数判断输入年份是闰年还是平年*/return1;elsereturn0;}intday1(intyear,intmonth){inta[12]={31,28,31,30,31,30,31,31,30,31,30,31};/*定义数组确定12个月每个月的天数*/if(runnian(year))/*如果输入年份是闰年*/a[1]=29;/*二月29天*/returna[month-1];}intday2(intyear,intmonth,intday){inti,sum=0;for(i=1;imonth;i++){sum+=day1(year,i);}sum+=day;returnsum;}intweek1(intyear,intmonth,intday){intnumber=(year-1)+(year-1)/4-(year-1)/100+(year-1)/400+day2(year,month,day);number%=7;returnnumber;}char*Week2(intnumber){switch(number)/*分类一周七天*/{case0:returnSunday;case1:returnMonday;case2:returnTueaday;case3:returnWednesday;case4:returnThurday;case5:returnFriday;case6:returnSaturday;default:returnError!pleaseimportagain.\n;/*不符和上面七种情况的报错提示*/}}voidx1(intyear,intmonth,intday){intnumber=week1(year,month,day);if(runnian(year))printf(commonyear);/*年份为闰年则输出闰年*/elseprintf(commonyear);printf(%dyear%dmonth%dday%10s\n\n,year,month,day,Week2(number));/*按年月日输出结果*/}voidx2(intyear,intmonth){intmax,number,i,j=1;max=day1(year,month);number=week1(year,month,1);printf(%2s%2s%2s%2s%2s%2s%2s\n,Sunday,Monday,Tueaday,Wednesday,Thurday,Friday,Saturday);/*按照间隔打印日历*/for(i=0;inumber;i++){printf();}while(j=max){printf(%8d,j);if(i%7==6){printf(\n);}i++;j++;}printf(\n\n);}intx3(intyear,intmonth,intday){if(year0||month1||month12||day1||dayday1(year,month))/*当输入值出现这些情况时*/return0;/*返回0*/elsereturn1;/*返回1*/}voidyueli(intyear,intmonth,intday){if(runnian(year))printf(leapyear);elseprintf(commonyear);printf(%dyear%dmonth%dday\n\n,year,month,day);x2(year,month);}voidrili(intyear,intmonth,intday){printf(\n);x1(year,month,day);}voidmain(){intyear,month,day,a,b;while(1){printf(\n\n\n\n);printf(**********************************************************\n\n);printf(**\n);printf(Welcometoentercalendarsystem\n);printf(**\n\n);printf(**********************************************************\n\n\n);printf(1Themonthofcurrentdate2Date3Exit\n);printf(pleaseimportyourchoose1~3,pressEntertodefine:);scanf(%d,&b);switch(b){case1:/*选择1时*/printf(\nPleaseimporttheyear,monthanddaywhichyouwanttocheck,theyear,monthanddayseparationbyblankspace:);/*给出输入提示*/scanf(%d%d%d,&year,&month,&day);/*输入需要查询的年月日*/a=x3(year,month,1);if(a==0){printf(Error!Pleaseimportagain.n);/*输入值异常时报错*/break;}yueli(year,month,day);break;case2:/*选择2时*/printf(\nPleaseimporttheyear,monthanddaywhichyouwanttocheck,theyear,monthanddayseparationbyblankspace:);/*给出输入提示*/scanf(%d%d%d,&year,&month,&day);/*输入年月日*/a=x3(year,month,day);if(a==0){printf(Error!Pleaseimportagain.n);/*输入值异常时报错*/break;}rili(year,month,day);break;case3:exit(0);default:printf(Error!Pleaseimportagain.\n\n);}}}第5章执行结果1)登陆界面2)显示当前日历月3)显示具体日期信息第6章程序问题调试与课程设计心得1)程序问题调试(1)调用的week2函数中,忘记在万年历中一周的第一天是sunday。(2)定义的runnian语句中没有返回值,无法判断是否为闰年。(3)定义的x1与x2函数实现的功能时混淆。(4)被调用函数X3中的返回值要用于主调函数中的判断,但是未在主调函数中赋值给整型变量。(5)对于数组,数组的初始化要进行正确的赋值,以及对于数组的使用与变更。(6)程序的scanf语句中取地址符号不能省。2)课程设计心得通过本次课程设计我通过自己的实践对书本上的知识进行了与生活相关的运用。在这个程序中,主要应用了这学期所学习的循环,条件语句,数组以及调用函数。这些知识的应用使我对课本内容的认识得到了加深。在编写程序的过程中,也出现了很多错误。比如程序语句错误导致检测时连续报错;函数语句编写错误导致输出结果与实际不符等。出现这些情况后,通过对教材的深入理解和解度,我发现了自己的程序的问题所在并进行了改正。最后得到了正确的结果。
本文标题:C语言万年历设计报告
链接地址:https://www.777doc.com/doc-5109042 .html