下列程序的输出结果是非曲直【 】。
include<iostream, h>
class base
{
int x, y;
public:
base(int i, int j){x=i; y=j;}
virtual int add(){return x+ y;}
};
class three: public base
{
int z;
public:
three(int i, int j, int k) :base(i, j){z=k; }
int add() { return (base:: add()+z); }
};
void main()
{
three * q=new three(lO,20,30);
cout<<q->add()<<end1;
}
第1题:
若有以下程序: #include <iostream> using namespace std; class Base { public: Base() { x=0; } int x; }; class Derivedl: virtual public Base { public: Derivedl() { x=10; } }; class Derived2: virtual public Base { public: Derived2() ( x=20; } }; class Derived: public Derivedl,protected Derived2 { }; int main() { Derived obj; cout<<obj.x<<end1; return 0; } 该程序运行后的输出结果是
A.20
B.30
C.10
D.0
第2题:
下列程序段的输出结果是 #include<iostream.h> void fun(int * X,int * y) { cout < < * X < < * y; * X=3; * y=4; } void main( ) { int x=1,y=2; fun(&y,&x); cout < < X < < y < < end1; }
A.2143
B.1212
C.1234
D.2112
第3题:
下列程序的输出结果是______。
include<iostream.h>
class base
{
int x,y;
public:
base(int i,int j){x=i;y=j;}
virtual int add( ){return x+y;}
};
class three:public base
{
int z;
public:
three(int i,int j,int k):base(i,j){z=k;)
int add( ){return(base::add( )+z);}
};
void main( )
{
three*q=new three(10,20,30);
cout<<q->add( )<<endl;
}
第4题:
下列程序段的输出结果是 #include<iostream.h> void fun(int*x,int*y) {cout<<*x<<*y; *X=3; *y=4; } void main() {int x=1,y=2; fun(&y,&x); cout<<X<<y<<endl; }
A.2143
B.1212
C.1234
D.2112
第5题:
在下列的程序的横线处填上适当的语句,使该程序的输出为12。
include<iostream.h>
using namespace std;
class Base
{
public:
int a,b;
Base(int i){a=i;}
};
class Derived:public Base
{
int a;
public:
Derived(int x):Base(x),b(x+1){};
void show()
{