#include<iostream>
using namespace std;
class CDate
{
private:
int Y, M, D;
public:
CDate()
{
Y = 2018, M = 11, D = 21;
}
CDate(int y, int m, int d)
{
Y = y, M = m, D = d;
}
~CDate()
{
cout << "析构函数\n";
}
void SetTime(int y, int m, int d);
void print();
};
void CDate::SetTime(int y, int m, int d) //设置时间
{
Y = y, M = m, D = d;
}
void CDate::print()//输出时间
{
cout << Y << "年-" << M << "月-" << D << "日\n";
}
void main()
{
CDate c1, c2(2000, 1, 1);
c1.print();
c2.SetTime(2018, 11, 11);
c2.print();
system("pause");
}
Last modification:December 5th, 2018 at 07:05 pm
© 允许规范转载