( 32 )有如下程序;#includeiostreamusing namespace std;class Base{public:void output(){cout1;}virtual void Print(){cout'B';}};class Derived:public Base{public:void output(){cout2;}void Print(){cout'D';}};int main(){Base *ptr=new Derived;ptr-output();ptr-Print();delete ptr;return 0;}程序的输出结果是A ) 1BB ) 1DC ) 2BD ) 2D
( 32 )有如下程序;
#include<iostream>
using namespace std;
class Base{
public:
void output(){cout<<1;}
virtual void Print(){cout<<'B';}
};
class Derived:public Base{
public:
void output(){cout<<2;}
void Print(){cout<<'D';}
};
int main(){
Base *ptr=new Derived;
ptr->output();
ptr->Print();
delete ptr;
return 0;
}
程序的输出结果是
A ) 1B
B ) 1D
C ) 2B
D ) 2D
相关考题:
有如下程序:includeusing namespace std;Class Base{public:Base(){cout 有如下程序: #include<iostream.h> using namespace std; Class Base { public: Base(){cout<<“BB”;f();} void{(){cout<<“BF”;} }; class Derived:public Base { public: Derived(){cout<<“DD”;} void f(){cout<<“Df”;) }; int mainA.BBBfDDB.BBDfDDDfC.DDD.DDBBBf
有如下程序:includeusing namespace std;class Base{public:void output( ){cout 有如下程序: #include<iostream> using namespace std; class Base{ public: void output( ){cout<<l;} virtual void Print( ){cout<<'B';} }; class Derived:public Base{ public: void output( ){cout<<1;} void Print( ){cout<<'D';} }; int main( ){ Base*prt=new Derived; prt->output( ); prt->Print( ); delete prt; return 0; } 程序的输出结果是A.1BB.1DC.2BD.2D
有如下程序:include using namespace std;class BASE{public:~BASE(){cout 有如下程序: #include <iostream> using namespace std; class BASE{ public: ~BASE(){cout<<"BASE";} }; class DERIVED:public BASE{ public: ~DERIVED(){cout<<"DERIVED";} }; int main(){DERIVED x;return 0;} 执行后的输出结果是A.BASEB.DERIVEDC.BASEDERIVEDD.DERIVEDBASE
有如下程序:includeusing namespace std;class BASE{public:~BASE( ){cout 有如下程序: #include<iostream> using namespace std; class BASE{ public: ~BASE( ){cout<<"BASE";} }; class DERIVED:public BASE{ public: ~DERIVED( ){cout<<"DERIVED";} }; int main( ){DERIVED x;return 0;} 程序的输出结果是A.BASEB.DERIVEDC.BASEDERIVEDD.DERIVEDBASE
下列程序的运行结果是______。include class Base { public: void f(int x){cout 下列程序的运行结果是______。include<iostream.h>class Base{public:void f(int x){cout<<“Base:”<<x<<endl;});class Derived:public Base{public:void f(char*str){cout<<“Derived:”<<str<<endl;}};void main(void){Base*pd=ne
有如下程序: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.XYB.YXC.XD.Y
有如下程序:include using namespace std;class BASE{public:~BASE() {cout 有如下程序: #include <iostream> using namespace std; class BASE{ public: ~BASE() {cout<<"BASE"; } }; class DERIVED: public BASE { public: ~DERIVED() {cout<;"DERIVED"; } }; int main(){DERIVED x; return 0;} 执行后的输出结果是______ 。A.BASEB.DERIVEDC.BASEDERIVEDD.DERIVEDBASE
有以下程序:include using namespace std;class Base{public:Base(){}virtual void w 有以下程序: #include <iostream> using namespace std; class Base { public: Base(){} virtual void who() { cout<<"Base Class"<<end1; } ~Base(){} }; class Derivel : public Base { public: void who() { cout<<"Derivel Class"<<end1; } }; class Derive2 : public Base { public: void who () { cout<<"Derive2 Class"<<end1; } }; int main () { Base *p; Derivel obj1; Derive2 obj2; p=obj1; p=obj2; p->who ( ); return 0; } 执行程序后的输出结果是( )。A.Base ClassB.Derivel ClassC.Derive2 ClassD.程序编译时出错
阅读下列说明和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;}