首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: }}}}include using namespace std; class Pair{ int m; int n; public: Pair(int i,int J):m(i),n(J){} bool operator>(Pair P)co
有如下程序: }}}}include using namespace std; class Pair{ int m; int n; public: Pair(int i,int J):m(i),n(J){} bool operator>(Pair P)co
admin
2013-02-27
28
问题
有如下程序:
}}}}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 pl(3,4),p2(4,3),p3(4,5);
COUt<<(pl>p2)<<(p2>p1)<<(p2>p3)<<(p3>p2);
return 0;
{
运算符函数operator>功能是比较两个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 11>P.n;)
D、bool Pair::operator>(Pair P)
{if(m>P.m)return true;return 11>P.n;}
答案
A
解析
题目要求先比较m的大小。其次比较n的大小,首先看函数定义bool operator>(Pairp)corlst,从中可以看出B)和D)选项和函数定义不一致,缺少const,故排除;选项c只有一层比较不符合题意,故排除C)选项。因此,本题答案为A)。
转载请注明原文地址:https://kaotiyun.com/show/FoNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
请编写函数fun,其功能:编写函数fun(char*s0,char*s1,char*s2,char*s3),要求实现——将s0所指字符串分解成3个字符串,分别存入s1、s2、s3所指内存中。分解的方法是,s1、s2、s3从s0中依次按顺序每隔3个字
给定程序MODl1.C中函数char*fun(char*s1,char*s2,char*r)的功能:将两个长度相等的数字字符串当作两个加数,求其代表的数值之和并以字符串的形式存入r所指内存且返回。例如:s1是”723”,s2是”567”
有以下程序:#include<stdio.h>voidfun(intn,int*s){intf1,t2;if(n==1||n==2)*s=1;else
有以下程序:#include<stdio.h>main(){intk=2,m=4,n=6,*/pk=&k,*pm=&m,*p;*(p=&n)=*pk*(*pm);prin
有以下程序:#include<stdio.h>main(){intw=4,x=3,y=2,z=1;printf(”%d\n”,(w<x?w:z<y?z:x));}
请按下面注释的提示,将类B的构造函数定义补充完整。C1assA{inta;public:A(intaa=O){a=aa;}};classB:publicA{
在公有派生的情况下,派生类中定义的成员函数只能访问原基类的
带参数的流操纵算子【】与成员函数unsetf执行同样的功能。
随机试题
下列选项中属于鱼类原料特点的是________。
根据管路的作用,热工管路一般分为哪几种?
预防局麻药中毒的必要原则不包括
全体员工都应该认识到自己负有对自身和同事安全做出贡献的重要责任。员工对安全事务的()是落实这种责任的最佳途径。
根据《税收征收管理法》的规定,纳税人及其当事人认为税务机关的具体行政行为侵犯其合法权益的,()。
某科研单位工程师为某施工企业提供设计服务,双方商定,设计完成后由施工企业企业支付给工程师35000元劳务费,个人所得税由施工企业代付。不考虑其他税费的情况下,施工企业代付的个人所得税为()元。
阅读关于“人类面临的主要环境问题”的图文资料,按要求完成教学设计任务。材料一《普通高中地理课程标准(实验)》的内容标准要求:“根据有关资料,归纳人类所面临的主要环境问题。”材料二某版本教科书中关于“人类面临的主要环境问题”的部分内容。人类
国画家()以画虾而著称于世。
A、Theyhavedinnertogether.B、Thewomanhelpthemanlistentohistalk.C、Themanhelpthewomanlistentohertalk.D、Theygo
QuestionsontheOriginsofChristmas1.WhydowecelebrateonDecember25th?A)TheBiblemakesnomentionofJesusb
最新回复
(
0
)