这是让我们练习类的作业题,输入日期,输出加一日;输入时间,按输入增量时间加时间并输出。这是交作业的系统用来检验程序的记录,不知道哪里出错了,求求大佬,救救孩子吧,让我能交个作业QAQ
#include //头文件
#include //使用标准流;
#include
using namespace std;
class current_date
{
public:
current_date();
current_date(int day = 0, int month = 0, int year = 2018);
void assign_data();//给已经初始化的数据成员赋值
~current_date();
void display_data();//显示日期(数据成员的值)
int erro();// erro()判断输入date是否正确
int increment_date();//添加成员函数增量日期
private:
int day, month, year;
};
current_date::current_date(int x, int y, int z)//初始化
{
day = x; month = y; year = z;
}
void current_date::assign_data()//赋值
{
cin >> year; cin >> month; cin >> day;
}
void current_date::display_data()//显示
{
cout << year << "/" << month << "/" << day;
}
int current_date::erro()// 判断正误
{
int n, flag = 1;
switch (month)
{
case 1 || 3 || 5 || 7 || 8 || 10 || 12:
if (day > 31)
{
flag = -1;
}
break;
case 4:case 6: case 9: case 11:
if (day > 30)
{
flag = -1;
}
break;
case 2:
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
{
if (day > 29)
{
flag = -1;
}
}
else
{
if (day > 28)
{
flag = -1;
}
}
break;
default:
flag = -1;
}
return flag;
}
int current_date::increment_date()//添加成员函数增量日期
{
int n;
switch (month)
{
case 1 || 3 || 5 || 7 || 8 || 10:
if (day == 31)
{
month++; day = 1;
}
else
{
day++;
}
break;
case 4:case 6:case 9:case 11:
if (day == 30)
{
month++; day = 1;
}
else
{
day++;
}
break;
case 2:
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
{
if (day == 29)
{
month++; day = 1;
}
else
{
day++;
}
}
else
{
if (day == 28)
{
month++; day = 1;
}
else
{
day++;
}
}
break;
case 12:
if (day == 31)
{
year++; month = 1; day = 1;
}
else
{
day++;
}
break;
return 0;
}
}
current_date::~current_date() {}
class current_time
{
public:
current_time();
current_time(int hour = 0, int minute = 0, float second = 0);
current_time(int x, int y, int z);//给数据成员初始化
~current_time();
void assign_time();//给已经初始化的数据成员赋值
int increment_time(float);//添加成员函数增量时间
int display_time();//显示时间(数据成员的值)
private:
int hour; int minute; float second;
};
current_time::current_time(int x, int y, float z)
{
hour = x; minute = y; second = z;
}
void current_time::assign_time()
{
cin >> hour >> minute >> second;
}
int current_time::increment_time(float x)
{
int n = second;
n = second + x;
second = n % 60;
minute = minute + n / 60;
hour = hour + minute / 60;
minute = minute % 60;
//hour = hour % 24;
return 0;
}
int current_time::display_time()
{
cout << " " << hour << ":" << minute << ":" << second;
}
current_time::~current_time() {}
int main()
{
float s = 0;
current_date date(0, 0, 0);//建立data类
current_time time(0, 0, (float)0);//建立time类
while (1)//无限循环
{
date.assign_data();//赋值data
time.assign_time();//赋值time
cin >> s;//赋值增量时间
int erro = date.erro();//erro()判断输入date是否正确
if (erro == -1)//输出错误
cout << erro << endl;
else//输出正确
{
date.increment_date();//加一日
time.increment_time(s);//加规定增量时间
date.display_data();//显示日期
time.display_time();//显示时间
//cout << "-1 2008/3/1 25:0:0" << endl;
system("pause");
return 0;
}
}
}