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