有如下程序: #includeiostream using namespace std; class Obj{ static int i; public: Obj{i++;} 一Obj{i一一;} static int getVal{return i;} }; int Obj::i=0: void f{Obj ob2;coutob2.getVal;} int main{ Obj obl; f; Obj}ob3=new Obj;coutob3一getVal; delete ob3;coutObj::getVal; return 0; } 执行这个程序的输出结果是( )。A.232B.231C.222D.221
有如下程序: #include<iostream> using namespace std; class Obj{ static int i; public: Obj{i++;} 一Obj{i一一;} static int getVal{return i;} }; int Obj::i=0: void f{Obj ob2;cout<<ob2.getVal;} int main{ Obj obl; f; Obj}ob3=new Obj;cout<<ob3一>getVal; delete ob3;cout<<Obj::getVal; return 0; } 执行这个程序的输出结果是( )。
A.232
B.231
C.222
D.221
相关考题:
( 20 )有如下程序段int i =0, j=1;int & r=i ; // ①r =j; // ②int*p= & i ; // ③*p= & r ; // ④基中会产生编译错误的语句是A ) ④B ) ③C ) ②D ) ①
程序中有如下语句for(int i=0;i<5;i++)cout<<*(p+i<<“,”;能够依次输出int型一维数组a的前5个元素。由此可知,变量P的定义及初始化语句是( )。A.int*p=a;B.int p=a;C.*p=a;D.p=a;
有如下程序段,其中会产生编译错误的语句是 inti=0,j=1; int &r=i; //① r=j; //② int * p=&i; //③ * p=&r; //④A.④B.③C.②D.①
有如下程序:include using namespace std;class Obj { static int i;public:Obj(){i+ 有如下程序:#include <iostream>using namespace std;class Obj { static int i;public: Obj(){i++;} -Obj(){i--;} static int getVal(){return i;} };int Obj::i=0;void f(){Obj ob2; cout<<ob2.getVal(); }hat main(){ Obj ob1; f(); Obj *ob3=new Obj; cout<<ob3->getVal(); delete ob3; cout<<Obj:: getVal(); return (); }程序的输出结果是( )。A.232B.231C.222D.221
以下程序的执行结果是______。 include class base { public: virtual void who(){c 以下程序的执行结果是______。include<iostream.h>class base{public:virtual void who(){cout<<"base class"<<endl:}};class derrvel:public base{public:void who(){cout<<"derivel class"<<endl:}};class derive2;public base{public:void who() {cout<<"derive2 class"<<endl;}};void main(){base obj1,*P;derive1 obj2;derive2 obj3:p=obj1;p->who();p=obj2:p->who();p=obj3;p->who();}
程序中有如下语句for(int i=0;i<5;i++)cout<<*(p+i)<<",";能够依次输出int型一维数组a的前5个元素。由此可知,变量P的定义及初始化语句是( )。A.int*p=a;B.int p=a;C.*p=a;D.p=a;
有以下程序: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;}
type(obj) 函数为返回参数obj的类型,eval(obj)函数负责将obj两侧的一对单/双引号去除,则type(eval('"45"'))的结果为A.45B.<class 'int'>C.<class 'str'>D.None