若有以下程序: #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
第1题:
请找出下列程序中错误之处 ______。
#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
第2题:
若有以下程序: #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
第3题:
第4题:
若有以下程序: #include <iostream> using namespace std; class Base { private: int x; protected: int y; public: int z; void setx(int i) { x=i; int getx () { return x; } }
A.1,2,3,4
B.产生语法错误
C.4,3,2,1
D.2,3,4,5
第5题:
以下程序执行后的输出结果是 #include<iostream>. using namespace std; void try(int,int,int,int); int main() { int x,y,z,r; x=1; y=2; try(x,y,z,r); cout<<r<<end1; return 0; } void try(int x,int y, int z,int r) { z = x+y; x = x*x; y = y*y; r = z+x+y; }
A.18
B.9
C.10
D.不确定