基于C++编写的简单的日期计算器

本文介绍了如何使用C++编程语言编写一个简单的日期计算器。在Visual Studio 2013环境下,作者展示了代码并分享了测试结果。
摘要由CSDN通过智能技术生成

基于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 <
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值