下列程序的输出结果是________。 #include <iostream> using namespace std; int main() { int n[3], i, j, k; for(i=0; i<3; i++) n[i]="0;" k="2;" for(i="0;" i for(j="0;" j++) n[j]="n[i]+1;" return 0;>
第1题
A.33
B.38
C.83
D.88
第2题
#include<iostream>
using namespace std;
class Pair{
int m;
int n;
public:
Pair ( int i , int j ) : m ( i ) , n ( j ) {}
boot operator > ( pair p ) const; // 须在类体外给出定义
} ;
int main () {
Pair Al ( 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 n>p.n;}
D ) bool Pair:;operator> ( Pair p )
{if ( m>p.m ) return true; return n>p.n;}
第3题
}}}}include<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>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;}
第4题
A.33
B.38
C.83
D.88
第5题
A.33
B.38
C.83
D.88
第6题
#include<iostream>
usingnamespacestd;
classPair{
intm,n;
public;
Pair(intj,intk):m(j),n(k){}
intget(){returnm;}
intget()const{returnm+n;}
};
intmain(){
Paira(3,5);
constPairb(3,5);
cout<<a.get()<<b.get();
return0;
}
运行时的输出结果是( )。
A.33
B.38
C.83
D.88
第7题
A.375
B.357
C.0375
D.0557
第8题
#include<iostream>
usingnamespacestd;
classsample
{
private:
intn;
public:
sample(){}
sample(intm)
{
n=m:
}
sampleadd(samplesl,samples2)
{
this->n=s1.n+s2.n;
return(*this);
}
voiddisp()
{
cout<<"n="<<n<<endl;
}
};
intmain()
{
samples1(10),s2(5),s3;
s3.add(s1,s2);
s3.disp();
return0:
}
程序运行后,输出的结果是( )。
A.n=10
B.n=5
C.n=20
D.n=15
第9题
第10题
A.15
B.20
C.25
D.30
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!