基于C++编写的简单的日期计算器
以下代码是在VS2013下编译运行的:
下面展示我的测试结果:

代码如下:
#include<iostream>
using namespace std;
#include"vld.h"//这个是检测虚拟内存是否泄露,我在这里安装了vld,所以直接用,包含头文件就好了
class Date
{
public:
//构造函数
Date(int year=2018, int month=8, int day=16)
{
_year = year;
_month = month;
_day = day;
}
//析构函数
~Date()
{
}
//拷贝构造函数
Date(const Date& d)//必须传引用,传值会引发无穷递归调用
{
_year = d._year;
_month = d._month;
_day = d._day;
}
//赋值重载
Date& operator=(const Date& d)
{
if (this != &d)
{
this->_year = d._year;
this->_month = d._month;
this->_day = d._day;
}
return *this;
}
//打印输出
void showDate()
{
cout << "原来的日期:" << _year << "-" << _month << "-" << _day << endl;
}
void showDate1()
{
cout << "加上指定天数:" << _year << "-" << _month << "-" << _day<<endl;
}
void showDate2()
{
cout << "减去指定天数:" << _year << "-" << _month << "-" << _day << endl;
}
void showDate3()
{
cout <