软题库 移动APP 扫码下载APP 随时随地移动学习 培训课程
当前位置:信管网 >> 在线考试中心 >> 信息系统项目管理师题库 >> 试题查看
试卷名称 2010年上半年程序员考试下午真题试题(案例分析)
考试中心《2010年上半年程序员考试下午真题试题(案例分析)》在线考试
试卷年份2010年上半年
试题题型【分析简答题】
试题内容

阅读以下说明和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 << "请输入当月工资总和与员工数:" << end1;
     cin  >> sumSalary  >> employeeNumber;
     float  k=average(sumSalary,employeeNumber);
     cout  <<  "平均工资: "<<  k  <<  end1;
}
(2)(int e) {
if(e = =0) {
    cout << "请重新输入当月工资总和与员工数 :" << end1;
    cin  >>  sumSalary  >>  employeeNumber;
    float k =average(sumSalary,employeeNumber);
    cout  <<  "平均工资: "<<  k  <<  end1;
  }
 }
}
};
 
void  main ( ) {
try  {
(3);
d.caculate ( );
}
(4)(int  e) {
if  (  e = = 0)
cout <<  "程序未正确计算平均工资! " << end1;
}

【问题 1】
程序运行时,若输入的员工工资总和为6000,员工数为5,则屏幕输出为:
请输入当月工资总和与员工数:
6000 5
(5)
【问题 2】
若程序运行时,第一次输入的员工工资总和为6000,员工数为0,第二次输入的员工工资总和为0,员工数为0,则屏幕输出为:
请输入当月工资总和与员工数:
6000 0
(6)   
0 0
(7)


相关试题

推荐文章
合作网站内容