您的位置:首页 > 其它

66.6 设计一个雇员类 employee,存储雇员的姓名、编号和生日等信息,要求该类使用 上一题设计的日期类作为成员对象。雇员类的使用如下: //定义一个雇员,其雇员号为 10,生日为 1970 年

2016-07-29 23:12 1056 查看
#define _CRT_SECURE_NO_WARNINGS

/*

66.6 设计一个雇员类 employee,存储雇员的姓名、编号和生日等信息,要求该类使用

上一题设计的日期类作为成员对象。雇员类的使用如下:

//定义一个雇员,其雇员号为 10,生日为 1970 年 11 月 25 日,姓名为 Jane

employee jane("Jane",10,1970,11,25);

Date today’

if (jane.IsBirthday(today)) //判断今天是否为 Jane 的生日

//...

*/

#include <iostream>

using namespace std;

class Date

{

public:
int y, m, d;

public:
Date()
{

}
Date(int y, int m, int d)
{
this->y = y;
this->m = m;
this->d = d;
}
Date(Date &d)
{
*this = d;
}
void GetDate() //取日期值,格式如“2001 年 2 月 5 日”
{
cout << y << "年" << m << "月" << d << "日" << endl;
}
void GetYear() //取年份
{
cout << y << "年" << endl;
}
void GetMonth() //取月份
{
cout << m << "月" << endl;
}
void GetDay()//取日期
{
cout << d << "日" << endl;
}
void SetDate(int y, int m, int d)//设置日期值
{
this->y = y;
this->m = m;
this->d = d;
}

};

class employee

{
char name[20];
int num;
Date birth;

public:
employee(char name[], int num, int y, int m, int d)
{
strcpy(this->name, name);
this->num = num;
this->birth.y = y;
this->birth.m = m;
this->birth.d = d;
}
bool IsBirthday(Date date)
{

if ((this->birth.m == date.m) && (this->birth.d == date.d))
{
return true;
}
return false;
}

};

void main()

{
employee jane("Jane", 10, 1970, 11, 25);
Date today(2016,11,25);
if (jane.IsBirthday(today)) //判断今天是否为 Jane 的生日
{
cout << "Happy birthday!!!" << endl;
}

system("pause");

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: