niusouti.com

下列程序的运行结果是【 】。 include class test { private: int num; public: tes下列程序的运行结果是【 】。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 ma

题目
下列程序的运行结果是【 】。 include class test { private: int num; public: tes

下列程序的运行结果是【 】。

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;

}


相似考题
参考答案和解析
正确答案:100
100 解析:本题比较简单,考查考生基本的类的定义,构造函数以及对象数组的概念。
更多“下列程序的运行结果是【 】。 include <iostream. h> class test { private: int num; public: tes ”相关问题
  • 第1题:

    下列程序的运行结果是 includeclass Location{private:int X.Y;public:void init(i

    下列程序的运行结果是 #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


    正确答案:A
    解析:本题中有成员函数和它的重载函数,要注意它们的不同,在本题中先调用了init函数,初始化了X,Y,都为0,valueX(5);又将X变为5,所以输出5和0,然后初始化init(6,2),接着又valueY(4);将X,Y设为6和4,所以输出6和4。

  • 第2题:

    下面程序的运行结果为includeclass A{ int num;public: A(int){num=i;} A(ABm){num

    下面程序的运行结果为 #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


    正确答案:C
    解析:本题;号查考生对拷贝构造函数的掌握。因为++运算是右结合的,所以在使用a对b赋值时,b的num变为l而a的num变为2(先赋值再自加)。

  • 第3题:

    如下程序编译时发生错误,错误的原因是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( );

    }


    正确答案:void test::show( ){coutnumendl;}
    void test::show( ){coutnumendl;} 解析:show成员函数的声明和实现不一致,即实现部分应有void修饰符,这样才能编译通过。

  • 第4题:

    有如下程序: include using namespace std;class Test {public: Test() {n+=2;} ~Tes

    有如下程序: #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


    正确答案:A
    解析:经过一次构造函数和析构函数的调用后,执行后的输出结果是A。

  • 第5题:

    下面程序的结果是 include class test{private: int num; publi

    下面程序的结果是 #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


    正确答案:A
    解析:C++语言中析构函数是在程序退出不用该类的对象时进行调用。