写一个日期类Date,具有如下功能:
1、 具有年、月、日、时、分、秒等基本数据。
2、 能使用如下方式进行初始化或声明:
a) Date D1(2008,1,14) //2008年1月14日
b) Date D2(2008,1,14,13) //2008年1月14日13:00:00
c) Date D3(2008,1,14,13,5) //2008年1月14日13:05:00
d) Date D4(2008,1,14,13,5,7) //2008年1月14日13:05:07
e) Date D5(“2008-1-14 13:5:7”) //年月日之间用一个-号分隔,时间部分用:分隔,日期与时间之间有一个空格。
3、 能判断是否是闰年。
4、 能获取年、月、日、时、分、秒。
5、 能计算一个日期加上若干年,有AddYear(int n)这样的成员函数,对月、日、时、分、秒也有类似的函数。
6、 具有输入、输出流,输入的格式为年、月、日、时、分、秒用空格间隔分别输入,输出的格式采用24小时制,如“2008-1-14 13:05:07”
7、 提供日期对象之间的关系运算符的重载,能进行==,!=,<,>,<=.>=等运算符的比较。
#include "Date.h"
/*
e) Date D5(“2008-1-14 13:5:7”) //年月日之间用一个-号分隔,时间部分用:分隔,日期与时间之间有一个空格。
3、 能判断是否是闰年。
4、 能获取年、月、日、时、分、秒。
5、 能计算一个日期加上若干年,有AddYear(int n)这样的成员函数,对月、日、时、分、秒也有类似的函数。
6、 具有输入、输出流,输入的格式为年、月、日、时、分、秒用空格间隔分别输入,输出的格式采用24小时制,如“2008-1-14 13:05:07”
7、 提供日期对象之间的关系运算符的重载,能进行==,!=,<,>,<=.>=等运算符的比较。
*/
/* 各种构造函数 */
Date::Date()
:m_year(0), m_month(0), m_day(0), m_hour(0), m_minute(0), m_second(0)
{
}
Date::Date(int year, int month, int day)
:m_year(year), m_month(month), m_day(day), m_hour(0), m_minute(0), m_second(0)
{
}
Date::Date(int year, int month, int day, int hour, int minute, int second)
:m_year(year), m_month(month), m_day(day), m_hour(hour), m_minute(minute), m_second(second)
{
}
Date::Date(string str)
{
}
/*
bool Date::isLeapYear();
string Date::getDate();
void Date::addYear(int n);
void Date::addMonth(int n);
void Date::addDay(int n);
void Date::addHour(int n);
void Date::addMinute(int n);
void Date::addSecond(int n);
void Date::inputDate();
void Date::outputDate();
bool Date::operator==(Date& date);
bool Date::operator!=(Date& date);
bool Date::operator<(Date& date);
bool Date::operator>(Date& date);
bool Date::operator<=(Date& date);
bool Date::operator>=(Date& date);
*/
Date::~Date(void)
{
}
#pragma once
#include <iostream>
#include <string>
using namespace std;
class Date
{
public:
Date();
Date(int year, int month, int day);
Date(int year, int month, int day, int hour, int minute=0, int second=0);
Date(string str);
bool isLeapYear();
string getDate();
void addYear(int n);
void addMonth(int n);
void addDay(int n);
void addHour(int n);
void addMinute(int n);
void addSecond(int n);
void inputDate();
void outputDate();
bool operator==(Date& date);
bool operator!=(Date& date);
bool operator<(Date& date);
bool operator>(Date& date);
bool operator<=(Date& date);
bool operator>=(Date& date);
~Date();
private:
int m_year;
int m_month;
int m_day;
int m_hour;
int m_minute;
int m_second;
};