📄 mydate.cpp
字号:
#include "iostream"
#include "myDate.h"
Date::Date()
{
year = month = day = 0;
}
Date::Date(int y, int m, int d)
{
year = y;
month = m;
day = d;
}
//对‘ 〉’运算符重载
bool Date::operator>(const Date & D) const
{
if(year > D.year)
return true;
if((year == D.year) && (month > D.month))
return true;
if((year == D.year) && (month == D.month) && (day > D.day))
return true;
else
return false;
}
//对‘〈 ’运算符重载
bool Date::operator<(const Date & D) const
{
if(year < D.year)
return true;
if((year == D.year) && (month < D.month))
return true;
if((year == D.year) && (month == D.month) && (day < D.day))
return true;
else
return false;
}
//对‘ = ’运算符重载
bool Date::operator=(const Date & D) const
{
if((year == D.year) && (month == D.month) && (day == D.day))
return true;
else
return false;
}
//定义Show(), 方便输出
void Date::Show() const
{
cout << year << " year, " << month << " month, " << day << " day ";
cout << '\n';
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -