下列程序输出结果为:
include<iostream>
using namespace std;
class TestClass1
{
public:
TestClass1(){}
TestClass1(int i)
{
x1=i;
}
void dispa()
{
cout<<"x1="<<x1<<",";
}
private:
int x1;
};
class TestClass2:public TestClass1
{
public:
TestClass2(){}
TestClass2(int i):TestClass1(i+10)
{
x2=i;
}
void dispb()
{
dispa();
cout<<"x2="<<x2<<endl;
}
private:
int x2;
};
int main()
{
TestClass2 b(2);
b.dispb();
return 0;
}
第1题:
如下程序的输出结果是 #include<iostream> using namespace std; class Test{ public: Test( ){n+=2;} ~Test( ){n-=3;} static int getNum( ){return n;} private: static int n; }; int Test::n=1; int main( ){ Test*P=new Test: delete P; cout<<"n="<<Test::getNum( )<<endl; return 0; }
A.n=0
B.n=1
C.n=2
D. n=3
第2题:
请将如下程序补充完整,使得输出结果为:bbaa。
include<iostream>
using naluespace std;
class A{
public:
______{eout<<"aa";}
};
class B:public A{
public:
~B( ){eont<<"bb";}
};
int ulain( ){
B*P=new B;
delete P;
return 0;
}
第3题:
下列程序的输出结果是______。 #include<iostream> using namespace std; class Test( public: Test() {cnt++;} ~Test() {cnt--;} static int Count(){return cnt;} private: static int cnt; }; int Test::cnt=0; int main() { cout<<Test::Count()<<""; Test t1,t2; Test*pT3=new Test; Test*pT4=new Test; cout<<Test::Count()<<""; delete pT4; delete pT3; cout<<Test::Count()<<end1; return 0; }
A.024
B.042
C.420
D.240
第4题:
请将下列程序的横线处补充完整,使得输出结果为bbaa
include<iostream>
using namespace std;
class A{
public:
______{cout<<"aa";}
};
class B:public A{
public:
~B(){cout<<"bb";}
};
int main(){
B*p=new
第5题:
下列程序的输出结果为2,横线处应添加语句( )。 #include<iostream> using namespace std; { public: ______void fun(){cout<<1;} }; class TestClass2:public TestClass1 { public:void fun(){cout<<2;) }; int main() { TestClass1 *p=new TestClass2; p->fun(); delete p; Teturn 0; }
A.public
B.private
C.virtual
D.protected