} public: void showInfo() //K2 { cout<<\派生类E中重定义的虚函数showInfo()\ } void display() { cout<<\派生类E中纯虚函数display()的具体实现\ } }; void main() { E e(1,2,3); } 2、 假设最终派生类E的继承体系结构如图所示。其中,类别B1, B2, D的多重
继承关系的声明按图从左到右的顺序进行,而带阴影的类别A,C,B表示其在继承体系中为虚基类。请根据以下要求进行程序填空: (1)在标有行号L*的地方给出类别B1, B2和E的声明;
(2)类别D为纯虚函数,因为其包含纯虚函数void display()。除此之外,D中还包括了虚函数virtual void showInfo(){…}。派生类E为类别D的派生类,且其实体类,其具体实现了纯虚函数display()的功能,并在E中对虚函数showInfo()进行了重定义。请在标有行号K*的地方给出纯虚函数display()的声明及虚函数showInfo()的重定义代码。
(3)在面向对象程序设计中,派生类的构造需要对直接基类和虚拟基类进行构造,请阅读代码并根据图示的继承结构,在标有行号W*的地方给出相应基类的初始化参数列表;
ABAB2B1CDE #include 4.1. 第1章 C++与面向对象程序设计概述(P21) 1、 若控制台中输入数据“12??345???634????3214?”,请写出标有行号L*的 程序的输出结果。(P21,第6(1)题,ex1-6-1.cpp) #include void main(){ int a; char b; char c[4]; double d; cin>>a>>b>>c>>d; //输入数据 cout<<\ //L1 cout<<\ //L2 cout<<\ //L3 cout<<\ //L4 } 答案: L1: a=12 L2: b=3 L3: c=45 L4: d=634 2、 写出标有行号L*的程序的输出结果,要求严格符合控制格式。(P21,第 (2)题,ex1-6-2.cpp) #include int a=20,b=18,c=24; cout<<\ cout< cout< 1、 请根据重载函数print(…)的定义,写出标有行号L*的程序的输出结果。(P57, 第10(1)题,ex2-10-1.cpp) #include int print(int i){ return i*i; } double print(double i){ return 2*i; } void main(){ int a=25; float b=9.2f; double d=3.3; char c='a'; short i=3; long k=9; cout< L1: 625 L2: 18.4 L3: 6.6 //L1 //L2 //L3 //L4 //L5 //L6 L4: 9409 L5: 9 L6: 81 2、 请根据变量的作用域和生存周期,写出标有行号L*的程序的输出结果,其 中,L4和L5行各有一个输出分支。(P57,第10(2)题,ex2-10-2.cpp) #include cout<<\ cout<<\} void main(){ int *p2; int m; fun(); { int n(10),m(20); cout<<\ } cout<<\ if(p1) cout<<\ if(p2) cout<<\} 答: L1: a=0, b=-858993460