注意:此页面搜索的是所有试题
许昌学院面向对象程序设计
[分析题,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] ;}