首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostream> using namespace std; class Pair{ int m; int n; public: Pair(int i,intj):m(i
有如下程序: #include<iostream> using namespace std; class Pair{ int m; int n; public: Pair(int i,intj):m(i
admin
2020-11-11
15
问题
有如下程序:
#include<iostream>
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 p1(3,4),p2(4,3),p3(4,5);
cout<<(p1>p2)<<(p2>p1)<<(p2>p3)<<(p3>p2);
return 0;
}
运算符函数。perator>的功能是比较两个Pair对象的大小当左边对象大时,返回ture,否则返回false。比较规则是首先比较两对象的m成员,m大者为大:当m相等时比较n,n大者为大。程序输出0101,下列对运算符重载函数的正确定义是( )。
选项
A、bool Pair::operator>(Pair p)const
{if(mt=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)eonst
{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/ieyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
阅读以下程序:#inc1ude<iostream.h>voidmain(){staticinta[][2]={5,3,1,2};inti,j,s1=0;for(i=0;i<2;j++)
请使用VC6或使用【答题】菜单打开考生文件夹proi2下的工程proj2,其中定义了Employee类和Manager类。Employee用于表示某公司的雇员,其属性包括姓名(nfllIle)和工作部分(dept)。Nanager是Employee的公有派
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程prog3,其中声明了ValArray类,该类在内部维护一个动态分配的整型数组。ValArray类的复制构造函数应实现对象的深层复制。请编写VMArray类的复制构造函数。在main函数中给出了
下列叙述中正确的是()。
语句int*p=&k;定义了指针p,与这个语句等效的语句序列是()。
将前缀运算符“--”重载为非成员函数,下列原型中能正确用于类中说明的是()。
软件按功能可以分为:应用软件、系统软件和支撑软件(或工具软件)。下面属于应用软件的是()。
使用VC6打开考生文件夹下的源程序文件modi3.cpp。学校教务处要为任课老师开发一个学生管理系统,需求如下:(1)学生的信息是要受到严密保护和限制的,包括姓名、五个英文字符的学号,以及精确到小数点后一位的一科成绩,只有任课老师可以修改,如果学
在下列原型所示的C++函数中,按“传值”方式传递参数的是( )。
使用VC6打开考生文件夹下的源程序文件modi2.cpp。阅读下列函数说明和代码,实现函数sort(intA[].int.n),用选择排序法把数组从大到小排序。提示:选择排序法的思想是:(1)反复从还未排好的那部分线性表中选择出关键字最
随机试题
教育方针
简述决策树法的优缺点。
婴儿腹泻有明显的周围循环障碍者,扩容宜选用
检测和控制风险的方法有()。
下面()工作属于策划方承担。
下列关于“温室气体”的表述,错误的一项是()。根据原文,下列表述不属于二氧化碳对海洋及海洋生物影响的一项是()。
自行车:出行:环保
软件按功能可以分为:应用软件、系统软件和支撑软件(或工具软件)。下面属于应用软件的是( )。
【B1】【B11】
FoodInflationKeptHiddeninTinierBagsChipsaredisappearingfrombags,candyfromboxesandvegetablesfromcans.A
最新回复
(
0
)