下列程序的运行结果是【 】。
include <iostream. h>
class test
{
private:
int num;
public:
test()
int TEST() {return num+100;}
~test()
};
test::test(){num=0;}
test::~test(){cout<<"Destructor is active"<<endl;}
void main()
{
test x[3]
cout<<x[1]. TEST()<<endl;
}
第1题:
如下程序编译时发生错误,错误的原因是show函数实现语句错误,则正确的语句应该为______。
include<iostream.h>
class test
{
private:
int hum;
public:
test(int);
void show( );
};
test::test(int n){num=n;}
test::show( ){cout<<num<<endl;}
void main( )
{
test T(10):
T.show( );
}
第2题:
下面程序的结果是 #include<iostream.h> class test{ private: int num; public: test( ); int getint( ) {return num;} ~test( );}; test::test( ) { num=0;} test::~test( ) { cout<<"Destructor is active"<<endl;} void
A.Exiting main Destructor is active Destructor is active Destructor is active
B.Exiting main Destructor is active Destructoris active
C.Exiting main Destructoris active
D.Exiting main
第3题:
下面程序的运行结果为 #include<iostream.h> class A { int num; public: A(int){num=i;} A(ABm){num=a.num++;} void print(){cout<<num;} }; void main() { Aa(1),b(a); a.print(); b.print(); }
A.11
B.12
C.21
D.22
第4题:
有如下程序: #include <iostream> using namespace std; class Test { public: Test() {n+=2;} ~Test() {n-=3;} static int getNum(){retum n;} private: static int n; }; int Test:: n=1; int main() { Test*p=new Test; delete p; cout<<"n="<<Test:: getNum()<<end1; return 0; };执行后的输出结果是______.
A.n=0
B.n=1
C.n=2
D.n=3
第5题:
下列程序的运行结果是 #include<iostream.h> class Location{ private: int X.Y; public: void init(int=0,int=0); void valueX(int val){X=val;} int valueX( ){ return X;} void valueY
A.5 0 6 4
B.0 0 6 4
C.5 0 6 2
D.0 0 6 2
第6题:
有如下程序: #include<iostream> using namespace std; class Test{ public: Test() {n+=2;} ~Test() {n-=3;} static int getNum(){return n;} private: static int n; }; int Test::n=1; int main() { Test*p=new Test; delete p; cout<<"n="<<Test::getNum()<<endl; return 0; } 执行后的输出结果是( )。
A.n=0
B.n=1
C.n=2
D.n=3
第7题:
下列程序的运行结果是______。
include<iostream.h>
class test
{
private:
int hum;
public:
test( );
int TEST( ){return num+100;)
~test( );
};
test::test( ){num=0;)
test::~test( ){cout<<"Destructor is active"<<endl;)
void main( )
{
test x[3];
cout<<x[1].TEST( )<<endl;
}
第8题:
下列程序的运行结果是【 】。
include <iostream. h>
class SomeClass
{
public:
SomeClass(int value) { some_value=value;};
void show_data(void) { cout<<data<<"<<~some_value<<endl; };
static void set_data(int value) {data=value; }
private:
static int data;
int some_value
};
int SomeClass::data
void main(void)
{
SomeClass my_class(1001),your_class(2002);
your_class. set_data(4004);
my_elass. show_data()
}
第9题:
有如下程序:#include<iostream>using namespace std;class test{private: int a;public: test(){cout<<"constructor"<<endl;} test(int a){cout<<a<<endl;} test(const test&_test) { a=_test.a; cout<<"copy constructor"<<en+dl; } ~test(){cout<<"destructor"<<endl;}};int main(){ test A(3); rerun 0;}运行时输出的结果是
A.3
B.constructor destructor
C.copy constructor destructor
D.3 destructor