c语言编程 万年历查询系统
基本要求:1. 查询某年某月某日(阳历)是星期几;
2. 判断某年是否是闰年;
3. 查询某月的最大天数;
4. 打印某年的全年日历或某年某月的月历。
5. 系统完成后应实现类似下图所示界面。
追问:您好,我放到VC里试了一下,有62个错误。
基本要求:1. 查询某年某月某日(阳历)是星期几;
2. 判断某年是否是闰年;
3. 查询某月的最大天数;
4. 打印某年的全年日历或某年某月的月历。
5. 系统完成后应实现类似下图所示界面。
追问:您好,我放到VC里试了一下,有62个错误。
答案:按你的要求写的 如果不能正常运行联系我
#include <stdio.h>
#include <stdlib.h>bool isLeapyear( int nowYear );
int calcuWeek( int totalDays );
int calcuDays( int nowYear,int nowMonth,int nowDay );
bool checkValid( int nowYear,int nowMonth,int nowDay );
void nowMonthprint( int nowYear,int nowMonth,int nowDay );
void weekDayPrint( int nowYear,int nowMonth,int nowDay );
void nowYearprint( int nowYear );
void menuPrint();const int leapDay[12]={31,29,31,30,31,30,31,31,30,31,30,31};//存储闰年每月天数
const int noleapDay[12]={31,28,31,30,31,30,31,31,30,31,30,31};//存储非闰年每月天数int main()
{
int year,month,day;
while( true )
{
menuPrint();
int op;
scanf("%d",&op);
switch( op )
{
case 1:
{
printf("请输入年月日(格式为YYYY-MM-DD):");
scanf("%d-%d-%d",&year,&month,&day);
if ( checkValid(year,month,day) )
weekDayPrint(year,month,day);
else
{
printf("输入错误!!!退出操作\n");
break;
}
break;
}
case 2:
{
printf("请输入需要查询的年份:");
scanf("%d",&year);
if( year > 9999 || year < 0 )
{
printf("年份输入错误!!!退出操作\n\n");
break;
}
if ( isLeapyear( year ) )
printf("%-4d年是闰年!!!\n\n",year);
else
printf("%-4d年是平年!!!\n\n",year);
break;
}
case 3:
printf("请输入需要查询的年份:");
scanf("%d",&year);
if( year > 9999 || year < 0 )
{
printf("年份输入错误!!!退出操作\n\n");
break;
}
nowYearprint(year);
break;
case 4:
printf("请输入年月日(格式为YYYY-MM-DD):");
scanf("%d-%d-%d",&year,&month,&day);
if ( checkValid(year,month,day) )
nowMonthprint(year,month,day);
else
{
printf("输入错误!!!退出操作\n");
break;
}
break;
case 5:
int maxdays;
printf("请输入需要查询的年份及月份(格式YYYY-MM):");
scanf("%d-%d",&year,&month);
if( year > 9999 || year < 0 || month > 12 || month < 0 )
{
printf("年份及月份输入错误!!!退出操作\n\n");
break;
}
if ( isLeapyear(year))
maxdays = leapDay[month-1];
else
maxdays = noleapDay[month-1];
printf("%d年%d月最大天数为%d\n\n",year,month,maxdays);
break;
case 6:
printf("退出系统,谢谢使用\n\n");
return 0;
break;
}
}
return 0;
}bool isLeapyear( int nowYear ) // 判断是否闰年
{
if( nowYear%4 == 0 && nowYear%100 != 0 || nowYear%400 == 0)
return true;
else
return false;
}bool checkValid( int nowYear,int nowMonth,int nowDay )// 输入合法性检查
{
if ( nowYear <= 0 )
{
printf( "输入年份不合法!!!");
return false;
}
if ( nowMonth < 0 && nowMonth > 12 )
{
printf("输入月份不合法!!!");
return false;
}
if ( nowDay < 0 && nowDay > 31 && isLeapyear(nowYear) )
{
printf("输入号数不合法!!!");
return false;
}
if ( nowDay < 0 && nowDay > 30 && !isLeapyear(nowYear) )
{
printf("输入号数不合法!!!");
return false;
}return true;
}int calcuDays( int nowYear,int nowMonth,int nowDay )// 计算总天数
{
int days = 0;
int mon = 0;
for ( int i = 1;i < nowYear;i++ )
{
if( isLeapyear( i ) )
days += 366;
else
days += 365;
}
for ( int j = 1;j < nowMonth;j++ )
{
if ( isLeapyear(nowYear) )
mon = mon + leapDay[j-1];
else
mon = mon + noleapDay[j-1];
}
days = days + mon + nowDay;return days;
}int calcuWeek( int totalDays ) // 计算星期几
{
int weekNo = totalDays%7;
return weekNo;
}void weekDayPrint( int nowYear,int nowMonth,int nowDay ) //打印某年某日星期几
{
int days = calcuDays(nowYear,nowMonth,nowDay);
int weekNo = calcuWeek( days );
switch ( weekNo )
{
case 0:
printf( "%-4d年%-2d月%-2d日是星期天!!!",nowYear,nowMonth,nowDay);
break;
case 1:
printf( "%-4d年%-2d月%-2d日是星期一!!!",nowYear,nowMonth,nowDay);
break;
case 2:
printf( "%-4d年%-2d月%-2d日是星期二!!!",nowYear,nowMonth,nowDay);
break;
case 3:
printf( "%-4d年%-2d月%-2d日是星期三!!!",nowYear,nowMonth,nowDay);
break;
case 4:
printf( "%-4d年%-2d月%-2d日是星期四!!!",nowYear,nowMonth,nowDay);
break;
case 5:
printf( "%-4d年%-2d月%-2d日是星期五!!!",nowYear,nowMonth,nowDay);
break;
case 6:
printf( "%-4d年%-2d月%-2d日是星期六!!!",nowYear,nowMonth,nowDay);
break;
}
printf("\n\n");
}void nowMonthprint( int nowYear,int nowMon