首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #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
79
问题
有如下程序:
#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)template<typenameT>Tabs(Tx){retllrnx<0?-x:X;}B)templateclass<T>Tabs(Tx){returnx<0?-x;x;}C)temp
在每个C++程序中必须有且仅有一个()。A)函数B)主函数C)预处理指令D)语句
有如下程序:#include<iostream>usingnamespacestd;classTestClass{staticinti;public:TestClass(){i++;
数据流图中带有箭头的线段表示的是()。
设p是指向一个类动态对象的指针变量,则执行“deletep;”语句时,将自动调用该类中的__________函数。
符合结构化原则的三种基本控制结构为:顺序结构,选择结构和【 】。
若Xcs是一个类,该类中具有一个函数体为空的不带参数的构造函数,此构造函数的类外定义为______。
软件测试的目的是()。
随机试题
GeorgeWashingtonCarverGeorgeWashingtonCarverwasborninMissouribetween1861and1864.Hewasbornintoslavery.Itwas
医院药事管理指出医疗机构是
雇主应在收到履约证书副本后()天内,将履约担保退还给承包商。
隧道工程、有高温、导电灰尘或灯具距地高度低于2.4m等场所,电源电压应不大于()。
某职工未经签约公司同意后突然跳槽到另一公司(该公司知此职工未与原单位解除劳动合同),给原先单位造成几万元的损失,根据我国劳动法的相关规定,原单位的损失应由( )。
选派项目经理阶段的成本计划是按照(),一般只确定责任总目标成本。
()属于证券经营机构的禁止行为。
商店出售某种商品,进价每件180元,按每件200元出售,可出售50件。为薄利多销每降低1元出售,销量就增加5件。问每件降价多少元出售盈利最多?()
ManyAmericansfindsilenceuncomfortableduringabuffetoraformaldinner.【C1】______intheStatesthereisthe【C2】______
WhatisrequiredinmanydifferentsituationsinAmericanculture?Anexpressionof______.
最新回复
(
0
)