#include<iostream>
using namespace std;
class Date
{
public:
Date();
Date(int y,int m,int d);
void GetYear();
void GetMonth();
void GetDay();
void SetDate(int y,int m,int d);
void printDate()
{
cout<<"日期是:"<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
}
private:
int year;
int month;
int day;
};
Date::Date()
{year=2015;
month=4;
day=2;
}
Date::Date(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
void Date::GetYear()
{cout<<"the year:"<<year<<endl;
}
void Date::GetMonth()
{
cout<<"the month:"<<month<<endl;
}
void Date::GetDay()
{
cout<<"the day:"<<day<<endl;
}
void Date::SetDate(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
int main()
{ Date d1(2010,6,8);
d1.printDate();
Date d2;
d2.printDate();
Date d3(d1);
d3.GetYear();
d3.GetMonth();
d3.GetDay();
d3.printDate();
return 0;
}
作业3.24
最新推荐文章于 2022-03-25 10:09:11 发布