下列程序的输出结果是______。
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;
}
第1题:
( 31 )有如下程序
#include <iostream>
using namespace std;
Class Base{
public:
Base(int x=0):valB(x) {cout<<valB;}
~Base() {cout<<valB;}
private:
int valB;
};
class Derived:public Base{
public:
Derived(int x=0,int y=0):Base(x),valD(y){cout<<valD;}
~Derived() {cout<<valD; }
private:
int valD;
};
int main(){
Derived obj12(2,3);
retuen 0;
}
运行时的输出结果是
A ) 2332
B ) 2323
C ) 3232
D ) 3223
第2题:
有如下程序: #include<iostream> using namespace std; class Base{ int x; public: Base(int n=0):x(n){cout<<n;} int getX( )const{return x;} }; class Derived:public Base{ int y; public: Derived(int m,int n):y(m),Base(n){tout<<m;} Derived(int m):y(m){cout<<m;} }; int main( ){ Derived dl(3),d2(5,7); return 0; } 程序的输出结果是
A.375
B.357
C.0375
D.0357
第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(lO,20,30);
cout<<q->add()<<end1;
}
第4题:
有如下程序: #include<iostream> using namespace std; class Base{ public: Base(int x=0){cout<<x;} }; class Derived:public Base{ public: Derived(int x=0){cout<<x;} private: Base val; }; int main( ){ Derived d(1); return 0; } 程序的输出结果是
A.0
B.1
C.01
D.001
第5题:
在下面的程序的横线处填上适当的语句,使该程序的输出为12。
include 〈iostream〉
using namespace std;
class Base
{
public:
int a;
Base(int i) { a=i;}
};
class Derived : public Base
{
int a;
public:
Derived(int x) : Base(x),b(x+1) {}
void show()
{
【 】; //输出基类数据成员a的值
cout〈〈b〈〈end1;
}
};
int main()
{
Derived d(1);
d.show();
return 0;
}
第6题:
在下面程序的横线处填上适当的语句,使该程序的输出为12。
include <iostream>
using namespace std;
class Base
{
public:
int a;
Base(int i){a=i;}
};
class Derived: public Base
{
int a;
public:
Derived(int x): Base(x),b(x+l){}
void show()
{
【 】;∥输出基类数据成员a的值。
cout<<b<<end1;
}
};
int main()
{
Derived d(1);
d.show();
return 0;
}
第7题:
有如下程序: #include <iostream> using namespace std; class Base { public: Base(int x=0) { cout<<x; } } class Derived: public Base{ public: Derived(int x=0) { cout<<x; } private: Base val; }; int main() { Derived d(1); return 0; }程序的输出结果是
A.0
B.1
C.1
D.1
第8题:
在下面的程序的横线处填上适当的语句,使该程序的输出为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()
{
______;//输出基类数据成员a的值
cout<<b<<endl;
}
};
int main()
{
Derived d(1);
d.show();
return 0;
第9题:
为完成下面的程序,应在划线处填入的语句是 #include<iostream> using namespace std; class Base { private: int x; public: Base (int i) { x=i; } ~Base(){} }; class Derived:public Base { public: ______________//完成类Derive构造函数的定义 }; int main() { Derived Obj; return 0; }
A.Derived(int i):Base(i){}
B.Derived(){}
C.void Derived (int i):Base(i){}
D.Derived(int i){Base(i);}
第10题:
下列程序的输出结果是【 】。
include<iostream>
using namespace std;
class Base{
public:
int m,n;
Base(int i,int j):m(i),n(j){}
};
class Derived:public Base{
public:
int m,k,;
Derived(int i,int j):Base(i,j),m(i+1),k(j+1){}
};
int main(){
Derived d(1,5);
cout<<d.m<<d.k<<d.n;
return 0;
}