日期计算器

本文介绍了如何编写一个简单的日期类,实现日期的加减运算以及计算两个日期之间相差的天数。通过Date.h和test.cpp文件展示了核心功能。
摘要由CSDN通过智能技术生成

写一个简单的日期类实现日期计算器功能:

1 给一个日期计算这个日期加上一个天数后是哪一天

2 给一个日期计算这个日期减去一个天数后是哪一天

3 给定两个日期,求这两个日期中间相隔多少天


Date.h

#ifndef __DATE_H__
#define __DATE_H__


#define _CRT_SECURE_NO_DEPRECATE 1
#include<iostream>
#include<stdlib.h>
using namespace std;

class Date
{
public:
	Date(int year=1900, int month=1, int day=1)
	{
		this->_year = year;
		this->_month = month;
		this->_day = day;
	}
    Date(const Date& d)
	{
		this->_year = d._year;
		this->_month = d._month;
		this->_day = d._day;
	}
	~Date()
	{
		;
	}
	Date& operator=(const Date& d)
	{
		if(this != &d)
		{
		this->_year = d._year;
		this->_month = d._month;
		this->_day = d._day;
		}
		return *this;
	}
void Print_Date();
int GetMonthDay(int year, int month);
bool CheckLegality();
Date& operator+=(int day);    //求某个日期day天后的日期是哪一天
Date& operator-=(int day);	  //求某个日期day天前的日期是哪一天
bool operator>(const Date& d); 
bool operator&#
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值