📄 pr11017.cpp
字号:
////////////////////////////////////////
// File Name: pr11017.cpp
////////////////////////////////////////
#include <iostream>
#include <cstring>
////////////////////////////////////////
// Date class.
////////////////////////////////////////
class Date
{
int mo, da, yr;
char *month;
public:
Date(int m = 0, int d = 0, int y = 0);
~Date();
void display() const;
};
// The constructor definition.
Date::Date(int m, int d, int y)
{
static char *mos[] =
{
"January", "February", "March", "April", "May",
"June", "July", "August", "September", "October",
"November", "December"
};
mo = m; da = d; yr = y;
if (m != 0)
{
month = new char[std::strlen(mos[m-1])+1];
std::strcpy(month, mos[m-1]);
}
else
month = 0;
}
// The destructor definition.
Date::~Date()
{
delete [] month;
}
// Display member function.
void Date::display() const
{
if (month != 0)
std::cout << month << ' ' << da << ", " << yr;
}
////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
Date birthday(6,24,1940);
birthday.display();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -