📄 cpp01.cpp
字号:
// Coded by plusir -- Jan.05.2003.
// Standard C++ Bible -- (P358-12-1)
#include <iostream>
using namespace std ;
class Date
{
public:
Date( int m = 0, int d = 0, int y = 0 )
{
month = m ;
day = d ;
year = y ;
}
void display( void ) const
{
cout << month << '/' << day << '/' << year << endl ;
}
Date operator + ( int ) const ;
private:
int month ;
int day ;
int year ;
static int dys[] ;
} ;
int Date::dys[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } ;
Date Date::operator + ( int n ) const
{
Date dt( *this ) ;
n += dt.day ;
while ( n > dys[dt.month - 1] ) {
n -= dys[dt.month - 1] ;
if ( ( ++dt.month ) == 13 ) {
dt.month = 1 ;
dt.year++ ;
}
}
dt.day = n ;
return dt ;
}
int main()
{
Date oldDate( 2, 20, 1997 ) ;
Date newDate ;
//newDate = oldDate + 21 ;
newDate = oldDate.operator + ( 21 ) ;
newDate.display() ;
return 0 ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -