根据输出结果填空完成下面程序。 include class Test { private: static int val; in根据输出结果填空完成下面程序。include<iostream.h>class Test{private:static int val;int a;public:static int func( );void sfunc(Test &r);};______//初始化静态变量valint Test::func( ){return val++;}void Test::sfunc(Te

题目
根据输出结果填空完成下面程序。 include class Test { private: static int val; in

根据输出结果填空完成下面程序。

include<iostream.h>

class Test

{

private:

static int val;

int a;

public:

static int func( );

void sfunc(Test &r);

};

______//初始化静态变量val

int Test::func( )

{

return val++;

}

void Test::sfunc(Test &r)

{

r.a=125;

cout<<"Result3="<<r.a;

}

void main( )

{

cout<<"Resultl="<<Test::func( )<<endl;

Test A;

cout<<"Result2="<<A.fune( )<<endl;

A. sfunc(A);

}

输出结果为:

Result1=201

Result2=202

Result3=125


相似考题
更多“根据输出结果填空完成下面程序。 include<iostream.h> class Test { private: static int val; in ”相关问题
  • 第1题:

    下列程序的运行结果是______。 include class test { private: int hum; public: tes

    下列程序的运行结果是______。

    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;

    }


    正确答案:100 Destructor is active Destructor is active Destructor is active
    100 Destructor is active Destructor is active Destructor is active 解析:本题比较简单,考查考生基本的类的定义,构造函数以及对象数组的概念。

  • 第2题:

    下面程序的输出结果是()。includeinclude"string.h"void main(){char a[]="Hello T

    下面程序的输出结果是( )。 #include<iostream.h> #include"string.h" void main() {char a[]="Hello Test",b[]="Test"; strcpy(a,b); cout<<a<<end1; } A) B)

    C) D)

    A.Hello

    B.Test

    C.Hello Test

    D.Hello Test HelloTest


    正确答案:B

  • 第3题:

    下面程序的结果是 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++语言中析构函数是在程序退出不用该类的对象时进行调用。

  • 第4题:

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

  • 第5题:

    下面程序的输出结果为()。includeclass CStatic{public:CStatic() {val++;}static i

    下面程序的输出结果为( )。#include<iostream.h>class CStatic{public:CStatic() {val++;}static int val;};int CStatic::val=0;void main(){CStatic cs1;cout<<cs1.val<< "";CStatic cs2;CStatic cs3, cs4;cout<<cs val<<end1;}

    A.14

    B.24

    C.34

    D.54


    正确答案:A