有如下程序: #include using name space std; classB{ public: B(int xx):x(xx){++count;x+=10;} virtual void show()const {cout<<count<<'_'<<x<<endl;} protected: static int count; private: intx; }; class D:publicB{ public: D(int xx,int yy):B(xx),y(yy){++count;y+=100;} virtual void show()const {cout<<count<<'_'<<y<endl}; pnvate: inty; }; int B::count=0; intmain(){ B*ptr=new D(10,20); ptr->show(); delete ptr; return 0; } 运行时的输出结果是( )。
A.1_120
B.2_120
C.1_20
D.2_20
第1题:
有如下程序: #include<iostream> using namespace std; class XX{ protected; int k; public: XX(int n=5):k(n){} ~XX(){cout<<"XX";} Virtual void f()cons=0; }; inline void XX::f()const{cout<<k+3;} class YY:public XX{ public:
A.28XX
B.28YYXX
C.-33XX
D.-33XXYY
第2题:
有如下程序: #include<iostream> using namespace std; class Toy{ public: Toy(char*_n){strcpy(name,_n);count++;} ~Toy(){count--;} char*GetName( ){return name;} static int getCount( ){return count;} private: char name[10]; static int count; }; int Toy::count=0: int main( ){ Toy tl("Snoopy"),t2("Mickey"),t3("Barbie"); cout<<t1.getCount( )<<endl; return 0; } 程序的输出结果是
A.1
B.2
C.3
D.运行时出错
第3题:
有如下程序: #include <iostream> using namespace std; class XX { protected: int k; public: XX(int n=5):k(n){} ~XX() { cout<<"XX"; } virtual void f() const=0; }; inline void XX::f()
A.28XX
B.28YYXX
C.-33XX
D.-33XXYY
第4题:
下列程序的执行结果是______。
include<iostream.h>
class Student
{
public:
Student(int xx){x=xx;}
virtual float calcTuition( );
protected:
int x;
};
float Studertt::calcTuition( )
{
return float(x*x);
}
class GraduateStudent:public Student
{
public:
GraduateStudent(int xx):Student(xx){}
float calcTuition( );
};
float Graduatestudent::calcTuition( )
{
return float(x*2);
}
void main( )
{
Student s(20);
GraduateStudent gs(30);
cout<<s.calcTuition( )<<" "<<gs.calcTuition( )<<endl;
//计算学生s和研究生gs的学费
}
第5题:
有如下程序: #include<iostream> usingnamespacestd; classB{ public: B(intxx):x(xx){++count;x+=10;} virtualvoidshow( )const {cout<<count<<<<x<<endl;} protected: staticintcount; private: intx; }; classD:publicB{ public: D(intxx,intyy):B(XX),y(yy){++count;y+= 100;) virtualvoidshow( )const {cout<<count<<<<y<<endl); private: inty; }; intB::count==0; intmain( ){ B*ptr=newD(10,20); ptr->show( ); deleteptr; return0; } 运行时的输出结果是( )。
A.1_120
B.2_120
C.1_20
D.2_20