注意:此页面搜索的是所有试题
许昌学院面向对象程序设计
[应用题,25分]
请在横线中填入程序,完成如下PID控制仿真程序. (注意符号、标点符号、括号用半角)
#include
class AAA
{
int A,B;
public:
AAA()
{A=100;B=200;
cout<<"deflat constructing\n";
}
AAA(int i,int j)
{A=i,B=j;
cout<<"constructing\n";}
~AAA(){cout<<"destructing\n";}
void print( )
{cout<<><><><"\n";}>
friend int add(AAA &s1);
};
int add(AAA &s1)
{return (s1.A+s1.B);}
void main()
{AAA a1,*a2;
int s;
a2=new AAA(5,6);
a1.print();
a2->print();
s=add(*a2);
cout<<”s=”<<><>
delete a2;
}
运行结果是:
[应用题,25分] #include class Cdate { int day,month,year; public: Cdate () { day=1; month=1; year=1999; cout<<"default constructing\n";} Cdate (int d,int m,int y) { day=d; month=m; year=y; cout<<"constructing\n"; } ~ Cdate (){cout<<"destructing"<<><"><><><>void print( ) {cout<<><"><><>}; void main() { Cdate a1,*a2; a2=new Cdate (30,12,1996); a1.print(); a2->print(); delete a2; } 运行结果是: <"><">
[应用题,25分] #include void f(int *p1, int *p2) { int *t; t=p1;p1=p2;p2=t; } main() { int a=10,b=20; cout<<><> f(&a,&b); cout<<><> }
[应用题,25分] #include fun(int *s,int n1,int n2) { int t; while(n1<> {t=*(s+n1); *(s+n1)=*(s+n2); *(s+n2)=t; n1++;n2--; } } main() { int a[10]={1,2,3,4,5,6,7,8,9,0},i,*p=a; fun(p,0,3);fun(p+3,1,6); for(i=0;i<10;i++) { if(i%5= =0)cout<<> cout< } 运行结果:
[应用题,25分] #include #include #include main() { int a=4,b=5,c,d; cout<<”sqrt(a)=”<< sqrt(a)< c=a>b?a:b; cout<<”c=”<<> cout<<><><><> d=a; if(a>b) d=8; else if (a==b) d=0; else d=-1; cout<<”d=”<<><> } 程序运行结果为:
[应用题,25分] #include # include void fun(char *w,int m) {char s,*p1,*p2; p1=w; p2=w+m-1; while(p1<> { s=*p1;*p1=*p2;*p2=s; p1++; p2--; } } main() { char a[10]="abcdefghi"; char *p=new char[10]; strcpy(p,"student"); cout<<"compare:"<<> if(strcmp(a,p)==0) cout<<"a == p"<<> if(strcmp(a,p)>0) cout<<"a > p"<<> if(strcmp(a,p)<0) cout<<"a < p"<<> cout<<"before:\n"; cout<<><> cout<<><> cout<<"call fun"<<> fun(a,strlen(a)); fun(p,strlen(p)); cout<<"after:\n"; cout<<><> cout<<><> } 程序运行结果为:
[应用题,25分] #include float const PI=3.14; class point { private: float x,y,area; public: point(float x1=0.0,float y1=0.0) { cout<<"point构造函数被调用!\n"; } virtual ~point() { cout<<"point析构函数被调用!\n";} virtual float getarea(){return 0.0;} }; class circle:public point {private: float r; public: circle(float x1,float y1,float Nr):point(x1,y1) { r=Nr; cout<<"circle构造函数被调用!\n "; } ~circle(){cout<<"circle析构函数被调用!\n";} float getarea() { return PI*r*r; } }; void main() { point *p,p1(3,4); p=&p1; cout<getarea()< circle c(1,1,1); p=&c; cout<getarea()<<> } 程序运行结果为:
[应用题,25分] #include class Test; void fun1(Test t); Test fun2(); class Test { public: Test(int n=1) {val=n; cout<<"Con."< Test(const Test& t) {val=t.val; cout<<"Copy con."<<> Test& operator = (Test& t) { val=t.val; cout<<"Assignment."<<> return *this; } private: int val; }; void main() { Test t1(1); Test t2=t1; Test t3; t3=t1; fun1(t2); t3=fun2(); } void fun1(Test t){} Test fun2() { Test t; return t; } 运行结果为:
[应用题,11.1分] int fun (int i, int j) { int s; i=i+2; j=j-1; s=i+j; return s; } void main() { int i=4, j=5; cout<<><”><><”=""><="" fun(i,j)="">}; 程序运行结果为:<”>
[应用题,11.1分] int y=1, x, *p, a[ ]={2,4,6,8,10}; p=&a[1]; for(x=0;x<3;x++) y + = * (p + x); cout<<> 程序运行结果为:
[应用题,11.1分] #include class A{ int a; public: A(int aa=0){a=aa;} ~A(){cout<<"Destructor A!"<<><> }; class B : public A{ int b; public: B(int aa=0,int bb=0):A(aa){b=bb;} ~B(){cout<<"Destructor B!"<<><> }; void main() { B x(5),y(6,7);: } 程序运行结果为:
[应用题,11.1分] lass Box{ private: int a,b,c; public: Box(int a1,int b1,int c1) { a=a1; b=b1; c=c1;} int volum() { int v; v=a*b*c; return v; }}; void main() { Box box(4,5,6); cout<<” 体积为:”<<> } 程序运行结果为:
[应用题,11.2分] #include #include void main() { int i, max; char ch; char str[]="1234567"; for(i=0,j=strlen(str)-1;i;i++,j-- ) { ch=str[i]; str[i]=str[j]; str[j]=ch; } cout<<><> } 程序运行结果
[应用题,11.1分] 不用第三个变量,实现两个数的对调操作。 #include int main() { int a,b; cin>>a>>b; cout<<><><>< p=""> a= 【?】 ; b= 【?】 ; a= 【?】 ; cout<<><>< p=""> }
[应用题,11.1分] 分别求出一批非零整数中的偶数、奇数的平均值,用零作 为终止标记。 #include int main() { int x,i=0,j=0; float s1=0,s2=0,av1,av2; cin>>x; while(【?】) { if(x%2==0) {s1=s1+x;i++;} 【?】 { s2=s2+x; j++; } 【?】; } if(i!=0) av1=s1/i; else av1=0; if(j!=0) 【?】 ; else av2=0; cout<<"oushujunzhi:"<<"jishujunzhi><><><>< p=""> return 0; } <><><>
[应用题,25分] #include class Cdate { int day,month,year; public: Cdate () { day=1; month=1; year=1999; cout<<"default constructing\n";} Cdate (int d,int m,int y) { day=d; month=m; year=y; cout<<"constructing\n"; } ~ Cdate (){cout<<"destructing"<<><"><><><>void print( ) {cout<<><"><><>}; void main() { Cdate a1,*a2; a2=new Cdate (30,12,1996); a1.print(); a2->print(); delete a2; } 运行结果是: <"><">
[应用题,25分] #include void f(int *p1, int *p2) { int *t; t=p1;p1=p2;p2=t; } main() { int a=10,b=20; cout<<><> f(&a,&b); cout<<><> }
[应用题,25分] #include fun(int *s,int n1,int n2) { int t; while(n1<> {t=*(s+n1); *(s+n1)=*(s+n2); *(s+n2)=t; n1++;n2--; } } main() { int a[10]={1,2,3,4,5,6,7,8,9,0},i,*p=a; fun(p,0,3);fun(p+3,1,6); for(i=0;i<10;i++) { if(i%5= =0)cout<<> cout< } 运行结果:
[应用题,25分] #include #include #include main() { int a=4,b=5,c,d; cout<<”sqrt(a)=”<< sqrt(a)< c=a>b?a:b; cout<<”c=”<<> cout<<><><><> d=a; if(a>b) d=8; else if (a==b) d=0; else d=-1; cout<<”d=”<<><> } 程序运行结果为:
[应用题,25分] #include # include void fun(char *w,int m) {char s,*p1,*p2; p1=w; p2=w+m-1; while(p1<> { s=*p1;*p1=*p2;*p2=s; p1++; p2--; } } main() { char a[10]="abcdefghi"; char *p=new char[10]; strcpy(p,"student"); cout<<"compare:"<<> if(strcmp(a,p)==0) cout<<"a == p"<<> if(strcmp(a,p)>0) cout<<"a > p"<<> if(strcmp(a,p)<0) cout<<"a < p"<<> cout<<"before:\n"; cout<<><> cout<<><> cout<<"call fun"<<> fun(a,strlen(a)); fun(p,strlen(p)); cout<<"after:\n"; cout<<><> cout<<><> } 程序运行结果为:
[应用题,25分] #include float const PI=3.14; class point { private: float x,y,area; public: point(float x1=0.0,float y1=0.0) { cout<<"point构造函数被调用!\n"; } virtual ~point() { cout<<"point析构函数被调用!\n";} virtual float getarea(){return 0.0;} }; class circle:public point {private: float r; public: circle(float x1,float y1,float Nr):point(x1,y1) { r=Nr; cout<<"circle构造函数被调用!\n "; } ~circle(){cout<<"circle析构函数被调用!\n";} float getarea() { return PI*r*r; } }; void main() { point *p,p1(3,4); p=&p1; cout<getarea()< circle c(1,1,1); p=&c; cout<getarea()<<> } 程序运行结果为:
[应用题,25分] #include class Test; void fun1(Test t); Test fun2(); class Test { public: Test(int n=1) {val=n; cout<<"Con."< Test(const Test& t) {val=t.val; cout<<"Copy con."<<> Test& operator = (Test& t) { val=t.val; cout<<"Assignment."<<> return *this; } private: int val; }; void main() { Test t1(1); Test t2=t1; Test t3; t3=t1; fun1(t2); t3=fun2(); } void fun1(Test t){} Test fun2() { Test t; return t; } 运行结果为:
[应用题,11.1分] int fun (int i, int j) { int s; i=i+2; j=j-1; s=i+j; return s; } void main() { int i=4, j=5; cout<<><”><><”=""><="" fun(i,j)="">}; 程序运行结果为:<”>
[应用题,11.1分] int y=1, x, *p, a[ ]={2,4,6,8,10}; p=&a[1]; for(x=0;x<3;x++) y + = * (p + x); cout<<> 程序运行结果为:
[应用题,11.1分] #include class A{ int a; public: A(int aa=0){a=aa;} ~A(){cout<<"Destructor A!"<<><> }; class B : public A{ int b; public: B(int aa=0,int bb=0):A(aa){b=bb;} ~B(){cout<<"Destructor B!"<<><> }; void main() { B x(5),y(6,7);: } 程序运行结果为:
[应用题,11.1分] lass Box{ private: int a,b,c; public: Box(int a1,int b1,int c1) { a=a1; b=b1; c=c1;} int volum() { int v; v=a*b*c; return v; }}; void main() { Box box(4,5,6); cout<<” 体积为:”<<> } 程序运行结果为:
[应用题,11.2分] #include #include void main() { int i, max; char ch; char str[]="1234567"; for(i=0,j=strlen(str)-1;i;i++,j-- ) { ch=str[i]; str[i]=str[j]; str[j]=ch; } cout<<><> } 程序运行结果
[应用题,11.1分] 不用第三个变量,实现两个数的对调操作。 #include int main() { int a,b; cin>>a>>b; cout<<><><>< p=""> a= 【?】 ; b= 【?】 ; a= 【?】 ; cout<<><>< p=""> }
[应用题,11.1分] 分别求出一批非零整数中的偶数、奇数的平均值,用零作 为终止标记。 #include int main() { int x,i=0,j=0; float s1=0,s2=0,av1,av2; cin>>x; while(【?】) { if(x%2==0) {s1=s1+x;i++;} 【?】 { s2=s2+x; j++; } 【?】; } if(i!=0) av1=s1/i; else av1=0; if(j!=0) 【?】 ; else av2=0; cout<<"oushujunzhi:"<<"jishujunzhi><><><>< p=""> return 0; } <><><>