网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

有如下程序:

}}}}include<iostream>

using namespace std;

class Pair{

int m;

int n;

public:

Pair(int i,int J):m(i),n(J){}

bool operator>(Pair P)const; //需在类体外给出定义

};

int main(){

Pair pl(3,4),p2(4,3),p3(4,5);

COUt<<(pl>p2)<<(p2>p1)<<(p2>p3)<<(p3>p2);

return 0;

{

运算符函数operator>功能是比较两个Pair对象的大小,当左边对象大时,返回true,否则返回false。比较规则是首先比较两对象的m成员,m大者为大;当m相等时比较n.n大者为大。程序输出0101,下列对运算符重载函数的正确定义是

A.bool Pair::operator>(Pair P)const {if(m!=P.m)return m>P.m;return n>P.n;)

B.bool Pair::operator>(Pair P) {if(m!=P.m)return m>P.m;return n>P.n;)

C.bool Pair::operator>(Pair P)const {if(m>P.m)return true;return 11>P.n;)

D.bool Pair::operator>(Pair P) {if(m>P.m)return true;return 11>P.n;}


参考答案

更多 “ 有如下程序:}}}}includeiostreamusing namespace std;class Pair{int m;int n;public:Pair(int i,int J):m(i),n(J){}bool operator(Pair P)const; //需在类体外给出定义};int main(){Pair pl(3,4),p2(4,3),p3(4,5);COUt(plp2)(p2p1)(p2p3)(p3p2);return 0;{运算符函数operator功能是比较两个Pair对象的大小,当左边对象大时,返回true,否则返回false。比较规则是首先比较两对象的m成员,m大者为大;当m相等时比较n.n大者为大。程序输出0101,下列对运算符重载函数的正确定义是A.bool Pair::operator(Pair P)const {if(m!=P.m)return mP.m;return nP.n;)B.bool Pair::operator(Pair P) {if(m!=P.m)return mP.m;return nP.n;)C.bool Pair::operator(Pair P)const {if(mP.m)return true;return 11P.n;)D.bool Pair::operator(Pair P) {if(mP.m)return true;return 11P.n;} ” 相关考题
考题 现有如下程序段#include "stdio.h"int fun(int k,int *m){if(k%3)*m=k*k;else *m=k/3;}main(){ int (*p)(int,int *),m;p=fun;(*p)(78, m);printf( "%d\n",m);}则程序段的输出结果为A.24B.25C.26D.27

考题 有如下程序: include using namespace std; class Pair{ int m, n; public: Pair(int 有如下程序:#include<iostream>using namespace std;class Pair{int m, n;public:Pair(int j, int k):m(j), n(k){}int get(){return m;}int get()const{return m+n;)};int main() {Pair a(3, 5);const Pair b(3, 5);cout<<a. get()<<b. get();return 0;}运行时的输出结果是( )。A) 33B) 38C) 83D) 88A.B.C.D.

考题 有以下程序includevoid f(int *p,int *q);main(){ int m=1,n=2,*r=m;f(r, n 有以下程序 #include<stdio.h> void f(int *p,int *q); main() { int m=1,n=2,*r=m; f(r, n); printf("%d,%d",m,n); } void f(int*p,int*q) {p=p+1; *q=*q+1;) 程序运行后的输出结果是______。A.1,3B.2,3C.1,4D.1,2

考题 有以下程序includestdio.hint*f(int*p,int*q);main( ){int m=1,n=2,*r=m;r=f(r,stdio.hint*f(int*p,int*q);main( ){int m=1,n=2,*r=m;r=f(r,n);printf(”%d\n”,*r);}int-f(int*P,int*q)(return(*p*q)?p:q;)程序运行后的输出结果是______。

考题 有下列程序: #includestdi0.h voidf(int*P,int*q); voidmain( ) (intm=1,n=2,*r=&m; f(r,&n);printf("%d,%d",m,n); } voidf(int*P,int*q){p=p+1;*q=*q+1;} 程序运行后的输出结果是( )。A.1,3B.2,3C.1,4D.1,2

考题 若有如下程序: sub(int *t,int a[3][4]) { int m,n; for(m=0;m<3;m++) for(n=0;n<4;n++) { *t=a[m][n];t++;} } main() { int*t,s[3][4)={{1,2,3),{4,5,6),{7,8,9}}; t=(int*)malloc(50); sub(t,s); printf("%d,%d\n",t[4],t[7]); } 则程序运行后的输出结果是( )。A.4,7B.4,0C.5,8D.程序错误

考题 阅读以下说明和Java程序,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。 【说明】 以下Java代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分接口、类及其关系如图5-1所示。 【Java代码】 interface?DrawCircle?{? //绘制圆形 public(1) ;}class?RedCircle?implements?DrawCircle?{? ?//绘制红色圆形???????public?void?drawCircle(int?radius,intx,?int?y)??{????????????System.out.println("Drawing?Circle[red,radius:"?+?radius?+",x:"?+?x?+?",y:"?+y+?"]");???????}}class?GreenCircle?implements?DrawCircle?{????//绘制绿色圆形??????public?void?drawCircle(int?radius,?int?x,int?y)?{???????????System.out.println("Drawing?Circle[green,radius:"?+radius+",x:?"?+x+?",y:?"?+y+?"]");??????}}abstract?class?Shape?{????//形状? protected? ? (2)???;? ? public?Shape(DrawCircle?drawCircle)?{? ?this.drawCircle=?drawCircle;? ? ? public?abstract?void?draw();}class?Circle?extends?Shape?{? //圆形? ?private?int?x,y,radius;? public?Circle(int?x,int?y,intradius,DrawCircle?drawCircle)?{? ?(3)???;? this.x?=?x;? ? ? this.y?=?y;? ?this.radius?=radius;? }? ? ?public?void?draw()?{? ? drawCircle.? ?(4)? ?;? ? ? }}public?class?DrawCircleMain?{? public?static?void?main(String[]?args)?{? Shape?redCircle=new?Circle(?100,100,10,? (5) );//绘制红色圆形? Shape?greenCircle=new?Circle(200,200,10,(6) );//绘制绿色圆形? ?redCircle.draw(); greenCircle.draw();? ?}}

考题 阅读下列说明和C++代码,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。 【说明】 以下C++代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分类及其关系如图6-1所示。 【C++代码】 #include?#include?using?namespace?std;class?DrawCircle?{??????//绘制圆形,抽象类? ? ? public: (1);//定义参数为?int?radius,?int?x,?inty? ?virtual~DrawCircle()?{?}};class?RedCircle:public?DrawCircle?{????//绘制红色圆形? ? ? ? public: void?drawCircle(intradius,?int?x,?int?y)?{cout??drawCircle?=?drawCircle;? }? ?virtual~shape()?{?}? public:? ?virtual?void?draw()?=?0;};class?Circle:public?Shape?{????//圆形? ? private:? ? ?int?x,y,radius;? ? public:? Circle(int?x,inty,int?radius,DrawCircle?*drawCircle)? (3)? {? this->x?=?x;? ?this->y?=?y;? ? this->radius?=?radius; }? ? ? public:? void?draw(){? drawCircle?-> (4); }};int?main(){Shape?*redCirclenew?Circle(100,100,10,????(5)????);//绘制红色圆形? Shape?*greenCircle=new?Circle(100,100,10, (6)??);//绘制绿色圆形redCircle >draw();? ?greenCircle?->draw();? ?return?0;}

考题 00330038003000301585067361821下列程序段执行结果是___________。 x = 1 print(type(x)) x = 1.0 print(type(x)) x = '1.0' print(type(x)A.<class 'int'> <class 'float'> <class 'str'>B.<class 'float'> <class 'int'> <class 'str'>C.<class 'str'> <class 'float'> <class 'int'>D.<class 'str'> <class 'int'> <class 'float'>

考题 下列程序段执行结果是___________。 x = 1 print(type(x)) x = 1.0 print(type(x)) x = '1.0' print(type(x)A.<class 'int'> <class 'float'> <class 'str'>B.<class 'float'> <class 'int'> <class 'str'>C.<class 'str'> <class 'float'> <class 'int'>D.<class 'str'> <class 'int'> <class 'float'>