请找出下列程序中错误之处 ______。
#include<iostream.h>
class A{
private:
int x1;
protected:
int x2;
public:
int x3;
};
class B:public A{
private:
int y1;
protected:
int y2;
public:
int y3;
void disp(){cout<<x1<<y1<<end1:} //A
void set(int i) {x2=i;} //B
};
void main() {
B bb;
bb.x3=10; //C
bb.y3=10; //D
}
A.A
B.B
C.C
D.D
第1题:
下面程序的结果为 #include<iostream.h> int c; class A { private: int a; static int b; public: A( ) {a=0;c=0;} void seta( ){a++;} void setb( ){b++;}
A.1 2 1
B.1 2 2
C.1 1 2
D.2 2 2
第2题:
下面程序中错误之处是 ______。
include<iostream.h>
class A{
private:
int xl;
protected:
int x2;
public:
int x3;
};
class B: public A{
private:
int b1;
protected:
int b2;
public:
int b3;
void disp(){cout<<x1<<b2<<end1;} //A
void set(int i){x3=i;} //B
};
void main()
B bb;
bb. a3=10 //C
bb. b3=10 //D
}
第3题:
若有以下程序: #include <iost ream> using namespace std; class A { private: int a; public: A(int i) { a=i; } void disp () { cout<<a<<", "; } }; class B { private:
A.10,10,10
B.10,12,14
C.8,10,12
D.8,12,10
第4题:
若有以下程序: #include <iostream> using namespace std; class A { private: int x; protected: int y; public: int z; void setx(int i) { x=i; } int getx () { return x; }; class B : protected A { public: void setvalue(int a, int b, int c) { setx (a); y=b; z=c; } void display() { cout<<getx ( ) <<", "<<y<<", "<<z<<", "<<end1; } }; int main () { B obj; obj.setvalue(5, 6, 7); obj.display ( ); return 0; } 程序运行后的输出结果是( )。
A.产生语法错误
B.7,6,5
C.5,6,7
D.7,5,6
第5题:
以下程序中,错误的行为
①#include<iostream.h> ②class A ③{ ④ public: ⑤ int n=2; ⑥ A(int val){cout<<val<<end1;} ⑦ ~A(){}; ⑧}; ⑨void main() ⑩{ (11) A a(0); (12)}
A.⑤
B.⑥
C.⑦
D.(11)