A)该程序完全正确
B)该程序有错,只要将语句swap(&a,&b);中的参数改为a,b即可
C)该程序有错,只要将swap()函数中的形参p和q以及t均定义为指针(执行语句不变)即可
D)以上说法都不对
(21)关于友元的概念错误的是
A)友元函数没有this指针
B)调用友元函数时必须在它的实参中给出要访问的对象
C)一个类的成员函数也可以作为另一个类的友元函数
D)只能在类的公有段声明友元
(22)关于抽象类下面说法正确的是
A)抽象类就是其中有函数定义但没有实现的类
B)抽象类是可以被实例化的
C)派生类不能成为抽象类
D)抽象类的子类必须实现父类中的纯虚函数
(23)下面程序的结果是
#include
classtest{private:
intnum;
public:
test();
intgetint(){returnnum;}
~test();};
test:
:
test()
{num=0;}
test:
:
~test()
{cout<<"Destructorisactive"< voidmain()
{testx[3];
cout<<"Exitingmain"< A)Exitingmain
Destructorisactive
Destructorisactive
Destructorisactive
B)Exitingmain
Destructorisactive
Destructorisactive
C)Exitingmain
Destructorisactive
D)Exitingmain
(24)如果表达式--x+y中,--是作为成员函数重载的,+是作为成员函数重载的,则该表达式还可为
A)y.operator+(x.operator--(0))
B)y.operator+(x.operator--())
C)y.operator+(operator--(x,0))
D)operator+(x.operator--())
(25)下列语句不能够用于打开C根目录下文件test.txt的语句是
A)ifstreamfin;fin.open("C:
\\test.txt");
B)ifstreamfin("C:
\\test.txt");
C)A)和B)
D)ifstreamfin;fin("C:
\\test.txt");
(26)以下哪个基类中的成员函数表示纯虚函数?
A)virtualvoidvf(int)
B)voidvf(int)=0
C)virtualvoidvf(=0)
D)virtualvoidyf(int){}
(27)下面程序输出的结果是
#include
voidmain()
{inti;
inta[3][3]={1,2,3,4,5,6,7,8,9};
for(i=0;i<3;i++)
cout< A)159
B)753
C)357
D)591
(28)派生类继承基类的方式有
A)public
B)private
C)protected
D)以上都对
(29)下列程序的运行结果为
#include
classLocation{
protected:
intX,Y;
public:
voidSetX(intmyx){X=myx;}
voidSetY(intmyy){Y=myy;}
voidshowxy(){cout<<"X="<publicLocation{
private:
intH,W;
public:
voidSetH(intmyh){H=myh;}
voidSetW(intmyw){W=myw;}
voidshow(){cout<<"X="< voidmain()
{Rectangler1;
r1.SetX(3);
r1.SetY(5);
r1.SetH(4);
r1.SetW(6);
r1.showxy();
r1.show();}
A)X=3Y=5
X=3Y=5H=4W=6
B)X=3Y=5
X=3Y=5H=3W=6
C)X=3Y=5
X=3Y=4H=4W=6
D)X=3Y=5
X=3Y=3H=4W=6
(30)有以下程序
#include
voidss(char*s,chart)
{while(*s)
{if(*s==t)*s=t-′a′+′A′;
s++;}}
voidmain()
{charstr1[100]="abcddfefdbd",c=′d′;
ss(str1,c);cout< 程序运行后的输出结果是
A)ABCDDEFEDBD
B)abcDDfefDbD
C)abcAAfefAbA
D)Abcddfefdbd
(31)有以下程序
#include
voidmain()
{inta=5,b=0,c=0;
if(a=b+c)cout<<"