1、c语言万年历C语言课程设计内容: 课程设计题目:万年历 功能如下:1、查询某年某月某日是星期几 2、打印某年的某月的全月日历 3、打印某年的全年日历 4、退出 具体要求: (1)在住菜单中输入1后,显示:“请输入年月日(XXXX,XX,XX)” 运行后输出:XXXX年XX月XX日是星期X,是否继续查询(Y/N)? 如果输入Y,则重新显示“请输入年月日(XXXX,XX,XX)”,否则回到主菜单. (2)在主菜单中输入2后,显示:“请输入要打印的月份(XXXX)” 运行后输出X月的日历,格式为: XXXX年XX月 S M T W T F S X X X X X X X X X X X X X X
2、X X X X X X X X X X X X X X X X (3)在主菜单中输入3后,显示:“请输入要打印的年份(XXXX)” 运行后输出XXXX年的日历, XXXX X(月数) S M T W T F S X X X X X X X X X X X X X X X X X X X X X X X X X X X X x x S M T W T F S X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X 运行完成后显示:“是否继续打印(Y/N)?” 如果输入Y,则重新显示“请输入要打印的年份(XXXX)”,否则回到主菜
3、单。 (4) 在主菜单中输入4后,显示:“是否要真的退出(Y/N)?” 如果输入Y,结束程序运行,否则重新显示主菜单。#include #include typedef struct int year; char month; char day;*DATE;DATE NewDate(void);int DestroyDate(DATE date);int DaysAMonth(DATE date);int CheckDate(DATE date);int SetDate(DATE date,int year,int month,int day);int GetWeek(DATE date);i
4、nt QueryDay(void);int ShowMonth(DATE date);int QueryMonth(void);int QueryYear(void);int ConfirmExit(void);int Calendar(void);int main() if(Calendar() return 0; else return 1;DATE NewDate(void) DATE date; date=(DATE)malloc(sizeof(*date); return date;int DestroyDate(DATE date) if(!date) return 0; free
5、(date); return 1;int DaysAMonth(DATE date) int days; if(!date) return 0; switch(date-month) case 1: case 3: case 5: case 7: case 8: case 10: case 12: days=31; break; case 4: case 6: case 9: case 11: days=30; break; default: days=0; break; if(date-month=2) if(date-year%4=0 & date-year%400!=0 | date-y
6、ear%400=0) days=29; else days=28; return days;int CheckDate(DATE date) if(!date) return 0; if(date-monthmonth12) return 0; if(date-daydayDaysAMonth(date) return 0; return 1;int SetDate(DATE date,int year,int month,int day) if(!date) return 0; date-year=year; date-month=month; date-day=day; return Ch
7、eckDate(date);int GetWeek(DATE date) int year,month,day; if(!date) return 0; year=date-year; month=date-month; day=date-day; if(month=2) month+=12; -year; return (day+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7+1;int QueryDay(void) DATE date; char cont; int year,month,day; static char *we
8、ek=星期一,星期二,星期三,星期四,星期五,星期六,星期日; if(!(date=NewDate() return 0; do printf(请输入年月日(XXXX,XX,XX)); scanf( %d, %d, %d,&year,&month,&day); if(SetDate(date,year,month,day) printf(%4d年%2d月%2d日是%s,是否继续查询(Y/N)?, year,month,day,weekGetWeek(date)-1); scanf( %c,&cont); else printf(日期输入错误!n); while(cont=Y | cont=y)
9、; DestroyDate(date); return 1;int ShowMonth(DATE date) int startweek; int days; int i; if(!date) return 0; startweek=GetWeek(date); days=DaysAMonth(date); printf( S M T W S F S n); startweek=startweek%7; for(i=0;istartweek;+i) printf( ); for(i=1;i=days;+i) printf( %2d ,i); startweek=(startweek+1)%7;
10、 if(startweek=0) printf(n); if(startweek!=0) printf(n); return 1;int QueryMonth(void) int year,month; DATE date; if(!(date=NewDate() return 0; printf(请输入要打印的月份(XXXX,XX); scanf( %d, %d,&year,&month); if(SetDate(date,year,month,1) printf(%4d年%2d月n,year,month); ShowMonth(date); else printf(月份输入错误!n); D
11、estroyDate(date); return 1;int QueryYear(void) int year; int month; DATE date; char cont; if(!(date=NewDate() return 0; do printf(请输入要打印的年份(XXXX)); scanf( %d,&year); printf(%4d年n,year); for(month=1;month=12;+month) SetDate(date,year,month,1); printf(%2d月n,month); ShowMonth(date); printf(是否继续打印(Y/N)?
12、); scanf( %c,&cont); while(cont=Y | cont=y); DestroyDate(date); return 1;int ConfirmExit(void) char exit; printf(是否要真的退出(Y/N)?); scanf( %c,&exit); if(exit=Y | exit=y) return 1; else return 0;int Calendar(void) int menu=1; int tmp; do switch(menu) case 1: printf(n |1 查星期| |2 月日历| |3 年日历| |4 退出|:); sc
13、anf( %d,&tmp); switch(tmp) case 1: menu=11; break; case 2: menu=12; break; case 3: menu=13; break; case 4: menu=14; break; default: printf(选择有误!n); break; break; case 11: QueryDay(); menu=1; break; case 12: QueryMonth(); menu=1; break; case 13: QueryYear(); menu=1; break; case 14: if(ConfirmExit() menu=0; else menu=1; break; default: return 0; while(menu); return 1;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1