下面程序的运行结果是( )。#include<iostream.h>class Sample{int x, y;public:Sample() { x=y=0; }Sample(int a, int b) { x=a; y=b; }void (lisp(){cout<<"x="<<x<<",y="<<y<<end1;}};void main(){Sample s(2,3), *p=&s;p->disp();}
A.x=1, y=2
B.x=2, y=4
C.x=2, y=3
D.x=4, y=3
第1题:
以下程序的执行结果是【 】。
include<iostream.h>
include<stdlib.h>
class Sample
{
public:
int x,y;
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(2,3);
s1.disp();
}
第2题:
以下程序的执行结果是【 】。
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();
}
第3题:
有以下程序:#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
第4题:
下列程序的运行结果是【 】。
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 ();
}
第5题:
下列程序的执行结果是( )。 #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