nextday 软件测试
吉林大学应用技术学院
实验(训)报告单(电子版)
实验编号2实验班级实验名称测试nextdate任务书编号1实验组别实验组成员报告人指导教师实 验 报 告
代码: #ifndef _Date_H
#define _Date_H
#include
class Date
{
public:
Date(){}
Date(int,int,int);
Date(Date &);
~Date(){}
void setDate(int,int,int);
bool IsLeapYear() const;
int TimeElapsed() const;
void NextDate();
void print();
private:
int year;
int month;
int day;
};
#endif
#include
#include "stdlib.h"
Date::Date(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
Date::Date(Date &a)
{
year=a.year;
month=a.month;
day=a.day;
}
void Date::setDate(int y,int m,int d)
{
year=y;
month=m;
day=d;
int tof;
if((year>1919&&year<2051)&&(month>0&&month<13))
{
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
{
if(day>0&&day<32)
{
tof=1;
break;
}
else
{
tof=0;
break;
}
}
case 4:
case 6:
case 9:
case 11:
{
if(day>0&&day<31)
{
tof=1;
break;
}
else
{
tof=0;
break;
}
}
case 2:
{
if((IsLeapYear()&&day>0&&day<30)||(!IsLeapYear()&&day>0&&day<29))
{
tof=1;
break;
}
else
{
tof=0;
break;
}
}
default:
{
tof=0;
break;
}
}
}
else
{
tof=0;
}
if(tof==0)
{
cout<
exit(1);
}
}
bool Date::IsLeapYear() const
{
return (year%400==0)||(year%100!=0)&&(year%4==0);
}
int Date::TimeElapsed() const
{
int sum=0;
int b;
if(IsLeapYear())
b=29;
else
b=28;
return 0;
}
void Date::NextDate