首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
使用VC6打开考生文件夹下的源程序文件modi3.cpp。请完成以下部分,实现在屏幕上输出为: TestClass3 TestClass2 这个程序需要修改的部分,请按照以下部分实现。 (1)类TestClass0不能被实例
使用VC6打开考生文件夹下的源程序文件modi3.cpp。请完成以下部分,实现在屏幕上输出为: TestClass3 TestClass2 这个程序需要修改的部分,请按照以下部分实现。 (1)类TestClass0不能被实例
admin
2018-10-23
28
问题
使用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全国计算机二级
相关试题推荐
下列程序中的重载函数disp()发生错误,错误原因是______。#include<iostream.h>classSample{private:intm;staticintst;
main函数中发生编译错误的语句是______。#include<iostream.h>classA{public:inta;constintb;A():a(10
执行完下列语句inta,b,c=&a;int*&p=c;p=&b;后c指向
以下程序的输出结果是inta,b;voidfun(){a=100;b=200;)main(){inta=5,b=7;fun();cout<<a<<b<<endl;}
下列有关数据库的描述,正确的是
下列关于C++函数的说明中,正确的是()。
只能作为成员函数重载的是
下列数据结构中,按先进后出原则组织数据的是
下列程序用于将源文件中的字母进行大小写转换,请填写while的请句。#include<iostream.h>#include<fstream.h>#include<iomanip.h>voidmain(){cha
若有如下变量定义和函数调用语句:inta=5;fun(&A);则执行下面函数后正确的输出结果是()。voidfun(int*x){cout<<++*
随机试题
材料:随着中考的临近,学生刘冰下定决心认真学习,争取在中考取得满意的成绩。在最初的学习中,刘冰明显感觉到自己的学习成绩进步迅速,然而经过一段时间废寝忘食地学习后,刘冰发现自己的进步速度减缓了,甚至出现成绩停滞不前的现象,而刘冰因为持续不断地学习,也
患者男性,46岁。近1个月频繁发作胸痛,持续数分钟,无症状时心电图正常。患者在进行平板运动试验检查时出现剧烈胸痛,立即终止试验,运动前、运动中及运动终止后的心电图见图4-4-5A、B、C。该患者终止运动试验的原因是
痿证与痹证的主要鉴别点是
由于供货方设计图纸错误以及因供货方技术服务人员的指导错误造成返工,供货方应承担因此所发生的()。
某商业企业为增值税一般纳税人,2013年3月采用分期收款方式批发商品,合同规定不含税销售额为300万元,本月收回50%的货款,其余货款于4月10日前收回。由于购货方资金紧张,本月实际收回不含税销售额100万元;零售商品实际取得销售收入228万元,其中包括以
产品成本预算的编制基础包括()。
机关对晋升领导职务的公务员应当在任职前或者任职后一年内进行任职培训。()
简述民主集中制原则在我国国家机构组织和活动中的体现。
在VB6.0的数据绑定控件中,用于连接外码对应的主码所在的主表数据源的属性是(3)。用于指定要绑定的数据源,并且值一般为ADO数据控件的名称的属性是(4)。3.
下列进程状态的转换下,不正确的一项是______。
最新回复
(
0
)