下列程序的运行结果是【 】。
include <iostream. h>
class Sample {
int x,y;
public:
Sample() {x=y=0; }
Sample(int a, int b) {x=a;y=b;}
void disp() {
cout<<" x=" <<x<<" , y="<<y<<end1;
}
};
void main() {
Sample s1, s2(1, 2);
s1. disp0;
s2. disp ();
}
第1题:
下列程序的运行结果是【 】。
include<iostream, h>
class Sample
{
int a;
public:
Sample(int aa=0) {a=aa;}
~Sample() {cout<<"Sample="<<a<<;}
class Derived: public Sample
{
int b;
public:
Derived(int aa=0, int bb=0): Sample(aa) {b=bb;}
~De rived() {cout <<"Derived="<<b<<'';}
void main()
{
Derived dl (9)
}
第2题:
下列程序的执行结果是( )。 #include<iostream.h> class Sample { int x,y; public: Sample() {x=y=0;} Sample(int a,int b) {x=a;y=b;} ~Sample() { if(x==y) cout<<"x=y"<<end1; else cout<<"x!=y"<<end1; } void disp() { cout<<"x="<<x<<",y="<<y<<end1; } }; void main() { Sample s1(2,3); s1.disp(); }
A.x=2,y=2
B.x=3,y:3
C.x=2,y=3
D.x=3,y=2
第3题:
执行以下程序后的输出结果为( )。#include<iostream. b>class Sample{ int x, y; public: Sample() { x=y=0;} Sample(int a, int b) {x=a; y=b; } void disp () { cout<<"x="<<x<<"y="<<y<<end1; }};void main(){ Sample s(2,3), *p=&s; p->disp();}
A.x=1, y=3
B.x=2, y=4
C.x=3, y=2
D.x=2, y=3
第4题:
以下程序的执行结果是【 】。
include<iostream. h>
class Sample
{
public:
int x:
int y;
void disp()
{
cout<<"x="<<x<<",y="<<y<<end1;
}
};
void main()
{
int Sample:: ** pc;
Sample s;
pc=& Sample: :x;
s.*pc=10;
pc:=&Sample: :y;
s.*pc=20;
s.disp();
}
第5题:
有以下程序:#include <iostream>using namespace std;class sample{private: int x; static int y;public: sample(int a); static void print(sample s);};sample:: sample(int a){ x=a; y+=x;}void sample:: print(sample s){ cout<<"x="<<s. x<<",y="<<y<<end1;}int sample:: y=0;int main(){ sample s1(10); sample s2(20); sample:: print(s2); return 0;}程序运行后的输出结果是( )。
A.x=10,y=20
B.x=20,y=30
C.x=30,y=20
D.x=30,y=30