(30)有如下程序:
#include
using namespace std;
class AA{
lilt k;
protected:
int n;
void setK(int k){ this->k=k;}
public:
void setN(int n){ this->n=n;}
};
class BB: public }{/*类体略*/};
int main(){
BB x_ ; //1
x .n=1; //2
x.setN (2); //3
x.k=3; //4
x .setK(4);
return 0;
}
在标注号码的四条语句中正确的是
A)1
B)2
C)3
D)4
(31)有如下类定义:
class XX{
int xx;
public:
XX():xx(0){cout<<' A';}
XX(int n):xx ( n){tout<<' B';}
};
Class YY:public XX{
Int yy;
public:
YY():yy ( 0){cout+yy;}
YY(int n):XX(n+1),yy(n){cout<
下列选项中,输出结果为A0的语句是
A)YY y1(0,0);
B)YY y2(1);
C)YY y3(0);
D)YY y4;
(32)有如下程序:
#include
Using namespace std;
class A{
public:
virtual void f(){cout+1;}
void g(){cout<<2;}
};
class B:public A{
public:
virtual void f(){cout<<3;}
void g(){ecut<<4;}
};
void show(A &a){a.f();a.g( );}
int main(){
B b;
show(b);
return 0;
}
运行时的输出结果是
A)12
B)34
C)14
D)32
(33)有如下程序:
#include
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;}
(34)假定下列语句都是程序运行后首次执行的输出语句,其中输出结果与另外三条语句不同的语句是 (35)有如下程序:
A)cout<
#include
using namespace std;
class ONE{
int c;
public:
ONE():c(0){cout<<1;}
ONE(int n):c (n){cout<<2;}
};
class TWO{
ONE onel;
ONE one2;
public:
TWO(int m):one2(m){cout<<3;}
};
int main()t
TWO t(4)
return 0
}
运行时的输出结果是
A)3
B)23
C)123
D)213
① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;
② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。