#include
struct date
{
int year;
int month;
int day;
};
int days(struct date day)
{
static int day_tab[2][13]=
{{0,31,28,31,30,31,30,31,31,30,31,30,31,}, /* 平均每月的天数 */
{0,31,29,31,30,31,30,31,31,30,31,30,31,},
};
int i,lp;
lp=day.year%4==0&&day.year%100!=0||day.year%400==0;
/* 判定 year 为闰年还是平年, lp=0 为平年,非 0 为闰年 */
/* 判定 year 为闰年还是平年, lp=0 为平年,非 0 为闰年 */
for(i=1;i
return day.day;
}
int main()
{
struct date today,term;
int yearday,year,day;
printf("Enter year/month/day:");
scanf("%d%d%d",&today.year,&today.month,&today.day); /* 输入日期 */
term.month=12; /* 设置变量的初始值:月 */
term.day=31; /* 设置变量的初始值:日 */
for(yearday=0,year=1990;year
term.year=year;
yearday+=days(term); /* 计算从 1990 年至指定年的前一年共有多少天 */
}
yearday+=days(today); /* 加上指定年中到指定日期的天数 */
day=yearday%5; /* 求余数 */
if(day>0&&day<4)
printf("he was fishing at that day.\n"); /* 打印结果 */
else
printf("He was sleeping at that day.\n");
}
我写了一个DATE类,你可以改一下,然后,再用天数除以5判断是否打鱼的。我写的DATE类是从1880年开始到2500年的,需要不?以下是DATE类的类接口,需要的话,给我加分
class Date
{
public:
enum { FIRST_YEAR = 1800, MAX_YEAR = 2500 };
// Constructor
Date( int y = FIRST_YEAR, int m = 1, int d = 1 );
// Aissgnment operator ( instead of + )
Date & operator+=( int days );
// Binary operators.
int operator- ( const Date & right );
bool operator<( const Date & right );
friend ostream & operator<<( ostream & out, const Date & rhs );
friend istream & operator>>( istream & in, Date & rhs );
private:
int totalDays;
static int DAYS_TILL_FIRST_OF_MONTH[ 13 ];
static int DAYS_TILL_JAN1 [ 6 ];
bool isLeapYear( int year = FIRST_YEAR );
};
1990年只要稍微改一下,你懂的
我有个三天打鱼两天晒网的程序,但是不包括年份什么的,你要把?
应该改下就可以了。。。
#include
struct date
{
int year;
int month;
int day;
};
int days(struct date day);
void main()
{
date today,term;
int yeardays=0,day;
cout<< "请输入年/月/日:";
cin>>today.year>>today.month>>today.day;
term.month=12;
term.day=31;
for(term.year=2000;term.year
yeardays+=days(today);
day=yeardays%5;
if (day>0&&day<4)
cout<<"他在打渔"<
cout<<"他在晒网"<
//计算从年初到day时的天数
int days(date day)
{
static int day_tab[2][13]=
{ {0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31} };
int i,flag;
flag=day.year%4==0&&day.year%100!=0||day.year%400==0;
for (i=1;i
return(day.day);
}