C 语言课程 设计报告 题目:编写万年历系统编写万年历系统 年级: 专业: 班级: 姓名: 学号: 目目 录录 第 1 章 设计目的 第 2 章 需求分析 第 3 章 概要设计 第 4 章 源程序清单 第 5 章 执行结果 1)登陆界面 2 2))显示当前日月历 3)显示具体日期信息 第 6 章 程序问题调试与课程设计心得 第第 1 章设计目的章设计目的 设计目的(实验要求): 1.模仿现实生活中的挂历. 2.当前页以系统当前日期的月份为准显示当前月的每一天(显示 出日及对应的星期几). 3.当系统日期变到下一月时,系统自动翻页到下一月. 第 2 章需求分析 (1)程序运行时,首先给出菜单选项和输入提示: (2)用户可以通过主菜单选择不同选项。输入 1,通过输入当前日期可显 示当前月的日历;输入 2,通过输入具体日期(中间以空格分开)可显示该 日具体信息;输入 3,则退出查询系统。 第 3 章 概要设计 输入具体日期 1.菜单选择界面可通过下面所示函数时现; 主要思路: 通过 while 语句与 swich…case 以及 if 条件语句实现菜单的循环功能和不同选 项的功能实现。 闰年与平年的判断: 代码如下: void main() { int year,month,day,a,b; while(1) { printf(“\n\n\n\n“); printf(“ **********************************************************\n\n“); printf(“ * * \n“); 开始 输入指令 3.退出出、 、 判断是否为闰年 1.当前日期 月 2.具体日期 信息 输入要查询的当 前日期 printf(“ Welcome to enter calendar system \n“); printf(“ * * \n\n“); printf(“ **********************************************************\n\n\n“); printf(“ 1 The month of current date 2 Date 3 Exit\n“); printf(“ please import your choose,press Enter to define: “); scanf(“%d“, switch(b) { case 1: printf(“\n Please import the year,month and day which you want to check,the year,month and day separation by blank space: “); scanf(“%d%d%d“, a=x3(year,month,1); if(a==0) { printf(“Error!Please import again.\n“); break;} yueli(year,month,day); break; case 2: printf(“\n Please import the year,month and day which you want to check,the year,month and day separation by blank space: “); scanf(“%d%d%d“, a=x3(year,month,day); if(a==0) { printf(“Error!Please import again.\n“); break;} rili(year,month,day); break; case 3: exit(0); default: printf(“Error!Please import again.\n\n“); } } 2.闰年的判断: 计算所输入的年份是否可被 4 整除,若不能被整除,为平年。若可被 4 整除,计算此年份能否被 100 整除,不能被 100 整除则为闰年。既能被 4 整 除,也能被 100 整除的年份,若也能被 400 整除,则为闰年,否则为平年。 闰年 366 天,平年 365 天 代码: int runnian(int year) { if(year%4==0 else return 0; } 3.判断某月的天数; 通过函数: int day1(int year,int month) { int a[12]={31,28,31,30,31,30,31,31,30,31,30,31}; 若为闰,则二月为 29 天。 第 4 章 源程序清单 #include #include/*定义头文件*/ int runnian(int year) { if(year%4==0 else return 0; } int day1(int year,int month) { int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};/*定义数组确定 12 个月每个 月的天数*/ if(runnian(year)) /*如果输入年份是闰年*/ a[1]=29; /*二月 29 天*/ return a[month-1]; } int day2(int year,int month,int day) { int i,sum=0; for(i=1;i12||dayday1(year,month)) /*当输入值出现 这些情况时*/ return 0; /*返回 0*/ else return 1; /*返回 1*/ } void yueli(int year,int month,int day) { if(runnian(year)) printf(“leap year“); else printf(“common year“); printf(“ %d year %d month %d day\n\n“,year,month,day); x2(year,month); } void rili(int year,int month,int day) { printf(“\n“); x1(year,month,day); } void main() { int year,month,day,a,b; while(1) { printf(“\n\n\n\n“); printf(“ **********************************************************\n\n“); printf(“ * * \n“); printf(“ Welcome to enter calendar system \n“); printf(“ * * \n\n“); printf(“ **********************************************************\n\n\n“); printf(“ 1 The month of current date 2 Date 3 Exit\n“); printf(“ please import your choose,press Enter to define: “); scanf(“%d“, switch(b) { case 1: /*选择 1 时*/ printf(“\nPlease import the year,month and day which you want to check,the year,month and day separation by blank space: “); /*给出输入提 示*/ scanf(“%d%d%d“, /*输入需要查询 的年 月 日*/ a=x3(year,month,1); if(a==0) { printf(“Error!Please import again.n“);/*输入值异常 时报错*/ break; } yueli(year,month,day); break; case 2: /*选择 2 时*/ printf(“\nPlease import the year,month and day which you want to check,the year,month and day separation by blank space: “); /*给出输 入提示*/ scanf(“%d%d%d“,/*输入年 月 日*/ a=x3(year,month,day); if(a==0) { printf(“Error!Please import again.n“);/*输入值 异常时报错*/ break; } rili(year,month,day); break; case 3: exit(0); default: printf(“Error!Please import again.\n\n“); } } } 第 5 章 执行结果 1)登陆界面 2 2))显示当前日历月 3)显示具体日期信息 第 6 章 程序问题调试与课程设计心得 1)程序问题调试 (1) 调用的 week2 函数中,忘记在万年历中一周的第一天是 sunday。 (2)定义的 runnian 语句中没有返回值,无法判断是否为闰年。 (3)定义的 x1 与 x2 函数实现的功能时混淆。 (4)被调用函数 X3 中的返回值要用于主调函数中的判断,但是未在主调函数 中赋值给整型变量。 (5)对于数组,数组的初始化要进行正确的赋值,以及对于数组的使用与变更。 (6)程序的 scanf 语句中取地址符号不能省。 2)课程设计心得 通过本次课程设计我通过自己的实践对书本上的知识进行了与生活相关的运用 。在这个程序中,主要应用了这学期所学习的循环,条件语句,数组以及调用 函数。这些知识的应用使我对课本内容的认识得到了加深。 在编写程序的过程中,也出现了很多错误。比如程序语句错误导致检测时 连续报错;函数语句编写错误导致输出结果与实际不符等。出现这些情况后, 通过对教材的深入理解和解度,我发现了自己的程序的问题所在并进行了改正 。最后得到了正确的结果。
展开阅读全文