首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请打开考生文件夹下的解决方案文件proj1,该工程中包含程序文件main.cpp,其中有Salary(“工资”)类和主函数main的定义。程序中位于每个“//ERROR ****found****”之后的一行语句行有错误,请加以改正。改正后程序的输出结果应
请打开考生文件夹下的解决方案文件proj1,该工程中包含程序文件main.cpp,其中有Salary(“工资”)类和主函数main的定义。程序中位于每个“//ERROR ****found****”之后的一行语句行有错误,请加以改正。改正后程序的输出结果应
admin
2019-04-24
35
问题
请打开考生文件夹下的解决方案文件proj1,该工程中包含程序文件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);
cout<<"应发合计:"<
cout<<"应扣合计:"<
//ERROR ********found********
cout<<"实发工资:"<
return 0;
}
选项
答案
(1):base(the_base),bonus(the_honus),tax(the_tax) (2)~Salary(){delete[]staff id;} (3)cout<<"实发工资:"<
解析
(1)主要考查号生对构造函数的掌握情况,构造函数的成员初始列表要把形参放在括号内。
(2)主要考查考生对析构函数的掌握情况,析构函数使用delete释放指针,delete后要跟标识符“[]”。
(3)主要考查考生对成员函数调用的掌握情况,调用类的成员函数使用标识符“.”.而不是作用域符“::”。
转载请注明原文地址:https://kaotiyun.com/show/2OAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
非成员函数应该声明为类______函数才能访问该类的私有成员。
如下程序的输出结果是______。#include<iostream>usingnamespacestd;classWages{//“工资”类doublebase;//基本工资dou
执行以下程序后,输出“*”号的个数是______。#include<iostream.h>main(){inti,j;for(i=1;i<5;i++)for(j=2;j<=i;j++)cout<<’
下列说法中错误的是()
关于运算符重载,下列表述中正确的是()。
假定MyClass为一个类,则该类的拷贝初始化构造函数的声明语句为()
数据管理技术的发展经历了人工管理、文件系统和数据库系统3个阶段,其中数据独立性最高的是______。
指针变量所保存的不是一般的数据值,而是程序中另一个对象的______。
插入排序算法的主要思想是:每次从未排序序列中取出一个数据,插入已排序序列中的正确位置。Insert类的成员函数sort()实现了插入排序算法,请填空。classInsert{public:Insert(int*b0,intn0)
随机试题
“你看我就看”是()。
痢下赤白脓血,脐腹灼痛,饮食减少,口烦口干,舌质红绛少苔,脉细数者,治疗宜选
急性乳腺炎最常见于急性乳腺炎的常见原因是
下列属于机械性肠梗阻的是
下列哪种情形之下,合伙人的继承人可以成为合伙人?
因甲公司不能偿还到期债务,贷款银行向法院提起民事诉讼。2004年6月7日,银行在诉讼中得知市发展和改革委员会已于2004年4月6日根据申请,将某小区住宅项目的建设业主由甲公司变更为乙公司。后银行认为行政机关的变更行为侵犯了其合法债权,于2006年1月9日向
后张预应力筋采用镦头锚固时,高强钢丝宜采用()。
HaveChineseaudiencesonaveragespentmoretimewatchingentertainmentcontentonlineinthisuncommonyearwhenthebattleag
根据以下情境材料,回答下列问题。某日,某城市发生一起恐怖劫持袭击事件,请结合下面图片回答问题:根据我国《反恐怖主义法》的规定,恐怖活动组织是指()人以上为实施恐怖活动而组成的犯罪组织。
记叙文的主要表达方式是()。
最新回复
(
0
)