首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class Pair{ int m; int n; public: Pair(int i,intj):m(i),n
有如下程序: #include using namespace std; class Pair{ int m; int n; public: Pair(int i,intj):m(i),n
admin
2019-06-04
99
问题
有如下程序:
#include
using namespace std;
class Pair{
int m;
int n;
public:
Pair(int i,intj):m(i),n(j){}
bool operator>(Pajr p)const; ∥须在类体外给出定义
};
int main(){
Pair p1(3,4),p2(4,3),p3(4,5);
cout<<(p1>p2)<<(p2>p1)<
return 0;
}
运算符函数。perator>的功能是比较两个Pair对象的大小,当左边对象大时,返回true,否则返回false。比较规则是首先比较两对象的m成员,m大者为大:当m相等时比较n,n大者为大。程序输出0101,下列对运算符重载函数的正确定义是( )。
选项
A、bool Pair∷operator>(Pair p)const
{if(m!=p.In)return m>p.m;return n>p.n;}
B、bool Pair∷operator>(Pair.p)
{if(m!=p.m)retum m>p.m;return>p.n;}
C、bool Pair∷operator>(Pair p)const
{if(m>p.m)retum true;return n>p.n;}
D、bool Pair∷operator>(Pair p)
{if(m>p.m)return true;return n>p.n;}
答案
A
解析
按照比较规则:首先比较两对象的m成员,m大者为大:当m相等时比较n,n大者为大。这条规则的用C++写出来就是选项A。
转载请注明原文地址:https://kaotiyun.com/show/098p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
要定义数组A,使得其中每个元素的数据依次为3、9、4、8、0、0、0,错误的定义语句是A)intA[]={3,9,4,8,0,0,0};B)intA[7]={3,9,4,8,0,0,0};C)intA[]={3,9,4,8};D)
有如下程序:#include<iostream>usingnamespacestd;classTestClass{staticinti;public:TestClass(){i++;
下面的函数调用为:fun(x+y,3,min(n-1,y))则fun的实参个数是()。A)3B)4C)5D)6
在下面程序的横线处填上适当的语句,使程序执行后的输出结果为ABCD。#include<iostream>usingnamespacestd;classA{public:A(){cout<<’A’;}
有如下语句序列:intx=-10;while(++x){}运行时while循环体的执行次数为______。
在C++语言中,打开一个文件就是将这个文件与一个什么建立关联?
下列叙述中错误的是()。
关系模型的完整性规则是对关系的某种约束条件,包括实体完整性、___________和自定义完整性。
数据结构作为计算机的一门学科,主要研究数据的逻辑结构、对各种数据结构进行的运算,以及
随机试题
南北朝时期东魏政权制定的法典是()
房地产经纪人在人际交往和人际关系方面的素质中,()是房地产经纪人的隐形财富。
分别在四杯100cm3水中加入5g乙二酸、甘油、季戊四醇、蔗糖形成四种溶液,则这四种溶液的凝固点()。
承销费用一般根据股票发行规模和承销时间确定。()
特许经营对受方的要求是()。
公司信贷的借款人主要是经工商行政管理机关(或主管机关)核准登记的()。
下列选项中,体现思维的概括性的是()
求解下列微分方程:1491
汉字国标码(GB2312-80)把汉字分成()。
Tounderstandcultureshock,ithelpstounderstandwhatcultureis.Youmayknowthatgenesdetermineabigpartofhowyouloo
最新回复
(
0
)