1>date

 

写一个日期类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;

};


 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值