首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
使用VC6打开考生文件夹下的源程序文件modil.cpp,但该程序运行时有错,请改正main()函数中的错误,使程序的输出结果如下: Constructor. Default constructor. Area is 12
使用VC6打开考生文件夹下的源程序文件modil.cpp,但该程序运行时有错,请改正main()函数中的错误,使程序的输出结果如下: Constructor. Default constructor. Area is 12
admin
2017-11-27
12
问题
使用VC6打开考生文件夹下的源程序文件modil.cpp,但该程序运行时有错,请改正main()函数中的错误,使程序的输出结果如下:
Constructor.
Default constructor.
Area is 12
Area is 0
Area is 12
注意:错误的语句在//*****error******的下面,修改该语句即可。
#include
class CRectangle
{
private:
double length,width;
public:
CRectangle()
{
cout<<"Default
constructor.\n";
}
CRectangle(double 1,double w)
{
length=1;width=w;
cout<<"Constructor .\n";
}
void Set(double 1,double w)
{
this->length=1;
this->width=w;
}
void GetArea()
{
cout<<"Area is"<
width<
}
}
void main()
{
CRectangle Rect1(3.0,4.0);
//*****error******
CRectangle Rect2(1);
//*****error******
Rect1.GetArea();
//*****error******
Rect2.Set(0);
Rect2.GetArea();
Rect3.GetArea();
}
选项
答案
(1)CRectangle Rect2; (2)CRectangle Rect3(Rect1); (3)Rect2.Set(0,0);
解析
(1)构造函数CRectangle()不带有参数,CRectangle(double1,double w)带有2个参数,在创建对象时会自动调用构造函数,但是参数必须匹配,第1个标识下定义Rect2对象时,有一个参数,而类CRectangle()并没有重载一个参数的构造函数,编译后出错,因此第1标识下应改为“CRectangle Rect2;”。
(2)Rect3.GetArea()输出的结果和Rect1.GetArea()输出结果一致,因此对象Rect3和对象Rect1两者具有相同的length和width值,除定义Rect3对象之外没有改变Rect31的length和width值,因此Rect3成员变量的初始化是通过拷贝构造函数类实现的,即用Rect1对象去初始化Rect3,因此第2个标识下应改为“CRectangle Rect3(Rect1);”。
(3)Rect2.GetArea()的输出结果为0,说明Rect2的成员变量length和width值至少一个为0,而Set()函数必须有两个参数,这里Rect2.Set(0)参数不匹配,应改为“Rect2.Set(0,0);”或者“Rect2.Set(0,5)”,两个参数当中至少一个为0即可。
转载请注明原文地址:https://jikaoti.com/ti/Eit0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
一个类中有【 】个构造函数。
如果一个对象部分地包含自己,或自己定义自己,则称这个对象是【 】的对象。
析构函数的特征包括
以下使用不当会破坏面向程序设计特性的是
设有定义 class C { public: int value; … }; int x, * p; 则以下引用形式中,正确的是
设有如下关系表:则下列操作中正确的是
如果一个工人可管理多个设备,而一个设备只被一个工人管理,则实体“工人”与实体“设备”之间存在______关系。
有如下类声明:classFoo{intbar;};则Foo类的成员bar是
数据模型分为格式化模型和非格式化模型,则关系模型属于【 】模型。
( )是以一种完全通用的方法来设计函数或类而不必预先说明将被使用的每个对象的类型。
随机试题
用不了几十年,人工智能就会超越多种人类自认独有的能力。对我们这一代人来说,这是个巨大的挑战,也许我们需要“非理性”地应对。计算机占领了曾专属于人类的工作——那些需要知识、策略甚至创造力的工作。在这种“劳动分工”之下,我们应把人类的工作定位在与机器互补,而非
血液凝固:
患者,男性,52岁。因胸闷、胸痛4小时入院。入院查体:血压86/60mmHg,心率44次/分,律齐。心电图示:Ⅱ、Ⅲ、aVF导联ST段抬高、Q波形成。其心律失常最可能的是
该患儿最可能的诊断是哪种检测方法有助于诊断和治疗
女性,50岁,畏寒、发热伴剧烈腰痛5天,T39℃,左肾区明显扣痛,血WBC11.8×109/L,N80%,尿常规提示尿蛋白(+),WBC10/HP。最可能的诊断是
在宪法文本的不同部分,“国家”一词的内涵与表现形式是不同的。在我国宪法中,主要是在三种意义上使用该词:一是在统一的政治实体意义上使用的“国家”;二是在与社会相对的意义上使用的“国家”:三是在与地方相对的意义上使用的“国家”。下列哪些选项是在第一种意义上使用
《旅行社条例》规定,县级以上各级人民政府()等有关部门,应当按照职责分工,依法对旅行社进行监督管理。
图书不同于报纸和期刊的主要特点有()。
“落雁”指的是我国四大美女中的()。
设f(x)=a1ln(1+x)+a2ln(1+2x)+…+anln(1+nx),其中a1,a2,…,an为常数,且对一切x有|f(x)|≤|ex-1|,证明|a1+2a2+…+nan|≤1.
最新回复
(
0
)