第三章作业3.24

来源:互联网 发布:云计算 电子政务 编辑:程序博客网 时间:2024/06/14 09:44
# include <iostream>
using namespace std;
class Date{
public :
void printDate();
void GetYear();
void GetMonth();
void GetDay();
void SetDate(int y,int m,int d);
private:
int year;
int month;
int day;
};
void Date::printDate()
{
cout<<year<<"."<<month<<"."<<day<<endl;
}
void Date::GetYear()
{
cout<<"该日期年份"<<" "<<year<<endl;
}
void Date::GetMonth()
{
cout<<"该日期月份"<<" "<<month<<endl;
}
void Date::GetDay()
{
cout<<"该日期"<<" "<<day<<endl;
}
void Date::SetDate(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
int main()
{
Date d1,d2,d3;
d1.SetDate(2010,6,8);
d1.printDate();
d1.GetYear();
d1.GetMonth();
d1.GetDay();
cout<<"************"<<endl;
d2.SetDate(2015,4,1);
    d2.printDate();
d2.GetYear();
d2.GetMonth();
d2.GetDay();
    cout<<"************"<<endl;
d3=d1;
    cout<<"复制d1的日期"<<endl;
    d3.printDate();
d3.GetYear();
d3.GetMonth();
d3.GetDay();
    return 0;
}
0 0
原创粉丝点击