首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #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
99
问题
有如下程序:
#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全国计算机二级
相关试题推荐
设有两个串p和q,求q在p中首次出现位置的运算称作
下面程序的输出结果是【】。#include<iostream>usingnamespacestd;intx;voidfunA(int&,int);voidfunB(int,int&);int
有以下程序:#include<iostream.h>classA{intx;public:A(inta){x=a;}
有如下的程序:#include<cstring.h>#include<iostream.h>usingnamespacestd;classMyString{public:MyString
一个模块直接调用的其他模块的个数称为______。
对于类定义classA{public:virtualvoidfunc1(){}voidfunc2(){}};ClassB:publicA{pu
在单链表中,增加头结点的目的是
下列叙述中正确的是
下面各语句中,能正确进行赋字符串操作的语句是
开发软件所需高成本和产品的低质量之间有着尖锐的矛盾,这种现象称做()。
随机试题
《中华人民共和国义务教育法》规定,义务教育期间不收()。
对消化性溃疡有确诊价值的检查方法是()。
范某去肉食品市场买肉,卖肉的商贩用自制的杆秤为范某称肉,范某对商贩使用的秤表示不信任而拒绝接受称好的肉,因此与商贩发生争议。对此,下列说法错误的是:()
数字信号B=1时,如图7-59所示,两种基本门的输出为()。
()的功能是能够及时报告发生火灾的部位。
【2013上】简述幼儿教育与小学教育的区别。
民事责任的特点是()。
2020年,全国政协大会期间举行的大会发言,被称为“协商民主的讲坛”。中共十九届四中全会决定着重指出:坚持社会主义协商民主的独特优势,丰富有事好商量、众人的事情南众人商量的制度化实践。中国特色社会主义协商民主,作为“中国之治”的一个制度密码,是(
设则()
A、Theynevercamebackhomewithdesireddiamonds.B、Theylostthehard-earneddiamondsontheirwaybackC、Theyweresentenced
最新回复
(
0
)