程序见下:
#include
class CDateINfo
{
public:
//默认的构造函数
CDateINfo()
{
cout<<"调用默认的构造函数\n";
m_nYear=2000;
m_nMonth=1;
m_nDay=1;
};
//有参数的构造函数
CDateINfo(int nYear,int nMonth,int nDay)
{
cout<<"调用带参数的构造函数\n";
m_nYear=nYear;
m_nMonth=nMonth;
m_nDay=nDay;
}
//拷贝构造函数
CDateINfo(CDateINfo &data)
{
cout<<"调用拷贝构造函数\n";
m_nYear=data.m_nYear;
m_nMonth=data.m_nMonth;
m_nDay=data.m_nDay;
};
~CDateINfo(){};
//设置日期
void SetDateINfo(int nYear,int nMonth,int nDay)
{
m_nYear=nYear;
m_nMonth=nMonth;
m_nDay=nDay;
};
//打印日期
void PrintDateINfo()
{
cout<<"年:"<
public:
int m_nYear;
int m_nMonth;
int m_nDay;
};
void main()
{
CDateINfo di1(2007,6,18),di2;
di2.PrintDateINfo();
di2.SetDateINfo(2007,1,1);
CDateINfo d3(di1);
di1.PrintDateINfo();
}
你可以不用C++做这么简单的程序,可以使用OFFICE来制作,如果你想体面点,可以下载E语言来制作