首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
使用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了用于表示矩形的CRect类,但类CRect的定义并不完整。请按要求完成下列操作,将类CRect的定义补充完成。 (1)定义私有数据成员lefiPoint、topPoint、rightPoi
使用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了用于表示矩形的CRect类,但类CRect的定义并不完整。请按要求完成下列操作,将类CRect的定义补充完成。 (1)定义私有数据成员lefiPoint、topPoint、rightPoi
admin
2016-10-28
17
问题
使用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://kaotiyun.com/show/qKNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
以下程序的执行结果是______。#include<iostream.h>#include<iomanip.h>voidmain(){cout.fi1(’*’);
下列打开文件的表达式中,错误的是
设有二维数组A[0..9,0..19],其每个元素占两个字节,第一个元素的存储地址为100,若按行优先顺序存储,则元素A[6,6]的存储地址为,【】。
以下程序的执行结果为()。#include<iostream.h>classmyClass{Dublic:myClass(intdata);myClass(){value=0;
为完成下面的程序,应在划线处填入的语句是()。#include<iostream>usingnamespacestd;classBase{private:intx;p
流操作子______向输出流中插入一个换行符并刷新输出缓冲区。
从一个函数模板产的模板函数是同名的,因此编译器用______的解决方法调用相应函数。
C++中运算符优先级由高到低排列正确的是()。
设有如下说明 typedef struct {int n;char c;double x;}STD; 则有以下选项,能正确定义结构体数组并赋初值的语句是
下列不属于软件工程3个要素的是()。
随机试题
达赖喇嘛被认为是观世音菩萨的化身。()
可同时进行治疗药物及其代谢物浓度监测的技术是
华新基金管理公司是信泰证券投资基金(信泰基金)的基金管理人。华新公司的下列哪些行为是不符合法律规定的?(2012年试卷三第73题)
1960年,法国总统戴高乐听到法国成功试验原子弹的消息后高呼:“法国万岁!从今天早上起,她更加强大了,更加骄傲了……”能够和这一情景联系起来的是()。
右边给出了四个图形,只有一个是由左边的四个图形拼合(只能通过上、下、左、右平移)而成的。请你把它找出来。
简述《白鹿洞书院揭示》的教育宗旨。(2019年南京师大、2014年华东师大、2013年西北师大)
下列关于Internet的叙述中,错误的是
数据模型所描述的内容通常由数据结构、数据操作和【】三部分组成。
Humansaresocial(11).Theyliketoliveandworkingroups,andtherefore,theyformcouplesandfamilies,villagesandcitie
Thedifferencebetweenaliquidandagasisobvious【C1】______theconditionsoftemperatureandpressurecommonlyfound【C2】_____
最新回复
(
0
)