下面程序有问题,请大侠根据题目和我编的改一下。最好说明一下,感激不尽。会加分的。
课程设计内容:
1.某学校职工,有从事行政工作的行政人员,有从事教学工作的教师,有兼有两者身份的辅导员。每种不同的人员工资的算法不同,行政人员根据级别拿固定工资,教师根据上课时数计算工资,辅导员两者兼有。
提示:
建立基类职工类,定义基本的属性与成员
行政人员与教师类从职工类继承
辅导员从行政人员与教师类共同派生,注意虚基类的设置。
计算工资的函数,设置为虚函数,不同的类有不同的计算方法,主函数中采用运行多态实现动态绑定。
#include<iostream>
#include<string>
using namespace std;
class worker{
public:
virtual void calculate(){
wage=2000;
cout<<"wage :"<<wage<<endl;}
virtual void work(){cout<<"职工"<<endl;}
void information(){cout<<"name:"<<name<<endl;
cout<<"id:"<<id<<endl;}
protected:
float wage;
string name;
string id;
};
class admonistration:virtual public worker{
public:
admonistration()
{cout<<"请输入名字"<<endl;
cin>>name;
cout<<"请输入编号"<<endl;
cin>>id;
cout<<"请输入奖金"<<endl;
cin>>bonus;}
void calculate(){
wage=2000+bonus;
cout<<"wage :"<<wage<<endl;};
void work(){cout<<"从事行政工作的行政人员"<<endl;}
private:
float bonus;
};
class teacher:virtual public worker{
public:
teacher(){cout<<"请输入名字"<<endl;
cin>>name;
cout<<"请输入编号"<<endl;
cin>>id;
cout<<"请输入课时"<<endl;
cin>>count;}
virtual void calculate(){
wage=2000+80*count;
cout<<"wage :"<<wage<<endl;
};
void work(){cout<<"从事教学工作的教师"<<endl;}
private:
int count;
};
class counstor: public admonistration,public teacher{
public:
counstor(){cout<<"请输入名字"<<endl;
cin>>name;
cout<<"请输入编号"<<endl;
cin>>id;
cout<<"请输入奖金"<<endl;
cin>>bonus;}
void calculate(){
wage=2000+bonus;
cout<<"wage :"<<wage<<endl;};
void work(){cout<<"兼有两者身份的辅导员"<<endl;}
private:
float bonus;
};
int main(){
teacher t();
admonistration a();
counstor c();
worker *pw[]={&t,&a,&c};
for(int f=0;f<3;f++)
{
pw[f]->calculate();
pw[f]->work();
pw[f]->information();
}
return 0;
}