};
intmain(){
Deriveddl(’B’);
retum0;
}
执行这个程序的输出结果是( )。
A)B
B)BA
C)AB
D)BB
(34)有如下类定义:
classMyBase{
intk;
public:
MyBase(intn=O):
k(n)}}
intvalue()eonst{returnk;}
};
classMyDerived:
MyBase{
intj;
public:
MyDerived(inti):
j(i)}}
intgetK()const{returnk;}
intgetJ()const{returnj;}
};
编译时发现有一处语法错误,对这个错误最准确的描述是( )。
A)函数9etK试图访问基类的私有成员变量k
B)在类MyDerived的定义中,基类名MyBase前缺少关键字public、protected或private
C)类MyDerived缺少一个无参的构造函数
D)类MyDerived的构造函数没有对基类数据成员k进行初始化
(35)有如下程序:
#include
usingnamespacestd;
classInstrument{
public:
virtualvoidDisplay()=0;
};
classPian0:
publicInstrument}
public:
voidDisplay(){/*函数体略*/}
};
intmain(){
InstrumentS;
Instrument*P=0:
//…;
return0;
}
下列叙述中正确的是( )。
A)语句“Insturment*P=0;”编译时出错
B)语句“Instnunents;”编译时出错
C)类Pian0中的Display函数不是虚函数
D)类Instrument是一个虚基类
(36)有如下程序:
#include
usingnamespacestd;
classA{
public:
virtualvoidfancl(){cout<<”Al”;}
voidfunc2(){cout<<”A2”;}
};
classB:
publicA{
public:
voidfuncI(){tout<<”Bl”;}
voidfunc2(){tout<<”B2”;}
};
intmain()}
A*P=newB:
P—>funcl();
P—>func2();
deletep;
return0;
}
执行这个程序的输出结果是( )。
A)B182
B)A1A2
C)B1A2
D)AIB2
(37)关于在调用模板函数时模板实参的使用,下列表述中正确的是( )。
A)对于虚拟类型参数所对应的模板实参,如果能从模板函数的实参中获得相同的信息,则都可以省略
B)对于虚拟类型参数所对应的模板实参,如果它们是参数表中的最后的若干个参数,则都可以省略
C)对于虚拟类型参数所对应的模板实参,若能够省略则必须省略
D)对于常规参数所对应的模板实参,任何情况下都不能省略
(38)关于关键字class和typename,下列表述中正确的是( )。
A) 程序中的typename都可以替换为class
B)程序中的class都可以替换为typename
C)在模板形参表中只能用{ypename来声明参数的类型
D)在模板形参表中只能用class或typenanle来声明参数的类型
(39)在下列枚举符号中,用来表示“相对于当前位置”文件定位方式的是( )。
A)ios_base:
:
cur
B)ios—base:
:
beg
C)los_base:
:
0ut
D)ios—base:
:
end
(40)下列关于c++流的描述中,错误的是( )。
A)cout>>’A’表达式可输出字符A
B)eof()函数可以检测是否到达文件尾
C)对磁盘文件进行流操作时,必须包含头文件fstream
D)以ios_base:
:
0ut模式打开的文件不存在时,将自动建立一个新文件
二、基本操作题(共l8分)
请使用VC6或使用【答题】菜单打开考生文件夹projl下的工程projl,此工程中包含一个源程序文件
main.cpp,其中有类Book(“书”)和主函数main的定义。
程序中位于每个“//ERROR****found****”下
的语句行有错误,请加以改正。
改正后程序的输出结果应该是:
书名:
C++语句程序设计总页数:
299
已把“c++语言程序设计”翻到第50页
已把“c++语言程序设计”翻到第51页
已把“c++语言程序设计”翻到第52页
已把“c++语言程序设计”翻到第51页
已把书合上。
当前页:
0
注意:
只修改每个“//ERROR***found***”下的那一行,不要改动程序中的其他内容。
#include
usingnamespacestd;
classBook{
char*title;
intnum—pages;//页数
intcur_page;//当前打开页面的页码,0表示书未打开
public:
//ERROR***********found***********
Book(constchar*theTitle,intpages)num_pages(pages)
{
title=newchar[strlen(theTitle)+1];
strepy(title,theTitle);
cout<”<
<<”总页数:
”<}
~Book(){delete[]title;}
boolisClosed()const{returncur_page==0;}//书合上时返回true,否则返回false
boolisOpen()const{return!
isClosed();}//书打开时返回true,否则返回false
intnumOfPages()const{returnnum_pages;}//返回书的页数
intcurrentPage()const{returncur_page;}//返回打开页面的页码
//ERROR***********found***********
voidopenAtPage(intpage_no)const{//把书翻到指定页
cout<i“page_nohum_pages){
tOUt<<”无法翻到第”<”;
ClOSe();
}
else{
cur_page=page_n0;
tout<<”已把“"<}
}
voidopenAtPrevPage(){openAtPage(curpage—1);{//把书翻到上一页
voidopenAtNextPage(){openAtPage(cur_page+1);}//把书翻到下一页
voidclose(){//把书合上
tout<if(isClosed())
tout<<"书是合上的。
";
else{
//ERROR**********found**********
num_pages=0;
cout<<”已把书合上。
”;
}
cOut<}
};
intmain(){
Bookbook(”C++语言程序设计”,299);
book.openAtPage(50);
book.openAtNextPage();
book.openAtNextPage();
book.openA.tPrevPage();
book.close();
tout<<”当前页:
”<return0:
}
三、简单应用题(共24分)
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2。
此工程中包含一个源程序文件
main.cpp,其中有“房间”类Room及其派生出的“办公室”类0ffice的定义,还有主函数main的定义。
请在程
序中“//****found****”下的横线处填写适当的代码并删除横线,以实现上述类定义。
此程序的正确输出
结果应为:
办公室房间号:
308
办公室长度:
5.6
办公室宽度:
4.8
办公室面积:
26.88
办公室所属部门:
会计科
注意:
只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“///料料found••料”。
#include
usingnamespaeestd;
classRoom{//“房间”类
introom_n0;//房间号
doublelength;//房间长度(m)
doublewidth;//房间宽度(n1)
public:
Room(intthe—room—n0,doublethe~length,doublethe—width):
loom—no(the—room—no),length(the—
length),width(the—width){}
inttheRoomNo()eonst{returniDonl—n0;}
//返回房间号
doubletheLength()const{returnlength;}//返回房间长度
doubletheWidth()const{returnwidth;}//返回房间宽度
//**********found**********
doubletheArea()const{_______________}//返回房间面积(矩形面积)
};
classOffice:
publicRoom{//“办公室”类
char*depart;//所属部门
public:
Office(intthe_room_n0,doublethe_length,doublethe_width,eonstchar木the_depart)
//**********found**********
:
_______________{
depart=newchar[strlen(thedepart)+1];
//**********found**********
strcpy(_______________);
}
~Office(){delete[]depart;}
constchar*theDepartment()const{returndepart;}//返回所属部门
};
intmain(){
//**********found**********
Office_______________;
cout<<”办公室房间号:
”<<<”办公室长度:
”<<<”办公室宽度:
”<<<”办公室面积:
”<<<”办公室所属部门:
”<return0;
}
四、综合应用题(共18分J
请使用VC6或使用【答题】菜单打开考生文件夹pr