下列程序的执行结果是【 】。
include < iostream. h>
class Myclass
{
public:
void GetSum(int a)
static int Sum:
private:
int A;
};
int Myclass:: Sum =10; //必须在类外部对静态数据成员初始化
void Myelass: :GetSum(int a)
{
A=a;
Sum+=A;
}
void PrintSum(Myclass& A)
{
cout<<"Sum="<<A.Sum<<end1;
}
void main( )
{
Myclass M,N;
M. GetSum(3)
N. GetSum(7)
PrintSum(M);
}
第1题:
下列程序的运行结果是______。
include<iostream.h>
class Base
{
public:
void f(int x){cout<<“Base:”<<x<<endl;}
);
class Derived:public Base
{
public:
void f(char*str){cout<<“Derived:”<<str<<endl;}
};
void main(void)
{
Base*pd=ne
第2题:
如下程序的输出结果是 #include<iostream> using namespace std; class MyClass{ public: MyClass(int i=0){cout<<1;} MyClass(const MyClass&x)}cout<<2;} }; int main( ){ MyClass objl(1),obj2(2),ohj3(objl); return 0; }
A.112
B.111
C.121
D.113
第3题:
第4题:
下列程序的执行结果为______。
include<iostream.h>
class Myclass
{
public:
void GetSum(int a);
static int Sum;
prtvate:
int A;
};
int Myclass::Sum=10;//必须在类外部对静态数据成员初始化
void Myclass::GetSum(int a)
{
A=a;
Sum+=A:
}
vold PrintSum(Myclass& A)
{
cout<<"Sum="<<A. Sum<<endl;
}
void main( )
{
Myclass M,N;
M.GetSum(3);
N.GetSum(7);
PrintSum(M);
}
第5题:
下列程序的运行结果是______。
include<iostream.h>
class Base
{
public:
virtual void func(int i){cout<<"class Base:"<<i<<end1;)
};
class Derived: public Base
{
public:
void func(double d){cout<<"class Derived:"<<d<<endl;}
};
void main( )
{
Base a,*p=a;
Derived b;
p=&b;
(*p).func(3.3);
}