首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
使用VC6打开考生文件夹下的源程序文件modil.cpp,但该程序运行时有错,请改正main()函数中的错误,使程序的输出结果如下: Constructor. Default constructor. Area is 12
使用VC6打开考生文件夹下的源程序文件modil.cpp,但该程序运行时有错,请改正main()函数中的错误,使程序的输出结果如下: Constructor. Default constructor. Area is 12
admin
2017-09-20
25
问题
使用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 Rectl(3.0,4.0);
∥********error********
CRectangle Rect2(1);
∥********error********
CRectangle Rect3;
Rectl.GetArea();
∥********error********
Rect2.Set(0);
Rect2.GetArea();
Rect3.GetArea();
}
选项
答案
(1)CRectangle Rect2; (2)CRectangle Rect3(Rectl); (3)Rect2.Set(0,0);
解析
程序中定义了类CRectangle,有length和width两个成员变量,两个构造函数,Set()成员函数和GetArea()成员函数,Set()成员函数可以改变length和width的值,GetArea()成员函数在屏幕上打印length和width的积。
转载请注明原文地址:https://kaotiyun.com/show/ATAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
在面向对象程序设计中,从外面看只能看到对象的外部特征,而不知道也无须知道数据的具体结构以及实现操作的算法,这称为对象的______。
若类A和类B的定义如下:#include<malloc.h>classA{inti,j;public:intgeti(){returni;}};classB:
非成员函数只有在声明为(),才能访问这个类的所有private成员。
下列程序的运行结果是()。#include< iostream.h>voidfun(int*a,int*b){int*kk=a;a=b;b=k}voidmain(){inta=2004,
在用class定义一个类时,数据成员和成员函数默认的访问权限是【】:
有如下类声明:classMyBASE{intk;public:voidset(intn){k=n;}intget()const{returnk;}};classMyDERI
下列关于运算符重载的描述中,正确的是()。
作为非成员函数重载的运算符,所有操作数都必须以______的形式出现在参数表中。
在一个容量为24的循环队列中,若头指针front=8,尾指针rear=3,则该循环队列中共有______个元素。
执行完下列代码段之后:boolx=true,y=false,z=false;x=x&&y||z;y=x||y&&z;z=!(x!=y)||(y==z);则x=false,y=false,z=(
随机试题
不能用无色试剂瓶来贮存配好的标准溶液是()。
糖的有氧氧化终产物是()
诊断积聚的关键是
A.糖醇B.寡糖C.单糖D.多糖E.糖原糖类中最简单的碳水化合物是()
下列不属于事故预警构建原则的是()。
保税仓库和出口监管仓库的区别是保税仓库设在保税区,出口监管仓库设在出口加工区。
Ihadnosoonerreachedhomethanitbegantorain.
必须用一对大括号括起来的程序段是()。
【S1】【S8】
说明:假定你是中学生周明,生活中遇到一些难题,向报纸的情感专栏Armie求助。内容:周明一直以为自己在学校人缘很好,但一次偶然发现好友几天前举办生日晚会的时候没有邀请他,而班里大部分同学都去了。他很伤心,但不知道怎么办,请Armie帮助解决这个问题。
最新回复
(
0
)