1 Star 0 Fork 0

Admin / text_cpp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
class_date.cpp 899 Bytes
一键复制 编辑 原始数据 按行查看 历史
Admin 提交于 2024-04-24 22:41 . 日期类
#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;
}
1
https://gitee.com/small-c_2_0/text_cpp.git
git@gitee.com:small-c_2_0/text_cpp.git
small-c_2_0
text_cpp
text_cpp
master

搜索帮助