首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
使用VC++6.0打开考生文件夹下的源程序文件3.cpp,其中定义了用于表示矩形的CRect类,但类CRect的定义并不完整。请按要求完成下列操作,将类CRect的定义补充完整。 (1)定义私有数据成员leftPoint、topPoint、righ
使用VC++6.0打开考生文件夹下的源程序文件3.cpp,其中定义了用于表示矩形的CRect类,但类CRect的定义并不完整。请按要求完成下列操作,将类CRect的定义补充完整。 (1)定义私有数据成员leftPoint、topPoint、righ
admin
2013-11-15
25
问题
使用VC++6.0打开考生文件夹下的源程序文件3.cpp,其中定义了用于表示矩形的CRect类,但类CRect的定义并不完整。请按要求完成下列操作,将类CRect的定义补充完整。
(1)定义私有数据成员leftPoint、topPoint、rightPoint、bottomPoint,分别用于表示矩形左上角及右下角的点的坐标,它们都是double型的数据。请在注释1之后添加适当的语句。
(2)完成默认构造函数CRect的定义,指定默认实参为0,它们都是double型的数据。请在注释2之后添加适当的语句。
(3)定义函数体为空的析构函数。请在注释3之后添加适当的语句。
(4)在main函数中定义CRect类的实例rect2,并把rect1的值赋给rect2。请在注释4之后添加适当的语句。
注意:除在指定位置添加语句之外,不要改动程序中的其他内容。
试题程序:
#include
class CRect
{
private:
//********1********
public:
//********2********
//********3********
void SetPoints(double,double,double,double);
void SetLeftPoint(double m){1eftPoint=m;}
void SetRightPoint(double m){rightPoint=m;)
void SetTopPoint(double m){topPoint=m;}
void SetBottomPoint(double m){bottomPoint=m;}
void Display();
};
CRect::CRect(double 1,double t,double r,double b)
{
leftPoint=1;topPoint=t;
rightPoint=r;bottomPoint=b;
}
void CRect::SetPoints(double 1,double t,double r,
double b)
{
leftPoint=1;topPoint=t;
rightPoint=r;bottomPoint=b;
}
void CRect::Display()
{
cout<<"left-top point is("<<1eftPoint<<","<
<<")"<<’\n’;
cout<<"right-bottom point is("<
<
}
void main()
{
CRect rectO;
rect0.Display();
rect0.SetPoints(20,20.6,30,40);
rect0.Display();
CRect rect1(O,0,150,150);
rect1.SetTopPoint(10.5);
rect1.SetLeftPoint(10.5);
//********4********
rect2.Display();
}
选项
答案
(1)应添加“double leftPoint,topPoint,rightPoint,bottomPoint;”。 (2)应添加“CRect(double leftPoint=0,double topPoint=0,double rightPoint=0,double bottomPoint=0);”。 (3)应添加“~CRect(){}”。 (4)应添加“CRec reet2(rect1);”。
解析
本题在第1处完成私有数据成员leftPoint、topPoint、rightPoint、bottomPoint的定义,均为double型的变量,故第1处应添加“double leftPoint,topPoint,rightPoint,bottomPoint;”。
构造函数完成成员变量的初始化,类CRect的默认构造函数初始化double型私有数据成员leftPoint、topPoint、rightPoint、bottomPoint为0,故第2处应添加“CRect(double leftPoint=0,double topPoint=0,double rightPoint=0,double bottomPoint=0);”。
析构函数名和类名一致,并在前面加“~”以和构造函数区别,该析构函数体为空,故第3处应添加“~CRect(){}”,虽然该函数体为空,但“{}”必须保留。主函数中类CRect的对象rect2是通过复制构造函数将rect1的值赋值给它实现初始化的,而rect1的初始化直接调用自定义构造函数,第4处应添加“CRect rect2(rect1);”。
转载请注明原文地址:https://kaotiyun.com/show/EXNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
对建立良好的程序设计风格,下面描述正确的是()。
下列函数原型声明中错误的是()。
有以下程序,其输出结果是()。#include<iostream>usingnamespacestd;intmain(){chara[10]={’1’,’2’,’3’,’4’,’5’,’6’,’7
下面程序的运行结果是【】。#include<iostream>usingnamespacestd;classcount{staticintn;public:count(){n++;}
有如下程序:#include<iostream>usingnamespacestd;classAA{intn;public:AA(intk):n(k){}intget(){returnn;}
一个类的友元函数或友元类能够通过成员操作符访问该类的()。
在下列选项中,没有构成死循环的程序是()。
下列关于C++函数的叙述中,正确的是()。
设有关系模式R(A,B,C,D,E,P),其函数依赖集为{E→D,C→B,(C,E)→F,B→A},则R最高达到______。
若有:intx=25,y=14,z=19;则在计算表达式x++<=25&&y--<=2&&++z<=18后,z的值为【】。
随机试题
“有增长而无发展”指的是()
食滞内停之呕吐的病机为食滞肠胃之泄泻的病机为
A.不凝固血液B.草绿色透明液体C.臭味重的血性液体D.淀粉酶含量高的血性液体E.黄色、混浊、含胆汁、无臭味液体胃十二指肠急性穿孔时腹腔穿刺液为
X线胶片的γ值称为
A、慢性牙周炎B、牙周牙髓联合病变C、侵袭性牙周炎D、牙周脓肿E、慢性龈炎单个牙窄而深的局限性牙周袋常见于
A.10日B.2日C.3日D.5日E.7日开具急诊处方,其药物用量一般不超过的日数是()
具有养阴润燥、清肺利咽功效的中成药是()
单回路架空线路(35kV有架空地线)每千米单相接地电容电流的平均值为()A/kin。
色彩三属性包含________、________、________。
国家对专门从事教育教学工作的人员的最基本要求是()。
最新回复
(
0
)