( 33 )有如下程序:
#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;}
第1题:
有如下程序: #include<iostream> usingnamespacestd; classPair{ intm,n; public; Pair(intj,intk):m(j),n(k){} intget( ){returnIn;} intget( )const{returnm+n;} }; intmain( ){ Paira(3,5); constPairb(3,5); cout<<a.get( )t<<b.get( ); return0; } 运行时的输出结果是( )。
A.33
B.38
C.83
D.88
第2题:
第3题:
00330038003000301585067361821下列程序段执行结果是___________。 x = 1 print(type(x)) x = 1.0 print(type(x)) x = '1.0' print(type(x)
A.<class 'int'> <class 'float'> <class 'str'>
B.<class 'float'> <class 'int'> <class 'str'>
C.<class 'str'> <class 'float'> <class 'int'>
D.<class 'str'> <class 'int'> <class 'float'>
第4题:
有如下程序: #include<iostream> using namespace std; class Pair{ int m,n; public: Pair(int j,int k):m(j),n(k){} int get{return m;} int getconst{return m+n;} }; int main{ Pair a(3,5); const Pair b(3,5); tout<<a.get’<<b.get; return U: } 执行这个程序的输出结果是( )。
A.33
B.38
C.83
D.88
第5题:
第6题:
下列程序段执行结果是___________。 x = 1 print(type(x)) x = 1.0 print(type(x)) x = '1.0' print(type(x)
A.<class 'int'> <class 'float'> <class 'str'>
B.<class 'float'> <class 'int'> <class 'str'>
C.<class 'str'> <class 'float'> <class 'int'>
D.<class 'str'> <class 'int'> <class 'float'>