1、输入一个年份(1-3000),然后显示12个月的月历能解决闰年和平年问题能输出显示结果、运行需求分析 操作系统: Windows9x, Windows2000, Windows XP及更高版本、数据流图是否闰年确定年份开始信息年份显示其他月份显示12月错误显示表头计算1月1日检查输入任意键非法显示2月显示1月 软件结构图:mainsetinit()output()inputyear()checkinput()setinfo()printmonth()printhead()isleap ()2 软件设计与编码#include ctype.hstdlib.hmath.h#define firstd
2、ayof1 1 /* 定义第一年的第一天, 星期日=7 */#define gap /* set gap between numbers of dates */#define dent /* set right margin. */struct info int month; int firstdayofmonth; int daysofmonth; int leap; monthinfo; int checkinput(void);int inputyear(void);int isleap(int y);void output(struct info);void printhead(str
3、uct info );void printmonth(struct info);struct info setinit(int);struct info setmonthinfo(struct info );/* 这个作用是判断年, 如果是闰年, return 1, 否则 return 0 */int isleap(int y) return (y%4=0 & y%100!=0) | y%400=0);/* This module is to accept inputyear() and check if it is correct. if it is correct it return in
4、t year, otherwise ask user reenter */ int checkinput(void) int y; do y=inputyear(); if(y3000) printf(n输入错误!。nn); y=0; while(y1); return y; /* This function is to accept the input year, if it is the integer, it returns it, otherwise it return -1 */int inputyear(void) char s80; int i, y; y=-1; printf(
5、请输入年份(1-3000): for(i=0;i80;+i) si=getchar(); if(si=27) exit(0); if(si=10) break;+i) if(si=10) break; else if(!isdigit(si) return y; y=atoi(s);/*This module is to accept monthinfo, and print the whole year calender. */void output(struct info monthinfo) char ch; printhead(monthinfo); printmonth(monthi
6、nfo);按任意键显视下一月, 按Esc键退出. n ch=getchar(); if(ch=27) exit(0); monthinfo=setmonthinfo(monthinfo); while(monthinfo.month13);/* This module is to accept monthinfo, amd print monthly head like一 月 */void printhead(struct info monthinfo) char *ss; printf(%s,dent); switch(monthinfo.month) case 1: ss=; case 2
7、:二 月 case 3:三 月 case 4:四 月 case 5:五 月 case 6:六 月 case 7:七 月 case 8:八 月 case 9:九 月 case 10:十 月 case 11:十一 月 case 12: ss=十二 月 %s%s%s%snn,gap,gap,gap,ss);/* This module is to accept monthinfo, and print the numbered dates of the month. */void printmonth(struct info monthinfo) int i,j,k; printf(一%s二%s三%
8、s四%s五%s六%s日nn,gap,gap,gap,gap,gap,gap); for(i=1;monthinfo.firstdayofmonth;i=i+1) printf(%s ,gap); k=monthinfo.firstdayofmonth; for(j=1;j7) k=k-7; printf(nn%s ; k=k+1;%2d%s,j,gap);/* This module is to accept the monthinfo, and set the monthinfo of next month. */ struct info setmonthinfo(struct info m
9、onthinfo) int m; monthinfo.firstdayofmonth= (monthinfo.firstdayofmonth+ monthinfo.daysofmonth-1)%7+1; monthinfo.month=monthinfo.month+1; monthinfo.daysofmonth=30; m=monthinfo.month; if(m=1 | m=3 | m=5 | m=7 | m=8 | m=10 | m =12) monthinfo.daysofmonth=31; if(m=2) if(monthinfo.leap) monthinfo.daysofmonth = 29; else
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1