c++课程设计作业、高手帮忙!(过了明天就交的,帮忙补到200行左右)
额。写过,我去找找 #include<stdio.h>
void PrintMonthCalender(int startDay,int days);/*函数原型*/
int GetWeekDay(int year,int month);/*函数原型*/
int GetMonthDays(int year,int month);/*函数原型*/
main()
{
int month,year;/*定义变量*/
printf("input the year and month<YYYY-MM>:");
scanf("%d-%d",&year,&month);/*读入变量*/
printf("\t\t\t%d-%d\n",year,month);
printf("Sun.\tMon.\tTue.\tWed.\tThu.\tFri.\tSat.\n");/*打印日历表头*/
PrintMonthCalender(GetWeekDay(year,month),GetMonthDays(year,month));/*调用函数子程序,打印出某年某月日历*/
return 0;
}
/*定义打印日历子程序*/
void PrintMonthCalender(int startDay,int days)
{
int k=0,n=1;
while(k<startDay)
{
printf(" \t");
k++;
}
if(k==startDay&&k!=6)
{
printf("%d\t",n);
k++;
n++;
}
else if(k==startDay&&k==6)
{
printf("%d\n",n);
k++;
n++;
}
while(n<days)
{
if(k%7==6)
{
printf("%d\n",n);
k++;
n++;
}
else
{
printf("%d\t",n);
k++;
n++;
}
}
if(n=days)
{
printf("%d\n",n);
n++;
}
}
/*定义求某月一号为周几子程序*/
int GetWeekDay(int year,int month)
{
int GetMonthDays(int year,int month);
int n,WeekDay,days;
days=(year-1)*365+(year-1)/400+(year-1)/4-(year-1)/100;
for(n=1;n<month;++n)
days=days+GetMonthDays(year,n);
WeekDay=(days+1)%7;
return WeekDay;
}
/*定义求某年某月的天数子程序*/
int GetMonthDays(int year,int month)
{
int MonthDays;
if((year%4==0&&year%100!=0)||year%400==0)
{
if(month==4||month==6||month==9||month==11)
MonthDays=30;
else if(month==2)
MonthDays=29;
else
MonthDays=31;
}
else
{
if(month==4||month==6||month==9||month==11)
MonthDays=30;
else if(month==2)
MonthDays=28;
else
MonthDays=31;
}
return MonthDays;
}