出国留学--美国商学院申请流程 联系客服

发布时间 : 星期五 文章出国留学--美国商学院申请流程更新完毕开始阅读27fb277401f69e3142329407

return st;

}

6.(15分)

某公司有二类职员Employee和Manager,Manager亦属于Employee。每个Employee对象所具有的基本信息为:姓名、年令、工作年限、部门号,Manager对象除具有上述基本信息外,还有级别(level)信息。公司中的二类职员都具有二种基本操作:

1). printOn() // 输出个人信息

2). retire() // 判断是否到了退休年令,是,则从公司中除名。公司规定:

// Employee类的退休年令为55岁,Manager类的退休年令为60岁。

要求:

1). 定义并实现类Employee和Manager;

2). 分别输出公司中二类职员的人数(注意:Manager亦属于Employee)。

答案:

#include

#include

class Employee{

char name[21];

int workYear;

int departmentNum;

protected:

static int ENumber;

int age;

public:

Employee(char* s, int age1, int workYear1, int depN)

{ if(strlen(s)<=20 && *s!='\\0') strcpy(name,s);

if(age1>=18 && workYear1>=0 && depN>0)

{ age=age1;

workYear=workYear1;

departmentNum=depN;

Employee::ENumber++;

}

}

virtual void printOn()

{cout<

virtual void retire(Employee& e)