下列程序的运行结果是【 】。
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)
}
第1题:
下列程序的运行结果是【 】。
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 ();
}
第2题:
下面程序的运行结果是( )。#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
第3题:
有如下程序: #include<iostream> using namespace std; int s=0; class sample { static int n; public: sample(int i) { n=i; } static void add() { s+=n; } }; int sample::s=0; int main() { sample a(2),b(5); sample::add(); cout<<s<<endl; return 0; } 程序运行后的输出结果是
A.2
B.5
C.7
D.3
第4题:
下列程序的运行结果是 #include<iostream.h> class Location{ private: int X.Y; public: void init(int=0,int=0); void valueX(int val){X=val;} int valueX( ){ return X;} void valueY
A.5 0 6 4
B.0 0 6 4
C.5 0 6 2
D.0 0 6 2
第5题:
以下程序的执行结果是 ( )。 #include <iostream> using namespace std; class sample { private: int x; public: sample (int A) { x=a; } friend double square(sample s); }; double square(sample s) {
A.20
B.30
C.900
D.400