代码拉取完成,页面将自动刷新
#include "class_date.h"
#include <iostream>
using namespace std;
//注意一下年份的调整!!!
Date Date::operator+=(int day)//日期加天数,注意要对原对象进行修改
{
_day += day;
while(_day > GetMonthDay(_year, _month))//如果天数大于,进行进位
{
if (_month > 12)//月份超过,再对于进行进位
{
_month = 1;
_year++;
}
_day = _day - GetMonthDay(_year, _month);
_month++;
}
return *this;
}
Date Date::operator+(int day)//加法,对原对象不进行处理
{
Date tmp = *this;
tmp += day;
return tmp;
}
Date Date::operator-=(int day)
{
_day -= day;
if (_day < 0)//天数为负,向前一位进行借位
{
if (_month < 1)//依旧进行调整
{
_month = 12;
_year--;
}
--_month;
_day += GetMonthDay(_year, _month);
}
return *this;
}
Date Date::operator-(int day)
{
Date tmp = *this;
tmp -= day;
return tmp;
}
void Date::Printf()
{
cout << _year << "-" << _month << "-" << _day << endl;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。