出自:许昌学院面向对象程序设计

[填空题,100分] 一个函数在执行时直接或间接的又调用该函数自身的调用过程称为 ______ 。
在类定义中,数据和成员函数默认权限是_________.
[填空题,100分] 在C++中,访问一个指针所指向的对象的成员所用的运算符是_________。
[填空题,100分] 在C++中,访问一个对象的成员所用的运算符是_________。
[填空题,100分] 在类对象生命期结束时,自动调用__________函数。
[填空题,100分] 当建立一个新对象时,程序自动调用该对象的_______________函数。
c++程序有且必须有一个 __________ 函数
[填空题,100分] 类定义中,缺省的成员是________成员.
[分析题,4分] #include<iostream.h> void main() { int i=0,j=1,k; k=i+=j; cout<<i<<’ ’<<j<<’ ’<<k<<endl; k=(i++)*(++j); cout<<i<<’ ’<<j<<’ ’<<k<<endl; k*=i++*j--; cout<<i<<’ ’<<j<<’ ’<<k<<endl; }
[分析题,4分] class Student { int studentNo; static int count; public: Student() { count++;StudentNo=count;} void print(){ cout<<StudentNo<<endl; }};int Student::count=0;main(){ Student student1; student1.print(); Student student2;student2.print();student *p;p= new Student;p->print();}
[分析题,4分] #include int cube(int); void main(void) { cout<<”cube(3)=”< cout<<”cube(5)=”< cout<<”cube(8)=”<} int cube(int x) { return x*x*x; }
[分析题,4分] class my_ base{ int a,b; public: base(int x,int y) {a=x;b=y;} virtual void show(){ cout<<“base”; cout< } }; class my_class:public base{ int c: public: my_class(int x,int y,int z):my_base(x,y){c=z;} void show(){cout<<“my_class ”<<“c=”< } void main { my_base mb(50,50),*mp; my_class mc(10,20,30); mp=&mb; mp->show(); mp=&mc; mp->show(); }
[分析题,4分] class Base{ protected: int a;public:Base(int x,){a=x;}virtual void show(){ cout<<“base”<<endl; cout<<a<<“ “<<endl;}};class my_class:public Base{int b:public: my_class(int x,int y): Base(x){ b=y;}void show(){ cout<<“my_class” <<“a=”<<a <<“b=”<<b;}};void main{Base ma(50),*mp;my_class mb(10,20);mp=&mb;mp->show();mp=&ma;mp->show();}
[分析题,4分] #include<iostream.h> void main() { int x=5; switch(2*x-3) { case 4: cout<<x<<’ ’; case 7: cout<<2*x+1<<’ ’; case 10: cout<<3*x-1<<’ ’;break; default: cout<<”default”<<endl; } cout<<”switch end.”<<endl; }
[分析题,4分] #include<iostream.h> void main() { int a=2,b=5,c=4; if(a+b>10)c=a*b;else c=3*a+b; if(c<=20) cout<<c*c;else cout<<4+c-5; cout<<endl; a=a+b;b=a+b;c=a+b+c; cout<<”a,b,c=”<<a<<’,’<<b<<’,’<<c<<endl; }
[分析题,4分] #include<iostream.h> void main() { int x=10,y=-1; cout<<((x>y)&&(y<0))<<’ ’; cout<<((x>y)||(y<0))<<’ ’; cout<<((x<=y)&&(y>=0))<<’ ’; cout<<((x<=y)||(y>=0))<<’ ’; cout<<((x==y)&&y)<<’ ’; cout<<((x==y)||y)<<’ ’; }
[分析题,4分] #include<iostream.h> void main() { int x,y; x=5;y=6; cout<<”x+y=”<<x+y<<’,’; cout<<”x*y=”<<x*y<<endl; }
[分析题,4分] #include <iostream.h>cass complex{ private: double real, image; complex( ) { real =0.0;image=0.0;}complex(double r, double i) { real =r; image=i; }void print(){cout<<real<<’+’<<image<<’i’<<endl;}friend complex operator+(complex col ,complex co2);}; complex operator+(complex col ,complex co2) { complex temp; temp.real=col.real+co2.real; temp.imag=col.imag+co2.imag; return temp;}main(){ complex c1(1.1,2.2), c2(3.3,4.4), sum; c1.print(); sum=c1+c2; sum.print();}
[分析题,4分] #include<iomanip.h> #include”abc.h” void main() { double a,b,c; double averageValue; a=2;b=3;c=4; averageValue=AVE(a,b,c); cout<<”averageValue;”<<averageValue<<endl; averageValue=AVE(a,b+1,c+2); cout<<”averageValue:”<<averageValue<<endl; }其中abc.h文件的内容如下: double AVE(double x,double y,double z) { return (x+y+z)/3; }
[分析题,4分] #include<iostream.h> void main() { cout<<sizeof(bool)<<’ ’<<sizeof(char)<<’ ’; cout<<sizeof(short)<<’ ’<<sizeof(int)<<’ ’; cout<<sizeof(long)<<’ ’<<sizeof(float)<<’ ’; cout<<sizeof(double)<<’ ’<<sizeof(long double)<<’ ’; cout<<sizeof(int *)<<’ ’<<sizeof(double *)<<’ ’; }
[分析题,4分] #include ”iostream.h”class three{ int x,y,z; public: three(int a,int b,int c){ x=a;y=b;z=c;} friend ostream &operator<<(ostream &output, three ob); };ostream &operator<<(ostream &output, three ob){ output<<ob.x<<’,’<<ob.z<<’,’<<ob.y<<endl; return output;}main(){ three obj1(10,20,30); cout<<obj; three obj2(50,40,100);cout<<obj2; }
[分析题,4分] #include “iostream.h” class A{ public: A( ) { cout<<”A begins” ; } ~A( ) { cout<<”A ends”; } void print( ) { cout<<”I am A”; } virtual void show() { cout<<”A is great”; } } }; class B :public A{ public: B( ) { cout<<”B begins” ; } ~B( ) { cout<<”B ends” ; } void print ( ) { cout<<”I am B” ; } void show() { cout<<”B is great” } }; void main( ) { A obj_b; A *p; p=new B; p->show(); p=&obj_b; p->print(); }
[分析题,4分] #include<iostream.h> int f1(int x,int y){ x=x+y;y=x+y; cout<<”x=”<<x<<”,y=”<<y<<endl; return x+y;}void main(){ int x=5,y=8; int z=f1(x,y); cout<<”x=”<<x<<”,y=”<<y; cout<<”,z=”<<z<<endl;}
[分析题,4分] #include<iostream.h> void main() { for(int i=1,s=0;i<7;i++) { if(i%2==0||i%3==0)continue; cout<<i<<’ ’; s+=I; } cout<<s<<endl; }
[分析题,4分] #include<iomanip.h> const int M=20; void main() { int c2,c3,c5; c2=c3=c5=0; for(int i=1;i<=M;i++) { if(i%2==0) c2++; if(i%3==0) c3++; if(i%5==0) c5++; } cout<<c2<<’ ‘<<c3<<’ ‘<<c5<<endl; }
[分析题,4分] #include<iostream.h> class A { int a,b; public: A(int aa=0,int bb=0):a(aa),b(bb){ cout<<”Constructor!”<<a+b<<endl; }}; void main(){ A x, y(2,3), z(y); }
[分析题,4分] #include<iostream.h> classA { int a,b; public: A(){ a=b=0; } A(int aa,int bb){ a=aa;b=bb; cout<<a<<’ ‘<<b<<endl; }}; void main(){ A x, y(2,3), z(4,5); }
[分析题,4分] #include<iostream.h> #define PI 3.14159 const int R=10 void main() { double p,s; p=2*R*PI; s=PI*R*R; cout<<”p=”<<p<<endl; cout<<”s=”<<s<<endl; }
[分析题,4分] #include enum race{Black,White,Yellow}; void main() { race ra; ra=Black;cout< ra=White;cout< ra=Yellow;cout< cout< }
[分析题,4分] #include<iostream.h> void fun10(int *a[],int m,int n) { int i,j; for(i=0;i<m;i++) a[i]=new int [n]; for(i=0;i<m;i++) for(j=0;j<n;j++) a[i][j]=(i+1)*(j+1); } void main() {int m1=2,n1=2; int **b=new int *[m1]; fun10(b,m1,n1); for(int i=0;i<m1;i++){ for(int j=0;j<n1;j++) cout<<b[i][j]<<’ ’; cout<<endl; } }
[分析题,4分] #include “iostream.h” class G{ public: static int m; G( ) //构造函数 { m++; cout<<”G begins” ; } ~F( ){ cout<<”G ends”; m--; } };class D:public G{ public: D( ) //构造函数 { m++; cout<<”D begins”; } ~F( ){ cout<<”D ends” ; m-- ; } };void main( ){ D objg; cout<<G::m ;}
[分析题,4分] #include “iostream.h” #include “stdio.h”class timer{ //定义一个时间类int seconds;public:timer();{ seconds=0; }timer(int x){ seconds=x; } timer(int min,int sec){seconds=min*60+sec;}int gettime(){return seconds;}};main(){ timer a, b(10),c(1,10); cout<<a.gettime()<<’endl; cout<<b.gettime()<<endl; cout<<c.gettime()<<endl; return 0;}
[分析题,4分] #include <iostream.h>int a[ 10 ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };int fun( int i );void main(){ int i ,s = 0; for( i = 0; i <= 10; i++ ) { try { s = s + fun( i ) ; } catch( int ) { cout << "数组下标越界!" << endl; } } cout << "s = " << s << endl;}int fun( int i ){ if ( i >= 10 ) throw i ; return a[i] ;}