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