下面这个程序的结果是
#include<iostream.h>
class A
{
private:
int a;
public:
void seta( ) ;int geta( ) ;};
void A: :seta( )
{ a=1;}
int A: :geta( )
{ retum a;}
class B
{ private:
int a;
public:
void seta( ) ;int geta( ) ;};
void B: :seta( )
{a=2;}
int B: :geta( )
{return a;}
class C: public A,public B
{ private:
int b;
public:
void display( ) ;};
void C: :display( )
{ int b=geta( ) ;
cout < < b;}
void main( )
{ C c;
c. seta( ) ;
c. display( ) ;}
A.1
B.2
C.随机输出1或2
D.程序有错
第1题:
下面程序的结果为 #include<iostream.h> int C; class A { private: int a; static int b; public: A() {a=0;c=0;} void seta(){a++;} voidsetb(){b++;} voidsetc(){c++;} void display() {cout << a << " " << b << “ ” << c;} }; int A∷b=0; void main() { A a1,a2; a1.seta(); a1.setb(); a1.setc(); a2.seta(); a2.seth(); a2.setc(); a2.display(); }
A.1 2 1
B.1 2 2
C.1 1 2
D.2 2 2
第2题:
下面这个程序的结果是 #include<iostream.h> class A { private: int a; public: void seta( );int geta( );}; void A::seta( ) { a = 1;} int A::geta( ) {return a;} class
A.1
B.2
C.随机输出1或2
D.程序有错
第3题:
下面程序的结果是 #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
第4题:
下列程序的运行结果是 #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
第5题:
下面程序的结果为
#include<iostream.h>
int c;
class A
{
private:
int a;
static int b;
public:
A( ) {a=0;c=0;}
void seta( ) {a++;}
void setb( ) {b++;}
void setc( ) {c++;}
void display( ) {cout < < a < < " " < < b < < " " < < c;}
};
int A: :b=0;
void main( )
{
A a1,a2;
a1.seta( ) ;
a1.setb( ) ;
al .setc( ) ;
a2.seta( ) ;
a2.setb( ) ;
a2.setc( ) ;
a2.display( ) ;
}
A.1 2 1
B.1 2 2
C.1 1 2
D.2 2 2