给出下面程序输出结果。 #include lt;iostream.hgt; class Base { private: int Y; public: Base(int y=0) {Y=y;coutlt;lt;quot;Base(quot;lt;lt;ylt;lt;quot;)\nquot;;} ~Base() {coutlt;lt;quot;~Base()\nquot;;} void print() {cout lt;lt;Ylt;lt; quot;quot;;} }; class Derived:public Base {private: int Z; public: Derived (int y, int z):Base(y) { Z=z; coutlt;lt;quot;Derived(quot;lt;lt;ylt;lt;quot;,quot;lt;lt;zlt;lt;quot;)\nquot;; } ~Derived() {coutlt;lt;quot;~Derived()\nquot;;} void print() {Base::print(); coutlt;lt;Zlt;lt;endl; } }; void main() {Derived d(10,20); d.print(); }
|
|
指出下面程序错误的地方,并修改: #include lt;iostream.hgt; class Test { int x,y; public: fun(int i,int j) {x=i;y=j;} show() {coutlt;lt;quot;x=quot;lt;lt;x; if(y) coutlt;lt;quot;,y=quot;lt;lt;ylt;lt;endl; coutlt;lt;endl;} }; void main() {Test a; a.fun(1); a.show(); a.fun(2,4); a.show(); }
|
|
指出下面程序错误的地方: #include lt;iostream.hgt; class Test { private: int x,y=20; public: Test(int i,int j){x=i,y=j;} int getx(){return x;} int gety(){return y;} }; void main() { Test mt(10,20); coutlt;lt;mt.getx()lt;lt;endl; coutlt;lt;mt.gety()lt;lt;endl; }
|
|
C++的流库预定义了4个流,他们分别是什么? |
|
编写C++程序一般需经过的步骤是什么? |
|
什么函数不能声明为虚函数?
|
|
编写一个函数找出一个整数数组中,第二大的数。
|
|
分析一下这段程序的输出: class B { public: B() { coutlt;lt;quot;default constructorquot;lt;lt;endl; } ~B() { coutlt;lt;quot;destructedquot;lt;lt;endl; } B(int i):data(i) // { coutlt;lt;quot;constructed by parameter quot; lt;lt; data lt;lt;endl; } private: int data; }; B Play( B b) { return b ; } int main(int argc, char* argv[]) { B t1 = Play(5); B t2 = Play(t1); return 0; }
|
|
文件中有一组整数,编写程序要求排序后输出到另一个文件中。
|
|
struct和 class 的区别是什么?
|
|
多态的作用是什么?
|
|
重载( overload) 和重写 (overried)的区别是什么?
|
|
将 “ 引用 ” 作为函数参数有哪些特点?
|
|
什么是 “ 引用 ” ?申明和使用 “ 引用 ” 要注意哪些问题?
|
|
子类析构时要调用父类的析构函数吗?
|
|
C++有哪些面向对象特点?
|
|
“继承”的优缺点是什么?
|
|
指出下面程序错误的地方,并说明理由: MemTest*mTest1=newMemTest[10]; MemTest*mTest2=newMemTest; int*pInt1=newint[10]; int*pInt2=newint; delete[]pInt1; //-1- delete[]pInt2; //-2- delete[]mTest1;//-3- delete[]mTest2;//-4-
|
|
请问delete与 delete [] 有何区别?
|
|
请阐述new 、 delete 、 malloc 和 free 之间的关系。
|
|
定义一个如下的模拟数字式时钟的类clock,请编写模拟时间更新动作和时间显示的成员函数代码,并通过程序运行设当前时钟为23:58:36,对时钟对象进行126次更新演示。class Clock{ int hour,minute,second; public ; clock(int h=0,int m=0,int s=0){hour=h:minute=m;second=S:} void update( );//模拟时间动作 vold display( );//模拟时间显示 };
|
|
从键盘输入10个整数,然后按有效到达的顺序排列。 |
|
阅读下面的程序,回答问题: #include lt;iostream.hgt; class A{ public: void f1(); A(){i1=21;j1=31;} protected: int j1; private: int i1; }; class B: private A { public: void f2(); B(){ i2=22;j2=32;} protected: int j2; private: int i2; } class C: public B { public: void f3(); C(){i3=23;j2=33;} protected: int j3; private: int i3; } 问题: 1、派生类B中的成员函数f2()能否访问基类A中的成员f1()、i1和j1? 2、派生类B的对象b能否访问基类A中的成员f1()、i1和j1? 3、派生类C中的成员函数f3()能否访问基类B中的成员f2()、i2和j2? 能否访问基类A中的成员f1()、i1和j1? 4、派生类C的对象c能否访问基类A中的成员f1()、i1和j1? 能否访问基类B中的成员f2()、i2和j2? 5、说明你的分析依据
|
|
利用BufferedReader和BufferedWriter在文件中实现输入输出字符串。 |
|
将如下三组不同类型的数据利用DataInputStream和DataOutputStream写入文件,然后从文件中读出。 三组数据如下 { 19.99, 9.99, 15.99,3.99, 4.99 }; { 12, 8, 13, 29, 50 }; { quot;Java T-shirtquot;, quot;Java Mugquot;, quot;Duke Juggling Dollsquot;, quot;Java Pinquot;,quot;Java Key Chainquot;}
|
|
编写一个测试文件一般属性(如显示文件的路径、绝对路径、显示文件是否可写、显示文件是否可读、显示文件的大小等属性)的程序。 |
|
什么叫流?简述流的分类?
|
|
利用StringBuffer类编写从键盘读入字符串、整数、实型数,并在屏幕上输出。 |
|
编一个应用程序,按行顺序地读取一个可读文件的内容。 |
|
#includelt;iostream.hgt; class A{ public: virtual void pr(){coutlt;lt;quot;1quot;lt;lt;endl;} }; class B:public A{ void pr(){coutlt;lt;quot;2quot;lt;lt;endl;} }; void p1(Aamp;a) {a.pr();} void p2(A a) {a.pr();} void main(){ B b; p1(b); p2(b); }
|
|
#includelt;iostream.hgt; class A{ public: A(int i=0){a=i;} void print(){coutlt;lt;Alt;lt;#39;,#39;;} private: int a; }; class B:public A{ public: B(){b1=b2=0;} B(int i){b1=i;b2=0;} B(int i,int j,int k):A(i),b1(j),b2(k){} void print(){A::print();coutlt;lt;B1lt;lt;#39;,#39;lt;lt;B2lt;lt;endl;} private: int b1,b2; };
void main(){ B d1,d2(5),d3(4,5,6); d1.print();d2.print();d3.print(); }
|
|
#includelt;iostream.hgt; class goods{ private: static int totalweight; int weight; public: goods(int w){ weight=w; totalweight+=weight; } goods(goodsamp;gd){ weight=gd.weight; totalweight+=weight; } ~goods(){ totalweight-=weight; } static int gettotal(){ return totalweight; } }; int goods::totalweight=0; void main(){ goods g1(50); coutlt;lt;goods::gettotal()lt;lt;endl; goods g2(100); coutlt;lt;G2.GETTOTAL()lt;lt;endl; }
|
|
#includelt;iostream.hgt; templatelt;CLASSamp;Tgt; void f(T *a,int n){ int k; T t; for (int i=0;ilt;N-1;I++){ k=i; for (int j=i+1;jlt;n;j++) if(a[k]gt;a[j]) k=j; t=a[i];a[i]=a[k];a[k]=t;} }; void main(){ double d[5]={12.3,4.5,-23.4,-90.4,0}; char a[5]={#39;B#39;,#39;F#39;,#39;A#39;,#39;X#39;,#39;E#39;}; f(a,5); f(d,5); for (int i=0;ilt;5;i++) coutlt;lt;D[i]lt;lt;quot; quot;lt;lt;A[i]lt;lt;endl; }
|
|
分析下列程序中的错误,并说明出错原因。#include lt;iostream.hgt; class AA{ int aa; AA(int xx){aa=xx;} public : int get( ){return aa;} ~AA( ){coutlt;lt;quot;Destroyingquot;lt;lt;AAlt; }; main( ) {AAelem[3]={5,8,4}; for(*int i=0;ilt;3;i++)coutlt;lt;ELEM[I].GET( )lt;lt;#39;,#39;; }
|
|
分析下列程序中的错误,并说明出错原因。#include lt;iostream.hgt; void fun( ) {ifstreammyfile(quot;d:\abcdquot;); myfilelt;lt;quot;myfile\nquot;; } void main( ) {fun( );}
|
|
分析下列程序中的错误,并说明出错原因。#include lt;iostream.hgt; class A{ int x; public : A(int a){x=a;fun( );} virtual void fun( )=0; }; class B:public A{ public : B(int b):A(b){} void fun( ){} }; void main( ) {Aaa(5); Bbb(8); }
|
|
分析下列程序中的错误,并说明出错原因。#include lt;iostream.hgt; class AA{ public :int aa; }; class BB:virtual public AA{ int bb; }; class CC:virtual public AA{ public :int bb; }; class DD:public BB,public CC{ public :float dd; }; void main( ) {DDp; int m=p.aa; AA*pr=amp;p; AAamp;pt=p; DD*pp=(DD*)(BB*)pr; AAr; DDamp;ps=r; }
|
|
分析下列程序中的错误,并说明出错原因。#include lt;iostream.hgt; class base{ const int n; public : base( ){coutlt;lt;quot;Initializingdefault\nquot;;} base(int m){coutlt;lt;quot;Initializing\nquot;;n=m;} ~base( ){coutlt;lt;quot;Destroying\nquot;;} }; void main( ){base x=1;base y=x;}
|
|
定义一个时间类Time,能提供由时.分.秒组成的时间。 |
|
编写一个有关日期(年.月.日)和时间(时.分.秒)的程序。该程序建立三个类,其中一个是日期的类Date,一个是时间的类Time,另一个是日期和时间类DateTime,它是以前面两个类为基类的派生类。 |
|
通过函数重载实现用max( )求出两整数.实数.字符串中的较大者并通过具体实例予以演示。 |
|
请给出下面的程序的输出结果。#include lt;iostream.hgt; template void sort(T*a,int n) {Tnum; for(int i=0;ilt;N-1;i++) {for(int j=i;jlt;N-1;j++) if(a[j]gt;a[j+1]) {num=a[j];a[j]=a[j+1];a[j+1]=num;} } for(i=0;ilt;N;I++)coutlt;lt;A[I]; coutlt;lt;endl; } void main( ) {int iver[5]={12,45,9,23,37}; double dver[5]={22.3,56.7,43.5,13.8,8.6}; sort(iver,5); sort(dver,.5); }
|
|
写出下列程序的输出结果。#includelt;iostream.hgt; class AA{ public : AA{}{coutlt;lt;quot;ConstructorofAA.\nquot;;fun( );} virtual void fun( ){coutlt;lt;quot;AA::fun( )is called.\nquot;;} }; class BB:public AA{ public : BB( ){coutlt;lt;quot;Constructor of BB.\nquot;; fun( );} void fun( ){coutlt;lt;quot;BB::fun( )is called.\nquot;;} }; void main( ){BB d;}
|
|
写出下列程序的运行结果。#includelt;iostream.hgt; class AA{ public : static int n; AA( ){n++;} }; int AA::n=0; main( ) { coutlt;lt;quot;AA::n=quot;lt;lt;AA::nlt;lt;endl;AA d1;coutlt;lt;lt;d1.nlt;lt;endl; AA d2;coutlt;lt;lt;D2.nlt;lt;endl;AA d3,d4;coutlt;lt;lt;d1.nlt;lt;endl; coutlt;lt;lt;d2.nlt;lt;endl; }
|
|
写出下面程序的执行结果:
#includelt;iostream.hgt; class AA{ int a; public : AA(int i){a=i;coutlt;lt;quot;AA=quot;lt;lt;alt;lt;quot;\nquot;;} virtual ~AA( ){coutlt;lt;quot;~AA=quot;lt;lt;alt;lt;quot;\nquot;;} }; class BB:public AA{ int b; public : BB(int i,int j):AA(i){b=j;coutlt;lt;quot;BB=quot;lt;lt;blt;lt;quot;\nquot;;} ~BB( ){coutlt;lt;quot;~BB=quot;lt;lt;blt;lt;quot;\nquot;;} }; void main( ) {AA *pa=new AA(8); delete pa; AA*pb=new BB(6,9); delete pb; }
|
|
写出下面程序的执行结果:
#includelt;iostream.hgt; class AA{ int a; public : AA( ){coutlt;lt;quot;Initualizing AA!\nquot;;} ~AA( ){coutlt;lt;quot;Destroying AA!\nquot;; }; class BB{ int b; AA p; public : BB( ){coutlt;lt;quot;Initualizing BB!\nquot;;} ~BB( ){coutlt;lt;quot;Destroying BB!\nquot;; }; void main( ) {BB X; coutlt;lt;quot;Ending main!\nquot;; }
|
|
#includelt;iostream.hgt; int add(int x,int y){return x+y;} void main( ) {int m=2,n=3; coutlt;lt;quot;1:quot;lt;lt;add(m++,m+n)lt;lt;endl; m=2,n=3; coutlt;lt;quot;2:quot;lt;lt;add(++m,m+n)lt;lt;endl; m=2,n=3; coutlt;lt;quot;3:quot;lt;lt;lt;endl; m=2,n=3; coutlt;lt;quot;4:quot;lt;lt;lt;endl; }
|
|
写出下面程序的执行结果: #includelt;iostream.hgt; class A{ public : A( ){} virtual void f( ){coutlt;lt;quot;A::f( )iscalleD.\nquot;;} }; class B:public A{ public : B( ){f( );} void g( ){f( );} }; class C:public B{ public : C( ){} virtual void f( ){coutlt;lt;quot;C::f( )is called.\nquot;;} }; void main( ) {Cc;C.g( );}
|
|
写出下面程序的执行结果: #includelt;iostream.hgt; class B{ protected: int b; public : B(int i){b=i+50;show( );} B( ){} virtual void show( ){coutlt;lt;quot;B::show( ) is called.b=quot;lt;lt;blt;lt;endl;} }; class D:public B{ protected: int d; public : D(int i):B(i){d=i+100;show( );} D( ){} void show( ){coutlt;lt;quot;D::show( )iscalleD.d=quot;lt;lt;dlt;lt;endl;} }; void main( ){D d1(108);}
|
|
写出下面程序的执行结果: #includelt;iostream.hgt; class A{ int a,b; public : A(int i,int j){a=i;b=j;} void move(int x,int y){a+=x;b+=y;} void show( ){coutlt;lt;quot;(quot;lt;lt;alt;lt;quot;,quot;lt;lt;blt;lt;quot;)\nquot;;} }; class B:public A{ int x,y; public : B(int i,int j,int k,int l):A(i,j),x(k),y(l){} void show( ){coutlt;lt;xlt;lt;quot;,quot;lt;lt;ylt;lt;endl;} void fun( ){ move(3,5);} void f1( ){ A::show( ); } }; void main( ) {Ae(1,2);e.show( );Bd(3,4,5,6); D.fun( ); D.A::show( );D.B::show( ); D.f1( ); }
|
|
写出下面程序的执行结果:
#includelt;iostream.hgt; class A{ int a,b; public : A(int i,int j){a=i;b=j;} void move(int x,int y){a+=x;b+=y;} void show( ){coutlt;lt;quot;(quot;lt;lt;alt;lt;quot;,quot;lt;lt;blt;lt;quot;)\nquot;;} }; class B:privateA{ int x,y; public : B(int i,int j,int k,int l):A(i,j){x=k; y=l;} void show( ){coutlt;lt;xlt;lt;quot;,quot;lt;lt;ylt;lt;endl;} void fun( ){move(3,5);} void f1( ){ A::show( ); } }; void main( ) {A e(1,2);e.show( ); Bd(3,4,5,6); D.fun( ); D.show( ); D.f1( ); }
|
|
写出下面程序的执行结果:
#includelt;iostream.hgt; class A{ private: int a,b; public : A( ); A(int i,int j); void print ( ); }; A::A( ) { a=b=0; coutlt;lt;quot;Default constructor is called.\nquot;; } A::A(int i,int j) { a=i; b=j; coutlt;lt;quot;Constructor is called.\nquot;; } void A::print ( ) { coutlt;lt;quot;a=quot;lt;lt;alt;lt;quot;,quot;lt;lt;quot;b=quot;lt;lt;blt;lt;endl; } void main( ) { Am,n(4,8); m.print ( ); n.print ( ); }
|
|
写出下面程序执行结果:
#includelt;iostream.hgt; void swap(int amp;,int amp;); void main( ) {int a=5,b=8; coutlt;lt;quot;a=quot;lt;lt;alt;lt;quot;,quot;lt;lt;quot;b=quot;lt;lt;blt;lt;endl; swap(a,b); coutlt;lt;quot;a=quot;lt;lt;alt;lt;quot;,quot;lt;lt;quot;b=quot;lt;lt;blt;lt;endl; } void swap(int amp;x,int amp;y) {int temp=x; x=y; y=temp;}
|
|