资源描述:
《人机交互作业》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、6.1编写一个程序。请用户输入日,月和年。程序返回一年中到给定的日子(包括这一天)的总天数。#include#include#include#include#defineSIZE20#defineEASY3#defineYUE12structMONTH{charmonth_name[SIZE];//月份名charmonth_easy[EASY+1];//月份简称intdays;//月份的天数};structMyDATE{intyear;intmonth;intday;};in
2、tleap_year(intyear);intGetMonth(charmonth[]);voidGetDate(structMyDATE*date);structMONTHyear[YUE]={{"january","jan",31},{"february","feb",28},{"march","mar",31},{"april","apr",30},{"may","may",31},{"june","jun",30},{"july","jul",31},{"august","aug",31},{"september","sep",30},{"oc
3、tober","oct",31},{"november","nov",30},{"december","dec",31}};intmain(){intmnth,days,alldays,nowdays;MyDATEmydate;GetDate(&mydate);days=(mydate.month<=1)?leap_year(mydate.year):0;//是的话为闰年intnum=leap_year(mydate.year);printf("%d",num);if(num=0){alldays=365;}else{alldays=366;}pr
4、intf("%d天",alldays);for(mnth=YUE;mnth>=mydate.month;--mnth)days+=year[mnth-1].days;//printf("%d天",days);//到年后的天数days=days-mydate.day+1;//printf("%d天",(alldays-days));//days=days-mydate.day+1;nowdays=alldays-days;//printf("%d年%d月%d日到年底还有%d天。",mydate.year,mydate.month,mydate
5、.day,days);printf("到%d年%d月%d日还有%d天。",mydate.year,mydate.month,mydate.day,nowdays);fflush(stdin);system("pause");return0;}voidGetDate(structMyDATE*date){intflag,days,addday;charmnth[15];printf("请输入日期(空格隔开):");do{scanf("%d%s%d",&date->year,mnth,&date->day);flag=0;if(date->year<1
6、
7、
8、date->year>99999999){flag=1;printf("你的输入有误(年份应在1--99999999之间)");printf("请重新输入日期(空格隔开):");continue;}if(mnth[0]>='0'&&mnth[0]<='9')date->month=atoi(mnth);elsedate->month=GetMonth(mnth);if(date->month<1
9、
10、date->month>YUE){flag=1;printf("你的输入有误(月份应在1--12之间,或英文的全写,或缩写)");printf(
11、"请重新输入日期(空格隔开):");continue;}addday=(date->month==2)?leap_year(date->year):0;days=year[date->month-1].days+leap_year(date->year)+addday;if(date->day<1
12、
13、date->day>days){flag=1;printf("你的输入有误(%d月的日期应在1--%d之间)",date->month,days);printf("请重新输入日期(空格隔开):");continue;}}while(flag);}int
14、leap_year(intyear){returnyear%4==0&&year%100!=0