首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class Pair{ int m; int n: public: Pair(int i,int j):m(i),
有如下程序: #include using namespace std; class Pair{ int m; int n: public: Pair(int i,int j):m(i),
admin
2020-04-07
31
问题
有如下程序:
#include
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 p1(3,4),p2(4,3),p3(4,5);
cout<<(p1>p2)<<(p2>p1)<<(p2>p3)<<(p3>p2);
return 0;
}
运算符函数。perator>的功能是比较两个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 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/0j8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列叙述中,不属于测试的特征的是
如果表达式y*x++中,“*”是作为成员函数重载的运算符,“++”是作为友元函数重载的运算符,采用运算符函数调用格式,该表达式还可表示为
在重载一个运算符为成员函数时,其参数表中没有任何参数,这说明该运算符是
已知枚举类型定义语句为:enunlToken{NAME,NUMBER,PLUS=5,MINUS,PRINT=10};则下列叙述中错误的是
按照标识符的要求,下列选项中,()符号不能组成标识符。
下面描述中,不属于软件危机表现的是
下列叙述正确的是()。
重载的关系运算符和逻辑运算符的返回类型应当是______。
下面叙述错误的是()。
随机试题
导致慢性肺源性心脏病最常见的病因是
A.硫糖铝B.氢氧化铝C.西咪替丁D.雷尼替丁E.奥美拉唑目前认为最强的胃酸分泌抑制剂是()。
对药品进行杂质检查应在什么步骤后进行
抑制细菌DNA促螺旋酶的药物抑制细菌依赖DNA的RNA聚合酶(DDRP)的药物
水泥混凝土路面实测混凝土强度大于设计强度的()后,可停止养护。
矩阵型监理组织形式的缺点是()。
企业将自有资产转换为以公允价值模式进行后续计量的投资性房地产时形成的其他综合收益,在投资性房地产处置时,要将其结转到“其他业务收入”科目中。()
你是税务机关的一名人员,一天有一紧急文件需要请示某部门领导,本单位的领导让你去一趟,而且说要马上办。可是你到该部门后,领导正在开会,你怎么办?
下列关于DVD光盘的叙述中,不正确的是( )。
在考生文件夹下,打开文档WORD1.DOCX,按照要求完成下列操作并以该文件名(WORD1.DOCX)保存文档。【文档开始】声明科学是中国发展的机遇新华网北京10月28日电在可预见的未来,信息技术和声明科学将是世界科技中最活跃的两个领域,两者在未来有
最新回复
(
0
)