首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #inc1ude<iostream> using namespace std; class Pair{ int m, int n; public: Pair (int i,int j
有如下程序: #inc1ude<iostream> using namespace std; class Pair{ int m, int n; public: Pair (int i,int j
admin
2019-02-22
77
问题
有如下程序:
#inc1ude<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>p 1)<<(p2>p3)<<(p3>p2);
retum 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(mf=p.m)return m>p.m; retum 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/VMAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列虚基类的声明中正确的是()。
下列关于抽象类的叙述不正确的是
下述关于数据库系统的叙述中正确的是
已知类A中有公用数据成员B*b;其中B为类名。则下列语句错误的是
以下关于私有和保护成员的叙述中,不正确的是
有如下程序:#include<iostream>usingnamespacestd;classpoint{intx,y;public:point(intvx,intvy){x=vx;
下列函数的功能是______。#include<iostream.h>intFunc(inta,intb){if(a>B)return1;elseif(a==B)return0;
用树状结构表示实体之间联系的模型是
下面的符号中不属于C++关键字的是()
随机试题
请解释今天的管理者面临的道德事项和社会责任事项。
结合实际,谈谈行政组织理论研究的意义。
在Excel扣,输入公式或函数时,其前导字符必须是____________。
下列函数在区间(-∞,+∞)上单调减少的是________.
苏联教育家沙塔洛夫提出的教学方法是【】
药品包装应具备的功能有()
关于食品添加剂管制,下列哪一说法符合《食品安全法》的规定?(2011年试卷一第28题)
所有与非典患者接触的人都被隔离了。所有被隔离的人都与小李接触过。如果以上命题是真的,以下哪个命题也是真的?
依据(12),声卡可以分为8位、16位和32位等。
•ReadthearticlebelowaboutcreditcardinAmerica,andthequestionsontheoppositepage.•Foreachquestion13--18,mark
最新回复
(
0
)