请使用VC6或使用【答题】菜单打开考生文件夹progl下的工程progl,该工程中包含程序文件main.cpp,其中有Salary(“工资”)类和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句行有错误,请加以

admin2021-05-06  23

问题 请使用VC6或使用【答题】菜单打开考生文件夹progl下的工程progl,该工程中包含程序文件main.cpp,其中有Salary(“工资”)类和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句行有错误,请加以改正。改正后程序的输出结果应为:
    应发合计:3500应扣合计:67.5  实发工资:3432.5
    注意:只修改每个“//ERROR****found****”下的那一行,不要改动程序中的其他内容。
#include
using namespace std;
class Salary{
public:
  Salary(const char * id,double the_base,double the_bonus,double the_tax)
//ERROR  ********found********
    :the base(base),the bonus(bonus),the tax(tax)
    {
    staff id=new char[strlen(id)+1];
    strcpy(staff id,id);
    }
//ERROR********found********
  ~Salary(){delete*staff_id;}
  double getGrosSPay()const {return base+bonus;} //返回应发项合计
  double getNetPay()const{return getGrossPay()-tax;)//返回实发工资额
private:
  char*staff id;  //职工号
  double base;  //基本工资
  double bonus;  //奖金
double tax;  //代扣个人所得税
};
int main(){
  Salary pay("888888",3000.0,500.0,67.50);
  tout<<"应发合计:"<  cout<<"应扣合计:"<//ERROR**********found**********
  cout<<"实发工资:"<  return 0;
}

选项

答案(1):base(the_base),bonus(the_bonus),tax(the_tax) (2)~Salary(){delete[] staff_id;} (3)cout<<"实发工资:"<
解析 (1)主要考查考生对构造函数的掌握情况,构造函数的成员初始列表要把形参放在括号内。
    (2)主要考查考生对析构函数的掌握情况,析构函数使用delete释放指针,delete后要跟标识符“[]”。
    (3)主要考查考生对成员函数调用的掌握情况,调用类的成员函数使用标识符“.”,而不是作用域符“::”。
转载请注明原文地址:https://kaotiyun.com/show/FTfp777K
0

最新回复(0)