int main()
{
Date d1,d2(2008,8,8);
cout<<“d1:”<<d1.GetYear()<<"-"<<d1.GetMonth()<<"-"<<d1.GetDay()<<endl;
cout<<“d2:”<<d2.GetYear()<<"-"<<d2.GetMonth()<<"-"<<d2.GetDay()<<endl;
d1.Set();
d2.Set(2016,12,28);
cout<<“d1:”<<d1.GetYear()<<"-"<<d1.GetMonth()<<"-"<<d1.GetDay()<<endl;
cout<<“d2:”<<d2.GetYear()<<"-"<<d2.GetMonth()<<"-"<<d2.GetDay()<<endl;
}
#include<iostream>
using namespace std;
class Date
{
private:
int year ,month,day;
public:
Date(int y=2015,int m=5,int d=20):year(y),month(m),day(d){}
~Date(){}
void Set(int y,int m,int d);
void Set();
int GetYear(); //提供对外接口
int GetMonth();
int GetDay();
};
void Date::Set()
{
year=2050;
month=12;
day=1;
}
void Date::Set(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
int Date::GetYear()
{
return year;
}
int Date::GetMonth()
{
return month;
}
int Date::GetDay()
{
return day;
}