参考答案:
详细解析:
阅读以下说明和C++代码,填补C++代码中的空缺(1)~(6),将解答写在答题纸的对应栏内。
【说明】
已知某公司按周给员工发放工资,其工资系统需记录每名员工的员工号、姓名、工资等信息。其中一些员工是正式的,按年薪分周发放(每年按52周计算);另一些员工是计时工,以小时工资为基准,按每周工作小时数核算发放。
下面是实现该工资系统的C++代码,其中定义了四个类:工资系统类PayRoll,员工类Employee,正式工类Salaried和计时工类Hourly,Salaried和Hourly是Employee的子类。
【C++代码】
//头文件和域名空间略
const int EMPLOYEE_NUM=5;
class Employee {
protected:
int empCode; //员工号
string name; //员工姓名
double salary; //周发放工资
public:
Employee(const int empCode, const string &name ) {
this->empCode=empCode; this->name=name;
}
virtual ~Employee(){ }
virtual void pay()=0;
double getSalary() { return this->salary; }
};
class Salaried (1) {
private: double payRate; //年薪
public:
Salaried(const int empCode, const string &namet double payRate):Employee (empCode, name) {
this->payRate=payRate;
}
void pay() {
this->salary= (2) ; //计算正式员工的周发放工资数
cout << this->name << ":" << this->salary<
class Hourly (3) {
private:
double payRate; //小时工资数
int hours; //周工作小时数
public:
Hourly (const int empCode. const string &name, int hours, double payRate)
:Employee(empCode, name) {
this->payRate=payRate; this->hours=hours;
}
void pay() {
this->salary= (4) ; //计算计时工的周发放工资数
cout << this->name << ":" << this->salary << endl;
}
};
class PayRoll {
public:
void pay (Employee*e[]) {
for (int i=0; i
}
}
};
int main() {
PayRoll payRoll=new PayRoll;
(5) employees [EMPLOYEE_NUM]= {
new Salaried (1001, "Zhang San", 58000.00),
//此处省略对其他职工对象的生成
new Hourly (1005, "Li", 12, 50.00),
};
payRoll->pay( (6) );
double total=0.0;
for (int i=0; i
cout<<"总发放额="<
}
参考答案:
详细解析: