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");
}
/*
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");
}
相关文章推荐
- 进制转换
- 6.5 定义一个日期类 Date,该类对象存放一个日期,可以提供的操作有: void GetDate(); //取日期值,格式如“2001 年 2 月 5 日” void GetYear(); //取
- (第15讲)哈希表的开放地址法中的再哈希法
- storm常见错误
- Java工作笔记:部署Tomcat时使用jni和jna调用DLL文件的问题
- Struts2.3+Spring3.2.8+Hibernate4.1全注解配置
- 5.7 编写一个程序,其中有一个函数指针*parea,通过它分别指向计算圆的面积函数 circle 和矩形面积函数 rect 来计算给定圆的面积和矩形面积。
- Q 统计量的计算
- 首次接触Oracle
- VMware虚拟机安装步骤
- 【杭电oj1242】Rescue
- oracle XA session priviledge
- 【JAVA】多态
- 了解程序编译、运行过程
- BZOJ 2151 种树
- storm安装
- HDU 1879 继续畅通工程【Prim】
- 背单词
- Windows下Eclipse+PyDev搭建Python开发环境
- HDU 5768Lucky7(多校第四场)容斥+中国剩余定理(扩展欧几里德求逆元的)+快速乘法