有如下程序:
#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 get()const{return m+n;)
};
int main() {
Pair a(3, 5);
const Pair b(3, 5);
cout<<a. get()<<b. get();
return 0;
}
运行时的输出结果是( )。
A) 33
B) 38
C) 83
D) 88
A.
B.
C.
D.
第1题:
有如下程序: #include<iostream>#include<iosream> using namespace std; class BASE{ char c; public; BASE(char n):c(n){} virtual ~ BASE(){cout<<c;} }; class DERIVED; public BASE{ char c; public: DERIVED (char n): BASE (n+1)
A.XY
B.YX
C.X
D.Y
第2题:
有如下程序: #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
第3题:
第4题:
使用VC6打开考生文件夹下的工程test27_1,此工程包含一个源程序文件test27_1.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为;
100
源程序文件test27_1.cpp清单如下:
include <iostream.h>
template <class T>
class pair
{
T valuel, value2;
public:
pair (T first, T second)
{valuel=first; value2=second;}
/***************** found *****************/
char getmax ();
};
/***************** found *****************/
T pair<T>::getmax ()
{
T retval;
/***************** found *****************/
retval = valuel>value2?? value1 : value2;
return retval;
}
void main ()
{
pair <int> myobject (100, 75);
cout << myobject.getmax()<<end1;
}
第5题:
有如下程序: #include<iostream> using namespaee 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 pl(3,4),p2(4,3),p3(4,5); cout<<(pl>p2)<<(p2>p1)<<(p2>p3)<<(p3>p2); retum 0; } 运算符函数operator>的功能是比较两个Pair对象的大小,当左边对象大时,返回true,否则返回false。比较规则是首先比较两对象的m成员,m大者为大;当m相等时比较n,n大者为大。程序输出0101,下列对运算符重载函数的正确定义是
A.bool Pair::operator>(Pair P)eonst
B.bool Pair::operator>(Pair P) {if(m!=P.m)return m>p.In;return n>p.n;} {if(m!=P.m)return m>p.m;return n>p.n;}
C.bool Pair::operator>(Pair P)eonst
D.bool Pair::operator>(Pair P) {if(m>p.m)return true;return n>p.n;} {if(Ul>p.m)return true;return n>p.n;}