网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)
阅读以下C++代码,填充(1)~(5)的空缺,将解答填入答题纸的对应栏内。 【说明】在下面程序横线处填上适当的字句,使其输出结果为:x=5x=6y=7x=8z=9【程序】#include<iostream.h>class X1{int x;(1):X1(int xx=0){x=xx;}(2)void Output()(cout<<"x="<<x<<end;}};(3)Y1:public X1{int y;public:Y1(int xx=0,int yy=0):X1(xx){y=yy;}(2)void Output(){(4)Output();cout<<"y="<<y<<end1;}};class Z1:pubtic X1{int z:(5):Z1(int xx=0,int zz=0):X1(xx){z=zz;}②void Output(){X1::Output();cout<<"z="<<z<<end1;}};void main(){X1 a(5);Y1 b(6,7);Z1 c(8,9);X1*p[3]={&a,&b,&c};For(int i=0;i<3;i++){p[i]-->Output();cout<<end1;}}


参考答案

参考解析
解析:(1)public
(2)virtual
(3)class
(4)X1::
(5)public
【解析】

通过对比三个类的定义就可以发现,在类X1和Z1的定义中缺少类的成员属性声明,而类一般将成员变量声明为公有的、私有的或受保护的三种类型中的一种,在类的定义中,我们一般将类的构造函数放在公有的属性下面,在题目中只能选择公有的属性了,因此,第1空和第5空中应该填“public”。对三个类的定义进行仔细观察后,我们同样可以发现,每个类中都定义了一个同名函数Output(),而且在后两个类的函数体中调用了函数Output(),由此,我们应该想到虚函数。虚函数的作用是允许在派生类中重新定义与基类同名的函数,并且可以通过基类指针或引用来访问基类和派生类中的同名函数。因此,第2空应该填“virtual”。第3空就简单了,考查类的定义,应该填类的标识符“class”。从程序中我们可以看到,类Y1和Z1都以公有的方式继承类X1。从输出的结果来分析,类Y1和Z1都输出了两个数,但单从类Z1的函数来看,只能输出一个变量的值z,因此,可以发现在类Z1中应该和类Y1一样,都调用了类X1的函数Output(),因此,第4空的答案为“X1::”。
更多 “阅读以下C++代码,填充(1)~(5)的空缺,将解答填入答题纸的对应栏内。 【说明】在下面程序横线处填上适当的字句,使其输出结果为:x=5x=6y=7x=8z=9【程序】#include<iostream.h>class X1{int x;(1):X1(int xx=0){x=xx;}(2)void Output()(cout<<"x="<<x<<end;}};(3)Y1:public X1{int y;public:Y1(int xx=0,int yy=0):X1(xx){y=yy;}(2)void Output(){(4)Output();cout<<"y="<<y<<end1;}};class Z1:pubtic X1{int z:(5):Z1(int xx=0,int zz=0):X1(xx){z=zz;}②void Output(){X1::Output();cout<<"z="<<z<<end1;}};void main(){X1 a(5);Y1 b(6,7);Z1 c(8,9);X1*p[3]={For(int i=0;i<3;i++){p[i]-->Output();cout<<end1;}}” 相关考题
考题 执行以下程序,输出结果的最后一行语句是______。 include class Sample { int x,y; 执行以下程序,输出结果的最后一行语句是______。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;elsecout<<"x!=y"<<end1;}void disp(){cout<<"x="<<x<<",y="<<y<<end1;}};void main(){Sample s1(2,3);s1.disp();}

考题 阅读下面程序: include void fun(int n) { int x(5); static int y(10); if(n>0) { 阅读下面程序:include<iostream.h>void fun(int n){int x(5);static int y(10);if(n>0){++x;++y;cout<<x<<","<<y<<end1;}}void main(){int m(1);fun(m);}则该程序的输出结果是______。

考题 在下面的程序的横线处填上适当的语句,使该程序的输出为12。 include using namespace 在下面的程序的横线处填上适当的语句,使该程序的输出为12。include<iostream.h>using namespace std;class Base{public:int a,b;Base(int i){a=i;}};class Derived:public Base{int a;public:Derived(int x):Base(x),b(x+1){};void show(){______;//输出基类数据成员a的值cout<<b<<endl;}};int main(){Derived d(1);d.show();return 0;

考题 以下程序输出结果为______。 include using namespace std; class TestClass 1 { publi 以下程序输出结果为______。include<iostream>using namespace std;class TestClass 1{public:TestClass1(){}TestClass1(int i){x1=i;}void dispa(){cout<<"x1="<<x1<<",";}private:int x1;}:class TestClass2:public TestClass1{public:TestClass2(){}TestClass2(int i):TestClass1(i+10){x2=i:}void dispb(){dispa();cout<<"x2="<<x2<<end1;}private:int x2:}:int main(){TestClass2 b(2):b.dispb();return 0;}

考题 在下面程序的横线处填上适当的语句,使该程序的输出为12。 include using namespace st 在下面程序的横线处填上适当的语句,使该程序的输出为12。include <iostream>using namespace std;class Base{public:int a;Base(int i){a=i;}};class Derived: public Base{int a;public:Derived(int x): Base(x),b(x+l){}void show(){【 】;∥输出基类数据成员a的值。cout<<b<<end1;}};int main(){Derived d(1);d.show();return 0;}

考题 有以下程序: include using namespace std; class sample {int x; public:void setx( 有以下程序:include <iostream>using namespace std;class sample{int x;public:void setx(int i){x=i;}int putx (){return x;}};int main ( ){sample *p;sample A[3];A[0] .set>:(5);A[1] .setx(6);A[2] .setx(7);for (int j=0;j<3;j++){p=A[j];cout<<p->putx () <<", ";}cout<<end1;return 0;}执行后的输出结果是【 】。

考题 在下面程序横线处填上适当内容,使得程序的输出为9876。include using namespace std;te 在下面程序横线处填上适当内容,使得程序的输出为9876。include <iostream>using namespace std;template<class T>void f(【 】){T t;for (int i=0;i<n/2;i++){t=a Ii];a [i]=a[n-1-i];a [n-1-i]=t;}}int main ( ){int x[]={6,7,8,9};f(x,4);for (int i=0;i<4;i++)cout<<x[i];cout<<end1;return 0;}

考题 下面程序的结果【】。 include int f(int); void main() { int x=1,i; for (i=0; i 下面程序的结果【 】。include<iostream.h>int f(int);void main() {int x=1, i;for (i=0; i<3; i++)cout<<f(x)<<‘ ’ ;cout<<end1;}int f(int x){int y=1;static int z=3y++;z++;return (x+y+z);}

考题 阅读以下说明和C++码,将相应的文字填入(n)处,写在对应栏内。[说明]以下代码实现了对象引用作为函数参数,仔细阅读以下代码,分析运行结果,填入(n)处。[代码]include<iostream.h>class Sample{int x,y;public:Sample() {x=y=0; }Sample (int i, int j ) {x=i; y=j; }void copy ( Sample s ).,void setxy ( int i, int j ) {x=i; y=j; }void print ( {cout<<"x="<<x<<end1 ; cout <<"y="<<y<<end1;};void Sample: copy ( Sample s ){X=S.X;y=s.y;}void func ( Sample s1, Sample s2 ){s1.setxy ( 10,20 );s2.setxy ( 30,40 );}void main ( ){Sample p ( 1,2 ) ,q;q.copy ( p );time ( p,q );p.print ( );q.print ( );}运行结果(1)(2)(3)(4)

考题 在下面的程序的横线处填上适当的语句,使该程序的输出为12。include 〈iostream〉using namespace std;class Base{public:int a;Base(int i) { a=i;}};class Derived : public Base{int a;public:Derived(int x) : Base(x),b(x+1) {}void show(){【 】; //输出基类数据成员a的值cout〈〈b〈〈end1;}};int main(){Derived d(1);d.show();return 0;}

考题 有如下程序: include using namespace std; class Point{ int x, y; public: Point(i 有如下程序:#include<iostream>using namespace std;class Point{int x, y;public:Point(int x1=0, int y1=0):x(x1), y(y1){}int get(){return x+y;)};class Circle{Point center;int radius;public:Circle(int CX, int cy, int r):center(cx, cy), radius(r){}int get(){return center. get()+radius;}};int main(){circle c(3, 4, 5);cout<<c. get()<<end1;return ():}运行时的输出结果是( )。A) 5B) 7C) 9D) 12A.B.C.D.

考题 以下程序的执行结果是______。 include class A{ int a: public: void seta(int x) { 以下程序的执行结果是______。include<iostream.h>class A{int a:public:void seta(int x) {a=x;}void showa() {cout<<a<<end1;}};class B{int b;public:void setb(int x) {b=x;}void showb(){cout<<b<<end1;}};

考题 阅读以下说明,以及用C++在开发过程中所编写的程序代码,将应填入(n)处的字句写在对应栏内。【说明】在下面函数横线处填上适当的字句,使其输出结果为:构造函数.构造函数.1,25,6析构函数析构函数.【C++代码】include "iostream.h"class AA{ public;AA(int i,int j){A=i; B=j;cout<<"构造函数.\n";}~AA(){(1);}void print();private:int A, B;};void AA∷print(){cout<<A<<","<<B<<endl;}void main(){AA *a1, *a2;(2)=new AA(1, 2);a2=new AA(5, 6);(3);a2->print();(4) a1;(5) a2;}

考题 下列程序输出结果为: include using namespace std; class TestClass1 { public: Test 下列程序输出结果为:include<iostream>using namespace std;class TestClass1{public:TestClass1(){}TestClass1(int i){x1=i;}void dispa(){cout<<"x1="<<x1<<",";}private:int x1;};class TestClass2:public TestClass1{public:TestClass2(){}TestClass2(int i):TestClass1(i+10){x2=i;}void dispb(){dispa();cout<<"x2="<<x2<<endl;}private:int x2;};int main(){TestClass2 b(2);b.dispb();return 0;}

考题 有以下程序: include class A { intx; public: A(int a) { x=a;} friend class B; 有以下程序:include<iostream.h>class A{int x;public:A(int a){x=a;}friend class B;}class B{public:void print(A a){a. x--;cout<<a.x<<end1;}};void main(){A a(10);B b;b.print(a) ;}程序执行后的输出结果是【 】。

考题 有如下程序:include using namespace std;Class x{protected: int a;public: x() {a= 有如下程序: #include <iostream> using namespace std; Class x { protected: int a; public: x() { a=1; } }; class x1 : virtual public x { public: x1() { a+=1; cout<<A.1B.123C.242D.244

考题 有如下程序: include class x { protected: int a; public:x(){ a=1;} }; class x 有如下程序: #include <iostream.h> class x { protected: int a; public: x() { a=1; } }; class x1 : virtual public x { public: x1() { a+=1; cout<<a; } }; class x2 : virtual public x { public: x2() { a+=2; cout<<a; } }; class y : public xl,public x2 { public: y() { cout<<a<<end1; } }; int main() { y obj; return O; } 该程序运行后的输出结果是( )。A.1B.123C.242D.244

考题 下面程序中错误之处是 ______。 include classA{private:intxl;protected:intx2;publ 下面程序中错误之处是 ______。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;} //Avoid set(int i){x3=i;} //B};void main()B bb;bb. a3=10 //Cbb. b3=10 //D}

考题 若有以下程序:include using namespaces std;class A{public: A (){} A (int i) {x1= 若有以下程序: #include <iostream> using namespaces std; class A { public: A (){} A (int i) { x1=i; } void dispa() { cout<<"xl="<<xl<<" , "; } private: int x1; }; class B : public A { public: B (){} B (int i):A(i+10) { x2=i; } void dispb() { dispa (); cout <<"x2="<<x2<<end1; } private: int x2; }; int main () { B b(2); b.dispb (): return 0; } 程序运行后的输出结果是( )。A.x1=10,x2=2B.x1=12,x2=10C.x1=12,x2=2D.x1=2,x2=2

考题 请找出下列程序中错误之处 ______。 include classA{private: intx1;protected: int 请找出下列程序中错误之处 ______。#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:} //Avoid set(int i) {x2=i;} //B};void main() {B bb;bb.x3=10; //Cbb.y3=10; //D}A.AB.BC.CD.D

考题 若有以下程序:includeusing namespaces std;class A{public: A(){} A(int i) {xl=i; 若有以下程序: #include<iostream> using namespaces std; class A { public: A(){} A(int i) { xl=i; } void dispa() { cout<<"x1="<<x1<<","; } private: int x1; }; class B:public A { public: B(){} B(int i):A(i+10) { x2=i; } void dispb() { dispa(); cout<<"x2="<<x2<<endl; } private: int x2; }; int main{) { B b(2); b.dispb(): return 0; } 程序运行后的输出结果是A.x1=10,x2=2B.x1=12,x2=10C.x1=12,x2=2D.x1=2,x2=2

考题 下列程序的输出结果是includevoid main(){char*str="12123434";int x1=0,x2=0,x3=0 下列程序的输出结果是 #include<iostream.h> void main() {char*str="12123434"; int x1=0,x2=0,x3=0,x4=0,i; for(i=0;str[i]!='\0';i++) switch(str[i]) {case'1':x4++; case'2':X3++; case'3':X2++; case'4':X1++; } cout<<X1<<","<A.8,6,4,1B.8,6,3,2C.8,8,4,1D.8,6,4,2

考题 若有以下程序:includeusing namespaces std;class A{public:A(){}A(int i){x1=i; } v 若有以下程序: #include<iOStream> using namespaces std; class A { public: A(){} A(int i) { x1=i; } void dispa() { cout<<"X1="<<x1<<",": } private; int x1; }; class B:public A { public: B(){} B(int i):A(i+10) { x2=i; } void dispb() { dispa(); cout<<"x2="<<x2<<end1; } private: int x2; }; . int main() { B b(2); b.dispb() return 0; } 程序运行后的输出结果是( )。A.x1=10,x2=2B.x1=12,x2=10C.x1=12,x2=2D.x1=2,x2=2

考题 若有以下程序:include using namespaces std;class A {public: A(){} A(int i) {x1=i 若有以下程序: #include <iostream> using namespaces std; class A { public: A(){} A(int i) { x1=i; } void dispa() { cout<<'x1="<<x1<<","; } private: int x1; }; class B: public A { public: B(){} B(int i):A(i+10) { x2=i; } void dispb() { dispa(); cout<<"x2="<<x2<<end1; } private: int x2; }; int main() { B b(2); b.dispb(): return 0; } 程序运行后的输出结果是A.x1=10,x2=2B.x1=12,x2=10C.x1=12,x2=2D.x1=2,x2=2

考题 若有以下程序:include using namespace std;class point{private: int x, y;public: 若有以下程序: #include <iostream> using namespace std; class point { private: int x, y; public: point ( ) { x=0; y=0; } void setpoint(int x1,int y1) { x=x1; y=y1;A.12,12B.5,5C.12,5D.5,12

考题 若有以下程序:include using namespace std;class A{public:A() { }A(int i){x1=i;}v 若有以下程序: #include <iostream> using namespace std; class A { public: A() { } A(int i) { x1=i; } void dispa0 { cout<<"x1="<<x1<<","; } private: int x1; }; class B: public A { public: B() { } B(int i):A(i+10) { x2=i; } void dispb() { dispa(); cout<<"x2="<<x2<<endl; } private: int x2; }; int main() { B b(2); b.dispb(); return 0; } 程序运行后的输出结果是( )。A.x1=10,x2=2B.x1=12,x2=10C.x1=12,x2=2D.x1=2,x2=2

考题 在下列的程序的横线处填上适当的语句,使该程序的输出为12。include using namespace 在下列的程序的横线处填上适当的语句,使该程序的输出为12。include<iostream.h>using namespace std;class Base{public:int a,b;Base(int i){a=i;}};class Derived:public Base{int a;public:Derived(int x):Base(x),b(x+1){};void show(){