g
图4.2类的层次结构图
5 程序类的说明
总职工类的声明 class Person //员工类 {
protected:
int No; //编号 char Name[20]; //姓名 int Duty; //岗位 double Earning; //收入 Person *next;
public:
Person(char ID,char *Name,int Duty) {
this->Duty=Duty;
strcpy(this->Name,Name); this->No=ID; }
virtual void CalcSalary()=0; virtual void Output()=0; friend class Company;
}; 技术员类的声明
class technician:virtual public Employee { public:
g
technician() {}
virtual void shanchu() {*name=*sex=0;number=age=hour=0;pay1=0;} void wage() { pay1=100*hour;} virtual void print() { }
void input() { } protected: int hour,pay1; };
经理类的声明
class Manager:public Person //经理类 { public:
Manager(char ID,char *Name,int Duty):Person(ID,Name,Duty){} void CalcSalary(){Earning=ManagerSalary;} void Output() {
CalcSalary();
cout<<No<<"\t"<<Name<<"\t经理\t"<<Earning<<endl; }
};
wage();
cout<<"技术员员工号:"<<number<<" "
<<"姓名:"<<name<<" " <<"性别:"<<sex<<" " <<"年龄:"<<age<<" " <<"工资:"<<pay1<<endl;
Employee::input();
cout<<"工作时间(以小时计算)"<<endl; cin>>hour;