首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class Pair{ int m: int n: public: Pair(int i,intj):m(i),n(j){}
有如下程序: #include using namespace std; class Pair{ int m: int n: public: Pair(int i,intj):m(i),n(j){}
admin
2014-08-29
55
问题
有如下程序:
#include
using namespace std;
class Pair{
int m:
int n:
public:
Pair(int i,intj):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);
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;retum n>p_n;}
B、bool Pair::operator>(Pair P)
{if(m!=p.m)retum m>p.m;retum n>p.n;}
C、bool Pair::operator>(Pair p)const
{if(m>p.m)retum true;retum n>p-n;)
D、bool Pair::operator>(Pair P)
{if(m>p.m)retum true;return n>p.n;}
答案
A
解析
按照比较规则:首先比较两对象的m成员,m大者为大:当m相等时比较n,n大者为大。这条规则的用c++写出来就是选项A。
转载请注明原文地址:https://kaotiyun.com/show/DXNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
测试的目的是暴露错误,评价程序的可靠性;而发现错误的位置并改正错误的是【】。
有以下程序,其输出结果是()。#include<iostream>usingnamespacestd;intmain(){chara[10]={’1’,’2’,’3’,’4’,’5’,’6’,’7
下列字符常量的写法中,错误的是()。
下面程序的输出为【】。#include<iostream.h>voidmain(){inta[10],i,k=0;for(i=0,i<10;i++)a[i]=i;for(i=1;i<4;i++)k+=a[i]+i;cout<<
有如下程序#include<iostream>#include<iomanip>usingnamespacestd;intmain(){cout<<setprecision(3)<<fixed<<setfill(’*’)<<setw(8);co
有如下程序:#include<iostream>#include<iomanip>usingnamespacestd;intmain(){cout.fill(’*’);cout.width(6);cout.fill(’#’)
C++程序第1条语句是从【】函数开始执行的。
假定一个一维数组的定义为“chara[8],b;”若把该数组最后一个元素赋值给b应该采取的表达式为:【】。
重载一个运算符函数时,其参数表中没有任何参数,这说明该运算是______。
使用fstream流类定义流对象并打开磁盘文件时,文件的隐含打开方式为()。
随机试题
计算:20+19—18—17+16+15—14—13+12+11一…+4+3—2一1=()。
吩噻嗪类不具有的效应是:
女性,32岁。门诊就诊,2个月来干咳、胸闷憋气,心悸,呼吸困难,夜间发作明显,影响睡眠,既往有过敏性鼻炎,有类似发作病史。听诊双肺散在哮鸣音,心率110次/分。此患者因病情较重收入病房,经用大剂量氢化可的松、氨茶碱等药物滴注,症状未能缓解,痰黏稠难以咳
经第二肝门的横断层图像上,肝右静脉出肝后多开口于下腔静脉的
社会因素的作用中介系统是
石斛的功效是
对热轧带肋钢筋HRB335进行拉伸试验,钢筋规格型号为20mm×400mm。请回答下列问题。钢筋拉伸试验的一组试样数量应为()根。
Christeacheschildrentheguitar______.
A、 B、 C、 A
TipsonReadingI.Three【T1】phasesofreading【T1】______—beforereading—inthecourseofreading—afterreadingII.Pre-rea
最新回复
(
0
)