中国矿业大学徐海学院软件开发基础实践报告姓名:李岳学号: ******** 专业:计算机科学与技术指导教师:孙锦程职称:讲师2012 年 6 月30 徐州源代码#include <stdio.h>#include <conio.h> //getch(); tolower(); exit();#include <stdlib.h> //system();int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};char *weeks[7] ={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};char *months[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November","December"};bool isLeap(int year) //by theLeap(); theCalendar();/*判断是否为闰年*/{if(year%4 == 0 && year%100 != 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, int month, int day) //by theWeek(); printCalendar();/*判断星期的自定义函数*/{int c, y, m, d, w;if( month < 3) { year -= 1; month += 12; }c = year / 100;y = year % 100;m = month;d = day;w = y + y/4 + C/4 - 2*C + 26*(m+1)/10 + d - 1;w %= 7;return (w >= 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 ) ) days[1] = 29; //是否闰年else days[1] = 28;}while(!( (month > 0 && month < 13) && (day > 0 && day <= days[month - 1]) ) );w = Zeller(year, month, day);printf("\nThis day %d-%02d-%02d is %s.", year, month, day, weeks[w]);getch();}void printCalendar(int year, int month) //by details(); theCalendar();/*输出日期详情及表格*/{int w, d;w = Zeller(year, month, 1);printf("%28s", months[month - 1]);printf("\n -%02d-\n", month);printf(" SUN MON TUE WED THU FRI SAT\n");for(d = 0; d < w; d++) { printf(" "); }for(month--, d = 1; d <= days[month]; d++){printf("%4d", d);if( (d + w)%7 == 0 && d != days[month]) printf("\n"); }printf("\n============================\n");}void details(int year) //by theCalendar();/*月历详情函数*/ {int month;while(true){do{system("Cls");printf("Press '0' to exit.\n");printf("Please input the month: ");scanf("%d", &month);}while(!(month >=0 && month <= 12));if(month != 0){printf("\n");printf("Calendar %d\n", 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 ) ) days[1] = 29; //是否闰年else days[1] = 28;system("Cls");printf("Calendar %d\n", year);for(month = 1; month <= 12; month++){printCalendar(year, month);}printf("More details of each month ?[Y/N]");if( tolower(getch()) == 'y' ) details( year );}void Menu() //by main();/*程序的主菜单*/{system("cls");printf("1 -This year is leap year or not\n");printf("2 -This day is which day of the week\n"); printf("3 -The Calendar of this year\n");printf("0 -Exit\n\n");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(); }}。