64,637
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
using namespace std;
class Deparment{
protect;
float average(float x, int y){
if(y==0) throw y //第一空;变量y的位置
return x/y;
}
public:
void caculate(void){
float sumSalary;
int employeeNumber;
try{
cout <<"请输入当月工资总和与员工数:"<<endl;
cin<<sunSalary<<employeeNumber;
float k= average(sumSalary,employeeNumber);
cout<<"平均工资:"<<k<<endl;
}
catch/*第二空*/ (int e){
if(e==0){
cout<<"请重新输入当月工资总和与员工数:"<<endl;
cin>>sumSalary>>employeeNumber;
float k = average(sumSalary,employeeNumber);
cout<<"平均工资:“<<k<<endl;
}
}
}
};
void main(){
try{
Department/*第三空*/ d;
d.caculate();
}
catch/*第四空*/(int e){
if(e==0)
cout <<"程序未正确计算平均工资!"<<endl;
}
}
float average(float x, int y) throw (exception & )//定义函数时最好要定义可抛异常的类型
{
if(y==0) throw (new exceprion("0 is divided"); y //第一空;变量y的位置
return x/y;
}
void caculate(void)
{
try
{
...
}
catch(int e)
{
throw;
}
}