首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
使用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了用于表示矩形的CRect类,但类CRect的定义并不完整。请按要求完成下列操作,将类CRect的定义补充完成。 (1)定义私有数据成员lefiPoint、topPoint、rightPoi
使用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了用于表示矩形的CRect类,但类CRect的定义并不完整。请按要求完成下列操作,将类CRect的定义补充完成。 (1)定义私有数据成员lefiPoint、topPoint、rightPoi
admin
2016-10-28
21
问题
使用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了用于表示矩形的CRect类,但类CRect的定义并不完整。请按要求完成下列操作,将类CRect的定义补充完成。
(1)定义私有数据成员lefiPoint、topPoint、rightPoint、bottomPoint,分别用于表示矩形左上角及右下角的点的坐标,它们都是double型的数据。请在注释//********1********之后添加适当的语句。
(2)完成默认构造函数CRect的定义,指定缺省实参为0,都是double型的数据。请在注释//********2********之后添加适当的语句。
(3)定义函数体为空的析构函数。请在注释//********3********之后添加适当的语句。
(4)在main()函数中定义CRect类的实例rect2,并把rectl的值赋给rect2。请在注释//********4********之后添加适当的语句。
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
#include<iostream.h>
class CRect
{
private:
//********1********
public:
//********2********
//********3********
void SetPoints(double,double,double,double);
void SetLeftPoint(double m){leftPoint=m;}
void SetRightpoint(double m){rightPoint=m;}
void SetToppoint(double m){topPoint=m;}
void SetBottomPoint(doublem){bottomPoint=m;}
void Display();
};
CRect::CRect(double1,double t,double r,double b)
{
leftPoint=1;topPoint=t;
rightPoint=r;bottomPoint=b;
}
void CRect::SetPoints(double1,double t,double r,double b)
{
leftPoint=1;topPoint=t;
rightPoint=r;bottomPoint=b;
}
void CRect::Display()
{
cout<<"left-top point is("<<leftPoint<<","<<topPoint<<")"<<’\n’;
cout<<"right-bottom point is("<<rightPoint<<","<<bottomPoint(<")"<<’\n’;
}
void main(){
CRect rect0;
rect0.Display();
rect0.SetPoints(20,20.6,30,40);
rect0.Display();
CRect rectl(0,0,150,150);
rectl.SetTopPoint(10.5);
rectl.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)添加语句:CRect rect2(rect1);
解析
(1)第1个标识下完成私有数据成员lefiPoint、topPoint、rightPoint、bottomPoint的定义,均为double型的变量,故第1个标识下应添加“double leftPoint,topPoint,rightPoint,bottomPoint;”。
(2)构造函数完成成员变量的初始化,类CRect的默认构造函数并初始化double型私有数据成员leftPoint、topPoint、rightPoint、bottomPoint为0,故第2个标识下应添加“CRect(double lettPoint=0,doubletopPoint=0,double rightPoint=0,double bottomPoint=0);”。
(3)析构函数名和类名一致,并在前面加“~”以和构造函数区别,该析构函数体为空,故第3个标识下应添加“~CRect(){};”,虽然该函数体为空,但是“{}”必须保留。
(4)主函数中类CRect的对象rect2是通过复制构造函数将rect1的值赋值给它实现初始化的,而rect1的初始化直接调用自定义构造函数,第4个标识下应添加“CRectrect2(rect1);”。
转载请注明原文地址:https://jikaoti.com/ti/4ME0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
C++语言中的基本数据类型是()。
有如下说明inta[10]={1,2,3,4,5,6,7,8,9,10},*p=a;则数值为9的表达式是
有以下程序:#include<iostream>#include<fstream>usingnamespacestd;intmain(){fstreamfile;fil
下列对字符数组进行初始化的语句中,正确的是()。
C++语言中关键字运算符有new,delete和______。
下列不属于软件工程的3个要素的是
如果表达式x*y+2中,“*”是作为友元函数重载的,“+”是作为友元函数重载的,则该表达式还可为
通过使用new和delete两个运算符进行的分配为【】存储分配。
如果一个模板声明列出多个参数,则多个参数之间必须使用______隔开,每个参数都必须重复使用关键字______。
如果有以下定义及初始化:inta=3,*p=&a;则由此可以推断,*p的值是()。
随机试题
坚持以人为本,要始终放在第一位的是()
扁平足,正确的摄影体位是
产生IL-2的细胞是
()是指在经济运行过程中,资金供求双方运用各种金融工具调节资金盈余的活动。
下列关于无形资产后续计量的表述中,正确的有( )。
一旅游团就餐1小时后,游客陆续出现唇、指甲、全身皮肤青紫。该采取何种措施进行急救?()
领导要你负责组织一次全体人员去上海自由贸易区学习和考察的活动,你怎么做?
下列4组含C1~C7的结点序列中,()是下图所示的有向图的拓扑序列。
人们说话所产生的语音信号经过数字化之后才能由计算机进行存储、传输和处理。语音信号的带宽大约为300~3400Hz,对其数字化时采用的取样频率和量化位数通常是
Whendoesthepartystart?
最新回复
(
0
)