首页 > 其他 > 详细

自考新教材--p69

时间:2019-12-03 10:19:08      阅读:90      评论:0      收藏:0      [点我收藏+]

源程序:

#include <iostream>

using namespace std;

class myDate

{

public:

myDate();

myDate(int,int,int);

void setDate(int,int,int);

void setDate(myDate);

myDate getDate();

void setYear(int);

int getMonth();

void printDate() const;

private:

int year, month, day;

};

 

//在类体外定义成员函数

myDate::myDate()

{

year = 1970;

month = 1;

day = 1;

}

myDate::myDate(int y, int m, int d)

{

year = y;

month = m;

day = d;

}

void myDate::setDate(int y, int m, int d)

{

year = y;

month = m;

day = d;

return;

}

void myDate::setDate(myDate oneD)

{

year = oneD.year;

month = oneD.month;

day = oneD.day;

return;

}

myDate myDate::getDate()

{

return *this;

}

void myDate::setYear(int y)

{

year = y;

return;

}

int myDate::getMonth()

{

return month;

}

void myDate::printDate() const

{

cout << year << "/" << month << "/" << day;

return;

}

 

int main()

{

myDate A;

myDate M;

myDate N(1995,8,30);

M.setDate(2001,12,23);

M.printDate();

cout << endl;

N.printDate();

cout << endl;

M.setDate(A);

A.printDate();

cout << endl;

system("pause");

return 0;

}

 运行结果:

技术分享图片

自考新教材--p69

原文:https://www.cnblogs.com/duanqibo/p/11974839.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!