【简答题】
试题五(共15分)
阅读以下说明和C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明】
现需要统计某企业员工的月平均工资,即该企业本月发给员工的工资总和除以员工数。假设企业本月发给员工的工资总和为sumSalary,该企业的员工总数为employeeNumber,下面的程序代码计算该企业员工本月的平均工资,其中需要处理employNumber为0的情况。【C++代码】
#include <iostream>
using namespace std;
class Department{
protected:
float average(float x, int y){
if (y ==0 ) throw (1) ;
return x/y;
}
public:
void caculate(void){
float sumSalary;
int employeeNumber;
try{
cout << "请输入当月工资总和与员工数:" << endl;
cin >> sumSalary >> employeeNumber;
float k = average(sumSalary,employeeNumber);
cout << "平均工资:"<< k << endl;
}
(2) (int e){
if(e == 0){
cout << "请重新输入当月工资总和与员工数:" << endl;
cin >> sumSalary >> employeeNumber;
float k = average(sumSalary,employeeNumber);
cout << "平均工资:"<< k << endl;
}
}
}
};
void main(){
try {
(3) ;
d.caculate();
}
(4) (int e){
if ( e == 0)
cout << "程序未正确计算平均工资!" << endl;
}
}
【问题1】
程序运行时,若输入的员工工资总和为6000,员工数为5,则屏幕输出为:
请输入当月工资总和与员工数:
6000 5
(5)
【问题2】
若程序运行时,第一次输入的员工工资总和为6000,员工数为0,第二次输入的员工工资总和为0,员工数为0,则屏幕输出为:
请输入当月工资总和与员工数:
6000 0
(6)
0 0
(7)