(15.,2应用举例】 15.2.1派生类使用例-公司雇员档案的管理 假设公司雇员分为:雇员( employee)、经理( manager) 工程师( engineer)、高级主管( director)。而且假定只关心这几 类雇员各自的如下一些数据 employee(雇员)类:姓名、年龄、工资; manager(经理)类:姓名、年龄、工资、行政级别; engineer((工程师)类:姓名、年龄、工资、专业、学位; director(高级主管)淡:姓名、年龄、工资、专业、学位、职
15.2.1 派生类使用例 -- 公司雇员档案的管理 假设公司雇员分为:雇员(employee)、经理(manager)、 工程师(engineer)、高级主管(director)。而且假定只关心这几 类雇员各自的如下一些数据: employee(雇员)类: 姓名、年龄、工资; manager(经理)类: 姓名、年龄、工资、行政级别; engineer(工程师)类: 姓名、年龄、工资、专业、学位; director(高级主管)类:姓名、年龄、工资、专业、学位、职务。 【 15.2 应用举例】
#include <iostream. h> #include <string. h> class employee t/ employed6类(类型),将作为其它几个类的基类 short age float salary protected char s name public: employee(short ag, float sa, char* na)i age-ag, salary=sa; name=new charstrlen (na)+1; strcpy(name, na); void print o const( cout<<p <name<<":"; cout<sage<s: cout<<salary<<endl employee delete name j
#include <iostream.h> #include <string.h> class employee { //employee类(类型),将作为其它几个类的基类 short age; float salary; protected: char * name; public: employee (short ag, float sa, char * na){ age=ag; salary=sa; name=new char[strlen(na)+1]; strcpy(name,na); } void print () const{ cout<<" "<<name<<": "; cout<<age<<" : "; cout<<salary<<endl; } ~employee() {delete[ ]name;} };