首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
使用VC6打开考生文件夹下的源程序文件modi3.cpp。请完成以下部分,实现在屏幕上输出为: TestClass3 TestClass2 这个程序需要修改的部分,请按照以下部分实现。 (1)类TestClass0不能被实例
使用VC6打开考生文件夹下的源程序文件modi3.cpp。请完成以下部分,实现在屏幕上输出为: TestClass3 TestClass2 这个程序需要修改的部分,请按照以下部分实现。 (1)类TestClass0不能被实例
admin
2018-10-23
51
问题
使用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全国计算机二级
相关试题推荐
完全不考虑程序的内部结构和内部特征,而只是根据程序功能导出测试用例的测试方法是
已知语句intm=10;则下列引用的表示中正确的是
有以下程序:#include<iostream>usingnamespacestd;intmain(){intx=15;while(x>10&&x<50){x+
如果类中的一个成员函数的定义实现在类内,则该函数系统自动默认为该类的______函数。
有以下程序:#include<iostream>usingnamespacestd;intmain(){intx=15;while(x>10&&x<50){x++;if(x/3
下列关于C++函数的说明中,正确的是()。
在类的对象被创建时,______函数会被自动调用。
下列数据结构中,按先进后出原则组织数据的是
类MyClass的定义如下:classMyClass{public:MyClass(){value=0;}SetVariable(inti){value=i;}private:intvalue
随机试题
默认情况下,Word2010的_____中含有设定字体的命令。
Iregret(tospend)(so)muchmoney(on)acar(that)Ihardlydriveineverydaylife.
提示排卵已经发生的指标是
下述不符合原发性血色素沉着症的是
在会计软件中,()一般用来完成原始凭证和单据的扫描,并将扫描结果存入会计软件相关数据库中。
俗话说:“冬练三九,夏练三伏”。这是说勤奋的人在最冷的“三九天”和最热的“三伏天”里都坚持锻炼。下列不是“三伏天”最热的原因是:
在VisualFoxPro中,编译或连编生成的程序文件的扩展名不包括()。
以下叙述中正确的是
Whatistilemainideaoftilenews?
It______beverycoldhere,eveninMay.
最新回复
(
0
)