c语言课程设计报告万历系统.doc

上传人:仙人指路1688 文档编号:2384896 上传时间:2023-02-17 格式:DOC 页数:13 大小:95.50KB
返回 下载 相关 举报
c语言课程设计报告万历系统.doc_第1页
第1页 / 共13页
c语言课程设计报告万历系统.doc_第2页
第2页 / 共13页
c语言课程设计报告万历系统.doc_第3页
第3页 / 共13页
c语言课程设计报告万历系统.doc_第4页
第4页 / 共13页
c语言课程设计报告万历系统.doc_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《c语言课程设计报告万历系统.doc》由会员分享,可在线阅读,更多相关《c语言课程设计报告万历系统.doc(13页珍藏版)》请在三一办公上搜索。

1、中国矿业大学徐海学院软件开发基础实践报告姓 名: 李岳 学 号: 22110522 专 业: 计算机科学与技术 指导教师: 孙锦程 职 称: 讲师 2012 年 6 月 30 徐州姓名/学号:李岳 22110522 班级:计(中软)11-1一、 程序来源:百度贴吧 c语言吧 二、程序项目名称:万年历三、 程序原理:1、int days12 = 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31; 这是定义的关于每个月天数的数组,根据大小月以及二月分的特殊情况将每个月的天数最为数组中的元素存入数组当中。其中days1=28,是将闰年二月的天数28天作为初

2、始元素存入。在经过theWeek函数后就可以给days1中存入正确的月天数。2、char *weeks7 =Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday; char *months12 = January, February, March, April, May, June, July, August, September, October, November, DeCember; 这两组数据都设计利用了指针定义的。这两个数组的作用是存入每个月,每个星期的地址。利用指针可以提高程序的可读性,可以更方便使用。四、程序

3、功能: 1、输入年份,判断是否为闰年 2、输入年月日,判断改日为星期几 3、输入年份,打出12个月历,输入月份,打出该月的日历五、程序内容(输入输出): isLeap和theLeap函数的共同使用,一起判断出了输入年份是否为闰年的信息。 theCalendar/*打开相应的详情*/ ,details /*月历详情函数*/ ,printCalendar /*输出日期详情及表格*/,通过这三个函数可以将输入数据的具体信息通过完整日历的形式表示出来。六、数据流分析(定义的变量,类型,数组,类型,结构体):头文件:stdio.h /*/ conio.h /*/ stdlib.h /*/采用指针形式定义

4、了*weeks和*months两组数组指针变量在程序中运用了大量的自定义函数,都涉及为了使程序更简介明了。其中有:isLeap/*判断是否为闰年*/theLeap/*输入输出改年是否为闰年的信息*/ Zeller/*判断星期的自定义函数*/ theWeek()/*对于输入的日期输出该天是星期几*/ printCalendar()/*输出日期详情及表格*/ details /*月历详情函数*/ theCalendar/*打开相应的详情*/ Menu()/*程序的主菜单*/ Select()/*按键的控制函数*/这些函数的定义极其相应的内部程序共同构筑起了这个万年历总程序。其中的isLeap函数是

5、用来判断输入的年份是否为闰年,实现了预计功能的第一个方面;theWeek函数则是为了实现判断星期而编写的;printCalendar , details , theCalendar这三个函数的共同使用就能够完成第三个功能。七、程序代码分析(每个函数和代码模块的功能作用分析):1、总天数算法isLeap和theLeap函数的共同使用,一起判断出了输入年份是否为闰年的信息。判断一年是否为闰年的方法是:该年分而能被四整除但不能被100整除,或者是能被400整除。2、计算输入日期是星期几利用Zeller函数可以判断出星期,然后对于输入的日期可以通过theWeek() 函数对Zeller进行一次调用然后

6、就可以输出相应的星期数。int Zeller(int year, int month, int day) /by theWeek(); printCalendar();/*判断星期的函数*/ int C, y, m, d, w; if( month = 0 ? w : w+7);void theWeek() /by Select();/*对于输入的日期输出该天是星期几*/ int year, month, day, w; printf(n); do printf(Please input the date(YYYY-MM-DD): ); scanf(%d-%d-%d, &year, &mont

7、h, &day); if( isLeap( year ) ) days1 = 29; /是否闰年 else days1 = 28; while(!( (month 0 & month 0 & day = daysmonth - 1) ) ); w = Zeller(year, month, day); printf(nThis day %d-%02d-%02d is %s., year, month, day, weeksw); getch();3、对输入信心的汇总theCalendar/*打开相应的详情*/ ,details /*月历详情函数*/ ,printCalendar /*输出日期详

8、情及表格*/,通过这三个函数可以将输入数据的具体信息通过完整日历的形式表示出来。void printCalendar(int year, int month) /by details(); theCalendar();/*输出日期详情及表格*/ int w, d; w = Zeller(year, month, 1); printf(%28s, monthsmonth - 1); printf(n -%02d-n, month); printf( SUN MON TUE WED THU FRI SATn); for(d = 0; d w; d+) printf( ); for(month-,

9、d = 1; d =0 & month = 12); if(month != 0) printf(n); printf(Calendar %dn, year); printCalendar(year, month); if( getch() = 0) break; else break; void theCalendar() /by Select(); int year, month; printf(nPlease input the year: ); scanf(%d, &year); if( isLeap( year ) ) days1 = 29; /是否闰年 else days1 = 2

10、8; system(cls); printf(Calendar %dn, year); for(month = 1; month = 12; month+) printCalendar(year, month); printf(More details of each month ?Y/N); if( tolower(getch() = y ) details( year );八、控制流分析(源程序整体流程图):开始计算是否为闰年计算星期数按键1?按键2?按键3?输出是否为闰年输出星期数计算编辑接收到的数据输出具体月历按键0?是是是是计算是否为闰年计算星期数按键1?按键2?按键3?是是是计算是

11、否为闰年计算星期数按键1?按键2?按键3?是是计算是否为闰年计算星期数按键1?按键3?是是结束 退出九、源代码优点,好处:程序中使用了大量的自定义函数,使程序简单明了,效率更高十、总结及心得体会: 这次“万年历系统设计”的课程设计不仅让我对C语言的熟悉程度上升到了另一个高度,更加熟练的运用C语言,而且在一定意义上对面向过程设计的理解更加深刻了。是我在编程路途上的一次质的飞跃。而且在处理非常规数据类型的运算的锻炼下,使我对编程语言有了一个新的认识。当看着一个具有图形界面的万年历的模型成品出现在自己面前时,心中有着无限感慨,原来编程也不是非常遥不可及的,原来在编程的趣味性中能让我学到更多有意思的知

12、识十一、对源程序过程及方法、手段的改进建议: 在主菜单输入0后,显示:是否真的要退出(Y/N)? 如果输入Y 则退出程序 否则重新运行 Case 0: 后的代码改为 printf(nDo you want to Exit?(Y/N); con=getch(); if(con=y)|(con=Y) return; if(con=n)|(con=N) Exit(1);报告评分: 指导教师签字:源代码#include #include /getch(); tolower(); exit();#include /system();int days12 = 31, 28, 31, 30, 31, 30,

13、 31, 31, 30, 31, 30, 31;char *weeks7 =Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday;char *months12 = January, February, March, April, May, June, July, August, September, October, November, December;bool isLeap(int year) /by theLeap(); theCalendar();/*判断是否为闰年*/ if(year%4 = 0 & year%1

14、00 != 0 | year%400 = 0) return 1; else return 0; void theLeap() /by Select();/*输入输出改年是否为闰年的信息*/ int year; printf(nPlease input the year: ); scanf(%d, &year); if( isLeap( year ) ) printf(nThe year %d is leap year., year); else printf(nThe year %d is not leap year., year); getch();int Zeller(int year,

15、 int month, int day) /by theWeek(); printCalendar();/*判断星期的自定义函数*/ int c, y, m, d, w; if( month = 0 ? w : w+7);void theWeek() /by Select();/*对于输入的日期输出该天是星期几*/ int year, month, day, w; printf(n); do printf(Please input the date(YYYY-MM-DD): ); scanf(%d-%d-%d, &year, &month, &day); if( isLeap( year )

16、) days1 = 29; /是否闰年 else days1 = 28; while(!( (month 0 & month 0 & day = daysmonth - 1) ) ); w = Zeller(year, month, day); printf(nThis day %d-%02d-%02d is %s., year, month, day, weeksw); getch();void printCalendar(int year, int month) /by details(); theCalendar();/*输出日期详情及表格*/ int w, d; w = Zeller(

17、year, month, 1); printf(%28s, monthsmonth - 1); printf(n -%02d-n, month); printf( SUN MON TUE WED THU FRI SATn); for(d = 0; d w; d+) printf( ); for(month-, d = 1; d =0 & month = 12); if(month != 0) printf(n); printf(Calendar %dn, year); printCalendar(year, month); if( getch() = 0) break; else break;

18、 void theCalendar() /by Select(); int year, month; printf(nPlease input the year: ); scanf(%d, &year); if( isLeap( year ) ) days1 = 29; /是否闰年 else days1 = 28; system(Cls); printf(Calendar %dn, year); for(month = 1; month = 12; month+) printCalendar(year, month); printf(More details of each month ?Y/

19、N); if( tolower(getch() = y ) details( year );void Menu() /by main();/*程序的主菜单*/ system(cls); printf(1 -This year is leap year or notn); printf(2 -This day is which day of the weekn); printf(3 -The Calendar of this yearn); printf(0 -Exitnn); printf(Please select the options:);void Select() /by main();/*按键的控制函数*/ char key; bool v = true; while( v ) key = getch(); switch( key ) Case 1: theLeap(); v = false; break; Case 2: theWeek(); v = false; break; Case 3: theCalendar(); v = false; break; Case 0: exit(1); void main() while(true) Menu(); Select();

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号