首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
使用VC6打开考生文件夹下的源程序文件modi3.cpp。请完成以下部分,实现在屏幕上输出为: TestClass3 TestClass2 这个程序需要修改的部分,请按照以下部分实现。 (1)类TestClass0不能被实例
使用VC6打开考生文件夹下的源程序文件modi3.cpp。请完成以下部分,实现在屏幕上输出为: TestClass3 TestClass2 这个程序需要修改的部分,请按照以下部分实现。 (1)类TestClass0不能被实例
admin
2018-10-23
67
问题
使用VC6打开考生文件夹下的源程序文件modi3.cpp。请完成以下部分,实现在屏幕上输出为:
TestClass3
TestClass2
这个程序需要修改的部分,请按照以下部分实现。
(1)类TestClass0不能被实例化,请定义一个纯虚函数print,在注释//********1********后添加适当的语句。
(2)类TcstClass1私有虚继承类TestClass0,请在注释//********2********后添加适当的语句。
(3)类TestClass2公有继承类TestClass0,请在注释//********3********后添加适当的语句。
(4)类TestClass3公有继承类TestClass2与TestClass1,请在注释//********4********后添加适当的语句。
注意:仅在函数指定位置添加语句,请勿改动主函数main与其他函数中的任何内容。
1 #include<iostream.h>
2 class TestClass0
4 {
4 //********1********
5
6 };
7 //********2********
8 class TestClass1:
9 {
10 public:
11 void print()
12 {
13 cout<<’’TestClass1’’<<end1;
14 }
15 };
16 //********3********
17 class TestClass2:
18 {
19 public:
20 void print()
21 {
22 cout<<’’TestClaSs2’’<<end1;
23 }
24 };
25 //********4********
26 class TeStClass3:
27 {
28 public:
29 void print()
30 {
31 cout<<’’TestClass3’’<<end1;
32 }
33 };
34 void main()
35 {
36 TestClass3 c3;
37 TestClass2 c2;
38 c3.print();
39 c2.print();
40 return;
41 }
选项
答案
(1)添加语句:virtual void print()=0; (2)将“class TeStClass1:”补充完整为:class TestClass1:virtual private TestClass0 (3)将“class TestClass2:”补充完整为:class TestClass2:public TestClass0 (4)将“class TestClass3:”补充完整为:class TestClass3:public TestClass2,public TestClass1
解析
在VC环境下打开程序,根据题干给出的几条功能要求,对程序中给出注释下的内容逐个补全或修改。本题从题干要求入手,依次处理各个类,完成各个类的定义。
(1)题目1要求“请定义一个纯虚函数print”。在C抖中,虚函数在基类中用virtual声明成员函数为虚函数。纯虚函数是在声明虚函数时被“初始化”为0的函数,即“virtual voidprint0=0;”。
(2)题目2要求“类TestClass1私有虚继承类TestClass0”。在C++中声明一个派生类时将基类的继承方式指定为privme的,称为私有继承。同(1),声明TestClass1虚继承类“:virtual TestClass0”,题目要求为私有,即“class TestClass1:virtual private TestClass0”。
(3)题目3要求“类TestClass2公有继承类TestClass0。”同(2),公有继承是在定义一个派生类时将基类的继承方式指定为public的,称为公用继承。所以这里补全“class TestClass2:public TestClass0”。
(4)题目4要求“类TestClass3公有继承类TestClass2与TestClass1。”同(3),所以这里补全“class TestClass3:public TestClass2,public TestClass1”。
转载请注明原文地址:https://kaotiyun.com/show/85Ap777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
类clasgone在声明func成员函数时发生错误,出错原因是______。classoneprivate:inta;public:voidfunc(two&);};class
有以下程序:#include<iostream>usingnamespacestd;intmain(){intx=15;while(x>10&&x<50){x+
数据库管理系统DBMS中用来定义模式、内模式和外模式的语言为
__[12]__是一系列相关函数的模型或样板,这些函数的__[13]__形式相同,只是所针对的__[14]__不同。
下列有关拷贝构造函数的描述中错误的是()。
两个或两个以上模块之间关联的紧密程度称为()。
如果使用数组名称为函数参数,形实结合时,传递的是______。
有下列程序:#include<iostream>usingnamespacestd;classTestClass1{public:TestClass1(){cout<<"A";}
类MyClass的定义如下:classMyClass{public:MyClass(){value=0;}SetVariable(inti){value=i;}private:intvalue
随机试题
舌下腺小管开口于舌下腺大管开口于
Ifyouweretobeginanewjobtomorrow,youwouldbringwithyousomebasicstrengthsandweaknesses.Successor【61】inyourwor
慢性肾小球肾炎进入慢性肾衰竭的患者合并高血压时,其饮食宜用
未满多大年龄者,不得参与放射工作
下列哪种物质属于被动免疫制剂
根据《建设工程安全生产条例》,施工单位在使用承租的机械设备和施工机具及配件的,由______共同进行验收。
中国金融期货交易所的全面结算会员()。
A上市公司于2010年5月向中国证监会提出增发股票的申请,根据《发行管理办法》规定,下列各项中,不符合上市公司增发股票条件的是()。
Foryears,astronomersstruggledtocalculatetheageoftheuniverse.
HMSBelfastisacruiser.ShewaslaunchedinMarch1938andservedthroughouttheSecondWorldWar,playingaleadingpartint
最新回复
(
0
)