首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有类CPolygon(“多边形”)、CRectangle(“矩形”)、CTfiange(“三角形”)的定义。请在横线处填写适当的代码并删
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有类CPolygon(“多边形”)、CRectangle(“矩形”)、CTfiange(“三角形”)的定义。请在横线处填写适当的代码并删
admin
2017-02-21
21
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有类CPolygon(“多边形”)、CRectangle(“矩形”)、CTfiange(“三角形”)的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。该程序的正确输出结果应为:
20
10
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#include<iostream>
using namespace std;
class CPolygon{
public:
//**********found**********
_______//纯虚函数area
声明
void printarea(void)
//**********found**********
{cout<<_______<<end1,}
};
class CRectangle:public CPolygon{
int width; //长方形宽
int height;//长方形高
public:
CRectangle(int W,int h):
width(w),height(h){}
int area(void){return
(width * height);}
};
class CTriangle:public CPolygon{
int length;//三角形一边长
int height;//该边上的高
public:
CTriangle(int 1,int h):
length(1),height(h){}
//**********found**********
int area(void){return(_______)/2;}
};
int main()f
CRectangle rect(4,5);
CTriangle trgl(4,5);
//**********found**********
_______*ppoly1,*ppoly2;
ppoly1=▭
ppoly2=&trg1;
ppoly1->printarea();
ppoly2->printarea();
retumR 0;
}
选项
答案
(1)viauM int area(void)=0; (2)area() (3)length * height (4)Cpolygon
解析
(1)主要考查考生对纯虚函数的掌握,在定义纯虚函数时要看在派生类中函数的定义:int area(void)。由此可知纯虚函数应该为:viauM int area(void)=0;。
(2)主要考查考生对纯虚函数的掌握情况,由void printarea(void)可知,该函数要打印面积,因此在此要调用纯虚函数area,即cont<<area()。
(3)主要考查考生对数学公式的掌握,该函数要返回三角形面积,三角形的面积公式为长乘以该边上的高除以2,即return(length * height)/2;。
(4)主要考查考生对抽象类的掌握情况,根据程序段:
ppoly1=▭
ppoly2=&trg1;
可知指针ppoly1指向CReetangle类,而指针ppoly2指向CTfiangle类,因此在这里只能填这两种类的基类CPolygon类。
转载请注明原文地址:https://kaotiyun.com/show/G6Ap777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
栈底至栈顶依次存放元素A、B、C、D,在第五个元素E入栈前,栈中元素可以出栈,则出栈序列可能是
当要使用ostrstream流类定义一个流对象并联系一个字符串时,应在文件开始处使用#include命令,使之包含()文件。
若已知charstr[20];,有语句cin>>str;当输入为;Thisisaprogram所得的结果是str=()。
下面程序的运行结果是【】和【】。#include<iostream.h>#defineN10#defines(x)x*x#definef(x)(x*x)
下列叙述中,不属于测试的特征的是
对待排序文件的初始状态作要求的排序方法是【】。
以下数据结构中不属于线性数据结构的是
数据结构分为逻辑结构与存储结构,循环队列属于【 】。
数据结构分为逻辑结构和存储结构,循环队列属于______结构。
如果有以下定义及初始化:inta=3,*p=&a;则由此可以推断,*p的值是()。
随机试题
蛋白质消化率
人民代表大会制的权力结构形式的特点是()。
公共政策终结的对象类别有
腹部外伤伴内出血休克,最重要的治疗原则是
A、麻醉药品B、精神药品C、毒性药品D、贵重药品E、普通药品属于二级管理并要定期清点的是
职业健康安全管理体系与环境管理体系中管理的主体是()。
根据《企业会计准则》规定,企业在自行开发并取得专利权的过程中所发生的下列费用中,计入相关专利权入账价值的有()。
认为“儿童在成长的过程中有关利他行为的规范的掌握是学习的结果”的理论属于()。
A.Thatsoundsverymechanical.B.Ah,"bodylanguage"isreallyimportant,isn’tit?C.I’veneverthoughtaboutthatbefore.D
Educationistooimportanttotake【C1】______,whenpeopletakeanythingforseriously,theyput【C2】______blinderswhichcaus
最新回复
(
0
)