c语言万年历.docx
- 文档编号:3675402
- 上传时间:2022-11-24
- 格式:DOCX
- 页数:11
- 大小:15.73KB
c语言万年历.docx
《c语言万年历.docx》由会员分享,可在线阅读,更多相关《c语言万年历.docx(11页珍藏版)》请在冰豆网上搜索。
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月
SMTWTFS
XXXXXXX
XXXXXXX
XXXXXXX
XXXXXXX
XX
(3)在主菜单中输入3后,显示:
“请输入要打印的年份(XXXX)”运行后输出XXXX年的日历,
XXXX
X(月数)
SMTWTFS
XXXXXXX
XXXXXXX
XXXXXXX
XXXXXXX
xx
SMTWTFS
XXXXX
XXXXXXX
XXXXXXX
XXXXXXX
XXXXX
运行完成后显示:
“是否继续打印(Y/N)?
”
如果输入Y,则重新显示“请输入要打印的年份(XXXX)”,否则回到主菜单。
(4)在主菜单中输入4后,显示:
“是否要真的退出(Y/N)?
”如果输入Y,结束程序运行,否则重新显示主菜单。
#include
#include
typedefstruct{
intyear;
charmonth;
charday;
}*DATE;
DATENewDate(void);
intDestroyDate(DATEdate);
intDaysAMonth(DATEdate);
intCheckDate(DATEdate);
intSetDate(DATEdate,intyear,intmonth,intday);
intGetWeek(DATEdate);
intQueryDay(void);
intShowMonth(DATEdate);
intQueryMonth(void);
intQueryYear(void);
intConfirmExit(void);
intCalendar(void);
intmain()
{
if(Calendar())
return0;
else
return1;
}
DATENewDate(void)
{
DATEdate;
date=(DATE)malloc(sizeof(*date));
returndate;
}
intDestroyDate(DATEdate)
{
if(!
date)
return0;
free(date);
return1;
}
intDaysAMonth(DATEdate)
{
intdays;
if(!
date)
return0;
switch(date->month)
{
case1:
case3:
case5:
case7:
case8:
case10:
case12:
days=31;
break;
case4:
case6:
case9:
case11:
days=30;
break;
default:
days=0;
break;
}
if(date->month==2)
if(date->year%4==0&&date->year%400!
=0||date->year%400==0)
days=29;
else
days=28;
returndays;
}
intCheckDate(DATEdate)
{
if(!
date)
return0;
if(date->month<1||date->month>12)
return0;
if(date->day<1||date->day>DaysAMonth(date))
return0;
return1;
}
intSetDate(DATEdate,intyear,intmonth,intday)
{
if(!
date)
return0;
date->year=year;
date->month=month;
date->day=day;
returnCheckDate(date);
}
intGetWeek(DATEdate)
{
intyear,month,day;
if(!
date)
return0;
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;}
intQueryDay(void)
{
DATEdate;
charcont;
intyear,month,day;
staticchar*week[]={"星期一","星期二","星期三","星期四","星期五","星期六","星期日"};
if(!
(date=NewDate()))
return0;
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,week[GetWeek(date)-1]);
scanf("%c",&cont);
}
else
{
printf("日期输入错误!
\n");
}
}while(cont=='Y'||cont=='y');
DestroyDate(date);
return1;
}
intShowMonth(DATEdate)
{
intstartweek;
intdays;
inti;
if(!
date)
return0;
startweek=GetWeek(date);
days=DaysAMonth(date);
printf("SMTWSFS\n");
startweek=startweek%7;
for(i=0;i printf(""); for(i=1;i<=days;++i) { printf("%2d",i); startweek=(startweek+1)%7; if(startweek==0) printf("\n"); } if(startweek! =0) { printf("\n"); } return1; } intQueryMonth(void) { intyear,month; DATEdate; if(! (date=NewDate())) return0; 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"); } DestroyDate(date); return1; } intQueryYear(void) { intyear; intmonth; DATEdate; charcont; if(! (date=NewDate())) return0; 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)? "); scanf("%c",&cont); }while(cont=='Y'||cont=='y'); DestroyDate(date); return1; } intConfirmExit(void) { charexit; printf("是否要真的退出(Y/N)? "); scanf("%c",&exit); if(exit=='Y'||exit=='y') return1; else return0; } intCalendar(void) { intmenu=1; inttmp; do{ switch(menu) { case1: printf("\n|1查星期||2月日历||3年日历| scanf("%d",&tmp); switch(tmp) { case1: menu=11; break; case2: menu=12; break; case3: menu=13; break; case4: menu=14; break; default: printf("选择有误! \n"); break;退出|: ");|4 } break; case11: QueryDay(); menu=1; break; case12: QueryMonth(); menu=1; break; case13: QueryYear(); menu=1; break; case14: if(ConfirmExit()) menu=0; else menu=1; break; default: return0; } }while(menu); return1; }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 万年历