📄 cpp31.cpp
字号:
// Coded by plusir -- Jan.05.2003.
// Standard C++ Bible -- (P343-11-31)
#include <iostream>
#include <string>
using namespace std ;
class Date
{
public:
Date( int = 0, int = 0, int = 0 ) ;
Date( const Date & ) ;
~Date( void ) ;
void display( void ) const ;
private:
int month ;
int day ;
int year ;
char *monthName ;
} ;
Date::Date( int m, int d, int y )
{
static char *mos[] = {
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"Septermber",
"October",
"November",
"December"
} ;
month = m ;
day = d ;
year = y ;
if ( m != 0 ) {
monthName = new char[strlen( mos[m - 1] ) + 1] ;
strcpy( monthName, mos[m - 1] ) ;
}
else
monthName = NULL ;
}
Date::Date( const Date &dt )
{
month = dt.month ;
day = dt.day ;
year = dt.year ;
if ( dt.monthName != NULL ) {
monthName = new char[strlen( dt.monthName ) + 1] ;
strcpy( monthName, dt.monthName ) ;
}
else
monthName = NULL ;
}
Date::~Date( void )
{
delete [] monthName ;
}
void Date::display( void ) const
{
if ( monthName != NULL )
cout << monthName << ' ' << day << ", " << year << endl ;
}
int main()
{
Date birthday( 6, 24, 1940 ) ;
birthday.display() ;
Date newDay = birthday ;
newDay.display() ;
Date lastDay( birthday ) ;
lastDay.display() ;
return 0 ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -