首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请打开考生文件夹下的解决方案文件proj1,此工程中含有一个源程序文件proj1.cpp”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: Constructor called. The value is 10 Max
请打开考生文件夹下的解决方案文件proj1,此工程中含有一个源程序文件proj1.cpp”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: Constructor called. The value is 10 Max
admin
2019-04-24
29
问题
请打开考生文件夹下的解决方案文件proj1,此工程中含有一个源程序文件proj1.cpp”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为:
Constructor called.
The value is 10
Max nllmber is 20
Destruetor called.
注意:只能修改注释“//ERROR****found****”的下一行语句,不要改动程序中的其他内容。
1 //proj1.cpp
2 #include
3 using namespace std;
4
5 class MyClass {
6 public:
7 //ERROR ********found********
8 void MyClass(int i)
9 {value=i;cout<<"Con structor called."<
10
11 int Max(int x,int y){return x>y?x:y;}//求两个整数的最大值
12
13 //ERROR ********found********
14 int Max(int x,int y,int z=0)
15 //求三个整数的最大值
16 {
17 if(x>y)
18 return x>z?x:z ;
19 else
20 return y>z?y:z ;
21
22
23 int GetValue()const { return value;}
24
25 ~MyClass () {cout<<"De structor called."<
26
27 private:
28 int value;
29 };
30
3l int main()
32 f
33 MyClass obj(10);
34 //ERROR********found********
35 cout<<"The value is" << value()<
36 cout<<"Max number is" << obj.Max(10,20)<
37 return 0;
38 }
选项
答案
(1)MyClass(int i) (2)int Max(int x,int y,int z) (3)cout<<"The value is"<
解析
(1)考查构造函数,构造函数前不加void或其他任何类型名,直接使用MyClass(int i)即可。
(2)主要考查函数重载,在int Max(int x,int y) {return x>y?x:y;}中两个形参变量都是int型,而语句int Max(int x,inty,int z=0)的前两个形参也都是int型,第三个形参定义默认值,那么这两个Max函数在调用时它们的参数个数和参数类型都一样,因为函数重载要求形参类型或形参个数不同,所以要把int z=0改为int z,才能构成函数重载。
(3)主要考查成员函数的调用,因为value是私有成员,所以不能被类外函数直接调用,而且value()的用法也是错误的,可以使用成员函数obj.GetValue()得到value的值。
转载请注明原文地址:https://jikaoti.com/ti/OYt0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
如下程序的输出结果是______。#include<iostream>usingnamespacestd;classWages{//“工资”类doublebase;//基本工资dou
请在下列程序中的空格处填写正确的语句:classSample{public:Sample(){}~Sample(){}voidSetData(intdatA){//将Sample类成员变量d
指针数组是由______构成的数组。
下列程序的输出结果是()。#include<iostream>usingnamespacestd;voidfun(int&r){r*=2;}intmain(){int
以下程序运行后的输出结果是()。#include<iostream.h>voidmain(){charaft="abbcabbcabbc";inti=0,j=0,k=0;while(a[i
下列函数的功能是判断字符串str是否对称,对称则返回true,否则返回false,则横线处应填上()。Boolfun(char*str){inti=0,j=0;while(str[j])j++;for(j
软件生命周期可分为多个阶段,一般分为定义阶段、开发阶段和维护阶段。编码和测试属于______阶段。
有如下头文件:intf1();staticintf2();classMA{public:intf3();staticintf4();};在所描述的函数中,具有隐含的thi
语句int*p=&k;定义了指针p,与这个语句等效的语句序列是
下面不属于C++的预定义的流对象是()。
随机试题
绘画是原始艺术的主要样式之一,它的主题多是早期人类的【】
由Stewart—Hamilton关系式得到DSA的提示不包括
A.艾卷灸B.艾炷灸C.温和灸D.温针灸E.天灸白芥子灸属()
急性血源性骨髓炎早期局部穿刺的正确方法是
某企业为了扩大生产规模,拟购置一套新设备。企业管理部门提出A、B两个方案供选择。A方案是购置国产设备,全部购置成本为500万元,预计可使用5年。第1年现金净流量为100万元;第2~4年内,每年现金净流量均为180万元;第5年现金净流量为150万元;
背景资料:某市政H公司承接了一座多跨预应力箱梁桥。该桥为斜拉桥,索塔采用裸塔形式,跨河流段宽度为60m。桥梁基础采用钻孔灌注桩形式,双柱式桥墩,柱高为l8m,桥梁上部结构采用普通钢筋混凝土盖梁。上部结构0号块采用墩顶混凝土现浇施工,临时固结构造示
下面是已公布的2002年我国国际收支平衡表简表,请据此对2002年国际收支情况做一分析,在下列备选答案中选出正确答案。
关于行为治疗的步骤,下列说法中不正确的是()。
编写教材(教科书)的直接依据是()。
A.ImportanceofstayingintellectuallyactiveB.Effectsofagingonaperson’srecallabilityC.Short-termmemoryversuslong-te
最新回复
(
0
)