首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
使用VC6打开考生文件夹下的源程序文件modi3.cpp。请完成以下部分,实现在屏幕上输出为: TestClass3 TestClass2 这个程序需要修改的部分,请按照以下部分实现。 (1)类TestClass0不能被实例
使用VC6打开考生文件夹下的源程序文件modi3.cpp。请完成以下部分,实现在屏幕上输出为: TestClass3 TestClass2 这个程序需要修改的部分,请按照以下部分实现。 (1)类TestClass0不能被实例
admin
2018-10-23
72
问题
使用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全国计算机二级
相关试题推荐
类中包含了一个静态成员函数,则main函数中和P.fl(P);语句具有同样功能的语句为______。#include<iostream.h>classM{public:M(intA){A=a;B+=a;}
执行完下列语句inta,b,c=&a;int*&p=c;p=&b;后c指向
下列程序的输出结果是main(){intx=1,a=0,b=0;switch(x){case0:b++;case1:a++;case2:a++;b++;}cou
operator是运算符重载时必须使用的关键字,它和被重载的运算符连在一起,作为运算符函数的专用函数名,务必把该函数说明为______的。
以下关于友元函数的叙述不正确的是()。
以下函数值的类型是()。fun(floatx){floaty;y=3*x-4;returny;}
有以下程序:main(){inta=5,b=4,c=3,d=2;if(a>b>C)cout<<d<<end1;elseif((c-1)=d)==1)tout<<d+1<<endl;elsecou
下列有关拷贝构造函数的描述中错误的是()。
在类的对象被创建时,______函数会被自动调用。
随机试题
国际经济组织根据其宗旨、职能、成员构成等因素分类,不包括()
上腔静脉阻塞癌性腹膜炎
下列选项中不属于财产处罚的是()
下列说法中不正确的为()。
以下各项中,最低折旧年限为3年的固定资产是()。
一个测验经过多次测量所得的结果的一致性程度,称为测验的()。
从内容来看,心理健康教育应包括以下哪两项任务?()
彩色视频信号的数字化过程中,图像的子采样技术通过减少(39)的采样频率来降低数据量。以下属于标准子采样方案的有(40),其中子采样方案(41)得到的数据量是相同的。①4:2:2②2:0:0③4:1:1④4:4:4⑤
Inthelate1960smanypeopleinNorthAmericaturnedtheirattentiontoenvironmentalproblems,andnewsteel-and-glassskyscra
Solidgeometryhasenabledastronomerstocalculatethepositionsoftheheavenlybodies______tooneanother.
最新回复
(
0
)