第1个回答 2011-01-12
//---------------------------------------------------------------------------
#include <stdio.h>
#include <conio.h>
//---------------------------------------------------------------------------
class C_Date
{
public:
int Year;
int Month;
int Day;
void GetNextDay(void);
void PrintDate(void);
};
void C_Date :: GetNextDay(void)
{
Day ++;
switch(Month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if(Day > 31)
{
Day = 1;
Month ++;
if(Month > 12)
{
Month = 1;
Year ++;
}
}
break;
case 2:
if( (Year%400)==0 || ((Year%4)==0 && (Year%100)) )
{
if(Day > 29)
{
Day = 1;
Month ++;
}
}
else
{
if(Day > 28)
{
Day = 1;
Month ++;
}
}
break;
case 4:
case 6:
case 9:
case 11:
if(Day > 30)
{
Day = 1;
Month ++;
}
break;
}
}
void C_Date :: PrintDate(void)
{
printf("=====The next day is: %d-%d-%d\n",Year,Month,Day);
}
int main(int argc, char* argv[])
{
C_Date date;
char ch;
while(1)
{
printf("\n");
printf("1: Input a date\n");
printf("2: Get next day\n");
printf("3: exit\n");
printf(">>>>>Please select a item: ");
ch = getch();
putch(ch);
putch('\r');
putch('\n');
switch(ch)
{
case '1':
printf(">>>>>(year month day): ");
scanf("%d %d %d",&date.Year,&date.Month,&date.Day);
break;
case '2':
date.GetNextDay();
date.PrintDate();
break;
case '3':
return 0;
default:
break;
}
}
return 0;
}
//---------------------------------------------------------------------------来自:求助得到的回答