问答题

请使用VC6或使用【答题】菜单打开考生文件夹prog1下的工程prog1,该工程中包含程序文件main.cpp,其中有Salary(“工资”)类和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句行有错误,请加以改正。改正后程序的输出结果应为:应发合计:3500应扣合计:67.5实发工资:3432.5注意:只修改每个“//ERROR****found****”下的那一行,不要改动程序中的其他内容。#include<iostream>usingnamespacestd;classSalary{public:Salary(constchar*id,doublethe_base,doublethebonus,doublethe_tax)//ERROR**********found**********:thebase(base),thebonus(bonus),thetax(tax){staffid=newchar[strlen(id)+1];strcpy(staffid,id);}//ERROR**********found**********~Salary(){delete*staffid;)doublegetGrossPay()const{returnbase+bonus;}//返回应发项合计doublegetNetPay()const{returngetGrossPay()_tax;}//返回实发工资额private:char*staffid;//职工号doublebase;//基本工资doublebonus;//奖金doubletax;//代扣个人所得税};intmain(){Salarypay("888888",3000.0,500.0,67.50);cout<<"应发合计:"<<pay.getGrossPay()<<"";cout<<"应扣合计:"<<pay.getGrossPay()-pay.getNetPay()<<"";//ERROR**********found**********cout<<"实发工资:"<<pay::getNetPay()<<end1;return0;}

【参考答案】

正确答案:(1):base(the_base),bonus(the_bonus),tax(the_tax) (2)~Sa......

(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)