niusouti.com

有如下程序:inCludeusing namespace std;Class TestClass{public:virtUal void furll有如下程序: #inClude<iostream> using namespace std; Class TestClass {public: virtUal void furll() {cout<<“funlTestclass”;} virtual void fun2() {cout<<“{fun2TestClass”;}}; class TestClass

题目
有如下程序:inCludeusing namespace std;Class TestClass{public:virtUal void furll

有如下程序: #inClude<iostream> using namespace std; Class TestClass {public: virtUal void furll() {cout<<“funlTestclass”;} virtual void fun2() {cout<<“{fun2TestClass”;}}; class TestClassl:public TestClass {void fun() {cout<<“fu

A.fun1TestClass1 fun2TestClass

B.fun1TestClass1 fun2TestClass1

C.fUnlTestClass fun2TestClass

D.funlTe3tClass fun2TestClassl


相似考题
更多“有如下程序:#inClude<iostream>using namespace std;Class TestClass{public:virtUal void furll ”相关问题
  • 第1题:

    有如下程序:includeincludeusing namespace std;class TestClass{public;T

    有如下程序: #include<iostream> #include<iomanip> using namespace std; class TestClass{ public; TestClass (){cout<<'A';} TestClass(char C){cout<<c;) ~TestClass (){cout<<'B';} }; int main(){ TestClass p1,*p2; p2=new TestClass('X'); delete p2; return 0; } 执行这个程序的结果是( )。

    A.ABX

    B.ABXB

    C.AXBB

    D.AXB


    正确答案:C
    解析:在定义对象p1时由系统自动调用构造函数TestClass(),输出字母A;用new创建单个对象TestClass('X')时,要根据参数调用相应的构造函数TestClass(char C),输出字母X;在执行delete时,系统会自动调用析构函数~TestClass(),输出字母B,当对象的生存周期即将结束时系统会自动调用析构函数~TestClass(),输出字母B。

  • 第2题:

    有如下程序: #include(iostream) using namespace std; class TestClass{ protected: TestClass(){couti(cout<<‘x’;} TestClass(char c){cout<<c;}}; class TestClassl:publicTestClass{ public: TestClassl(char c){cout<<c;}}; int main(){ Te

    A.y

    B.yx

    C.xy

    D.yy


    正确答案:C
    解析: 本题中类TestClass为基类,TestClass1为TestClass的派生类。由main主函数入手,定义TestClassl类型的对象dl,参数值为y。TestClassl类继承TestClass,所以主函数中“TestClassldl(‘y’);”语句首先调用“TestClass1 (char c){coutc;}”然后调用基类中的“TestClass(){cout‘x’;}”输出x,然后执行“TestClass(charc){eoutc;}”输出y,即答案为“xy”。

  • 第3题:

    有下列程序:includeusing namespace std;class TestClass{int a;public:TestClass(in

    有下列程序: #include<iostream> using namespace std; class TestClass { int a; public: TestClass(int x)<a=x;} void show(){cout<<a;} }; class TestClass1:publicTestClass { int b; public: TestCla

    A.5

    B.1

    C.0

    D.2


    正确答案:D
    解析: TestClass为TestClass1的基类,在主函数main中定义TestClass对象b,*p。TestClass1对象d,p指向d,调用其show函数。“TestClass1(int i):TestClass(i+1),b(i){}”语句中的TestClass类参数为2,所以show输出2。

  • 第4题:

    有如下程序:includeincludeusing namespace std;class BASE{char c;public

    有如下程序: #include<iostream>#include<iosream> using namespace std; class BASE{ char c; public; BASE(char n):c(n){} virtual ~ BASE(){cout<<c;} }; class DERIVED; public BASE{ char c; public: DERIVED (char n): BASE (n+1)

    A.XY

    B.YX

    C.X

    D.Y


    正确答案:A

  • 第5题:

    有如下程序:includeusing namespace std;Class TestClass{int a;public:TestClass(in

    有如下程序: #include<iostream> using namespace std; Class TestClass {int a; public: TestClass(int x){a=x;} void show(){cout<<a;}}; class TestClass1:public TestClass {int b; public: TestClass1(int i):TestClass(i+1),b(i){} voi

    A.5

    B.1

    C.0

    D.2


    正确答案:D
    解析: TestClass为TestClass1的基类,在主函数main中定义TestClass对象b,*p。TestClassl对象d,p指向d,调用其show函数。“TestClass(int i):TestClass(i+1),b(i){}”语句中的TestClass基类参数为2,所以show输出2。

  • 第6题:

    阅读下列说明和C++代码,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。
    【说明】
    以下C++代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分类及其关系如图6-1所示。



    【C++代码】
    #include?#include?using?namespace?std;class?DrawCircle?{??????//绘制圆形,抽象类? ? ? public: (1);//定义参数为?int?radius,?int?x,?inty? ?virtual~DrawCircle()?{?}};class?RedCircle:public?DrawCircle?{????//绘制红色圆形? ? ? ? public: void?drawCircle(intradius,?int?x,?int?y)?{cout?<?drawCircle?=?drawCircle;? }? ?virtual~shape()?{?}? public:? ?virtual?void?draw()?=?0;};class?Circle:public?Shape?{????//圆形? ? private:? ? ?int?x,y,radius;? ? public:? Circle(int?x,inty,int?radius,DrawCircle?*drawCircle)? (3)? {? this->x?=?x;? ?this->y?=?y;? ? this->radius?=?radius; }? ? ? public:? void?draw(){? drawCircle?-> (4); }};int?main(){Shape?*redCirclenew?Circle(100,100,10,????(5)????);//绘制红色圆形? Shape?*greenCircle=new?Circle(100,100,10, (6)??);//绘制绿色圆形redCircle >draw();? ?greenCircle?->draw();? ?return?0;}


    答案:
    解析:
    (6)(1)void drawCircle (int radius,int x,int y)
    (2)DrawCircle*drawCircle
    (3)drawcircle
    (4)drawCircle(radius,x,y)
    (5)new RedCircle()
    (6)new GreenCircle()【解析】
    第一空是填接口里面的方法,在接口的实现里面找,可以发现应该填void drawCircle (int radius,int x,int y)。
    第二空可以根据后面this drawCircle=drawCircle判断,这里应该有一个drawCircle属性,因此应该填)DrawCircle drawCircle。
    第三空这里填drawcircle,用-> drawcircle来引用父类的成员。
    第四空调用drawCircle(radius,x,y)方法。
    第五、六空分别创建一个红色圆形对象和一个绿色圆形对象作为Circle里面的实参。