#include <iostream.h>
class Date{
protected:
int year;
int month;
int day;
bool Isleapyear;
public:
Date(){};//构造函数无返回类型
Date(int year,int month,int day);
~Date(){};//析构函数无返回类型
int &GetYear(){return year;}
int &GetMonth(){return month;}
int &GetDay(){return day;}
void panduan(){Isleapyear=false;//平年闰年判断函数
if(year%100==0)
{if(year%400==0) Isleapyear=true;}
else {if(year%4==0) Isleapyear=true;} ;
if(Isleapyear==true) cout<<"\n该年是闰年";
else cout<<"\n该年是平年";
}
};
Date::Date(int year,int month,int day){
(*this).year=year;
(*this).month=month;
(*this).day=day;
}
void main(){
int year,month,day;
cin>>year>>month>>day;
Date mydate(year,month,day);
int &myyear=mydate.GetYear();
int &mymonth=mydate.GetMonth();
int &myday=mydate.GetDay();
cout<<myyear<<endl<<mymonth<<endl<<myday<<endl;
mydate.panduan();
}
测试通过,运行如下:
2000
12
2
该年是闰年