?? date.cpp
字號:
#include <iostream>
#include <string>
#include "Date.h"
using namespace std;
Date::Date(void):month(0),day(0),year(0),hour(0),minute(0),second(0)
{
}
Date::Date (int month, int day, int year, int hour, int minute, int second):month(month),day(day),year(year),hour(hour),minute(minute),second(second)
{
}
void Date::setMonth(int& mo)
{
month = mo;
}
void Date::setDay(int& da)
{
day = da;
}
void Date::setYear(int& ye)
{
year = ye;
}
void Date::setHour(int& ho)
{
hour = ho;
}
void Date::setMinute(int& mi)
{
minute = mi;
}
void Date::setSecond(int& se)
{
second = se;
}
int Date::getMonth(void) const
{
return month;
}
int Date::getDay(void) const
{
return day;
}
int Date::getYear(void) const
{
return year;
}
int Date::getHour(void) const
{
return hour;
}
int Date::getMinute(void) const
{
return minute;
}
int Date::getSecond(void) const
{
return second;
}
bool Date::operator== (const Date &rhs)
{
if((year == rhs.year)&&(month == rhs.month)&&(day == rhs.day)&&(hour ==rhs.hour)&&(minute == rhs.minute)&&(second == rhs.second))
return true;
else
return false;
}
bool Date::operator< (const Date &rhs)
{
if(year < rhs.year)
return true;
else if(year > rhs.year)
return false;
else
{
if(month < rhs.month)
return true;
else if(month > rhs.month)
return false;
else
{
if(day < rhs.day)
return true;
else if(day > rhs.day)
return false;
else
{
if(hour < rhs.hour)
return true;
else if(hour > rhs.hour)
return false;
else
{
if(minute < rhs.minute)
return true;
else if(minute > rhs.minute)
return false;
else
{
if(second < rhs.second)
return true;
else if(second > rhs.second)
return false;
else
{
return false;
}
}
}
}
}
}
}
ostream &operator<<(ostream& stream, const Date& d)
{
return stream << d.getMonth() << "/" << d.getDay() << "/" << d.getYear() << " " << d.getHour() << ":" << d.getMinute() << ":" << d.getSecond();
}
istream &operator>>(istream& stream, Date& d)
{
string str;
stream >> str;
int month,day,year,hour,minute,second;
string::size_type pos1,pos2;
pos1 = str.find_first_of ("/");
month = atoi(str.substr(0, pos1).c_str());
pos2 = str.find_last_of("/");
day = atoi(str.substr(pos1+1,pos2).c_str());
year = atoi(str.substr(pos2+1,pos2+5).c_str());
stream >> str;
pos1 = str.find_first_of(":");
hour = atoi(str.substr(0,pos1).c_str());
pos2 = str.find_last_of(":");
minute = atoi(str.substr(pos1+1,pos2).c_str());
second = atoi(str.substr(pos2+1).c_str());
d.setMonth(month);
d.setDay(day);
d.setYear(year);
d.setHour(hour);
d.setMinute(minute);
d.setSecond(second);
return stream;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -