[计算机类试卷]国家二级(C++)机试模拟试卷87及答案与解析.doc
《[计算机类试卷]国家二级(C++)机试模拟试卷87及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级(C++)机试模拟试卷87及答案与解析.doc(32页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级( C+)机试模拟试卷 87及答案与解析 一、选择题 1 一个栈的初始状态为空。现将元素 1、 2、 3、 4、 5、 A、 B、 C、 D、 E依次入栈,然后再依次出栈,则元素出栈的顺序是 ( )。 ( A) 12345ABCDE ( B) EDCBA54321 ( C) ABCDE12345 ( D) 54321EDCBA 2 下列符号中不属于 C+关键字的是 ( )。 ( A) friend ( B) namespace ( C) continue ( D) byte 3 有如下程序: #include using namespace std; class CD public:
2、CD() cout #include using namespace std; class MyBag public: MyBag(string br=“ABC“):brand(br) coutGetValue(); / sp-Task:GetValue(); / sp-Displayed:GetValue(); / sp-Draw(); / 在标注号码的语句行中,对类中成员访问存在二义性的是 ( A) ( B) ( C) ( D) 10 一个运动队有多个队员,一个队员仅属于一个运动队,一个队一般都有一个教练,则实 体运动队和队员的联系是 ( A)一对多 ( B)一对一 ( C)多对一 ( D
3、)多对多 11 有如下程序: #include using namespace std; void fun(int c=a; a=b; b=c; int main() int x,y; x=1; y=2; fun(x,y); cout using namespace std; int fun1(int x) return +x; int fun2(int int main() int a=0,b=0,c=0; c=fun1(a)+fun2(b); coutopen(“file.dat“); 16 下列字符中,可以出现在合法的 C+标识符中的是 ( A) : ( B) ( C) class AA
4、 public: virtual void disp() coutGetValue(); / sp-Task:GetValue(); / sp-Displayed:GetValue(); / sp-Draw(); / 在标注号码的语句行中,对类中成员访问存在二义性的是 ( A) ( B) ( C) ( D) 28 下列关于货币数据类型的叙述中,错误的是 ( A) DOUBLE ( B) abc ( C) _5_ ( D) xyz 29 在 C+中,编译系统自动为一个类生成默认构造函数的条件是 ( A)该类没有定义任何公有构造函数 ( B)该类没有定义任何无参构造函数 ( C)该类没有定义任何构
5、造函数 ( D)该类没有定义任何成员函数 30 某二叉树中有 15个度为 1的结点, 16个度为 2的结点,则该二叉树中总的结点数为 ( A) 32 ( B) 46 ( C) 48 ( D) 49 31 有如下类定义: class Base public: void fun() coutfun(); ( C) Base:fun(); ( D) fun(); 32 有如下类定义: class Base public: int a; protected: int b; private: int c; ; class Derived: public Base protected: int d; ;
6、若 obj是类 Derived的对象,以下 语句编译正确的是 ( A) obj.a; ( B) obj.b; ( C) obj.c; ( D) obj.d; 33 在函数中,可以用 auto、 extern、 register和 static这四个关键字中的一个来说明变量的存储类型,如果不说明存储类型,则默认的存储类型是 ( )。 ( A) auto ( B) extern ( C) register ( D) static 34 有如下程序: #include using namespace std; class Music public: void setTitle(char* str)
7、strcpy(title, str); protected: char type 10 ; private: char title 20 ; ; class Jazz : public Music public: void set(char* str) strcpy(type, “Jazz“); / strcpy(title, str); / ; 下列叙述中正确的是 ( )。 ( A)程序编译正确 ( B)程序编译时语句 出错 ( C)程序编译时语句 出错 ( D)程序编译时语句 和 都出错 35 已知枚举类型声明语句为: enum COLOR WHITE, YELLOW, GREEN=5,
8、RED, BLACK=10 ; 则下列说法中错误的是 ( )。 ( A)枚举常量 YELLOW的值为 1 ( B)枚举常量 RED的值为 6 ( C)枚举常量 BLACK的值为 10 ( D)枚举常量 WHITE的值为 1 36 有如下类定义: class Cup public: Cup(double val,string cr=“red“):price(val),color(cr) / Cup(); / private: string color; / double price=5.8; / ; 在标注号码的语句行中存在语法错误的是 ( A) ( B) ( C) ( D) 37 负责数据库中
9、查询操作的数据库语言是 ( )。 ( A)数据定义语言 ( B)数据管理语言 ( C)数据操纵语言 ( D)数据控制语言 38 如果派生类以 protected方式继承基类,则原基类的 protected成员和 public成 员在派生类中的访问属性分别是 ( A) public和 public ( B) public和 protected ( C) protected和 public ( D) protected和 protected 39 对长度为 n的线性表排序,在最坏情况下,比较次数不是 n(n 1)/2的排序方法是 ( )。 ( A)快速排序 ( B)冒泡排序 ( C)直接插入排序
10、( D)堆排序 40 有如下类声明和函数声明 class Base int m; public: int n; protected: int p; ; class Derived: public Base int k; friend void f(Derived d); ; 则在函数 f中通过 d可访问类数据成员的个数是 ( A) 1 ( B) 2 ( C) 3 ( D) 4 二、基本操作题 41 请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 proj1,其中有矩形类 Rectangle、 函数 show和主函数 main的定义。程序中位于每个 “ERROR*found*
11、”下一行的语句有错误,请力 11以改正。改正后程序的输出结果应该是: Upperleft=(1, 8), downright: (5, 2), areal=24 注意:只修改每个 “ ERROR*found*”下的那一行,不要改动程序中的其他内容。 #include #include usingnamespacestd; classRectangle doublex1ty1; 左上角坐标 doublex2, y2;右下角坐标 public: ERROR*found* Rectangle(doublex1, y1; double x2, y2) this-x1=x1; this-y1=y1; t
12、hiS-x2=x2; this-y2=y2; doublegetXl()constreturnx1; doublegetYl()constreturny1; doublegetX2()constreturnx2; doublegetY2()constreturny2; doublegetHeight()constreturn fabs(y1y2); doublegetWidth()constfreturn fabs(x1x2); doublearea()constreturngetHeight()*getWidth(); ; ERROR*found* voidshow(Rectangler)c
13、onst cout usingnamespacestd; classClass( “班级 ”类 public: Class(constchar*id, constchar* room) strcpy(classid, id); f*found* constchar*getClassID()constreturnclassid; 返回班号 *found* constchar*getClassroom()const _返回所在教室房号 voidchangeRoomTo(constchar*new room)改换到另一个指定房号的教室 strcpy(classroom, new_room); pri
14、vate: charclassid20;班号 charclassroom20;所在教室房号 ; classStudent “学生 ”类 charmyid10;学号 charmyname20;姓 名 Class&myclass;所在教室 public: *found* Student(constchar*theid, const char*the_name, Class&the_class): _; strcpy(my_id, the_id); strcpy(my_name, the_name); constchar*getID()constreturnmy_id; constchar*getN
15、ame()constreturnmy_name; ClassgetClass0constreturnmy_class; ; voidshowStudent(Student*stu) coutgetID()getName()getClass() getClassID()getClass() getClassroom() usingnamespacestd; classValArray int*v; intsize; public: ValArray(constint*p, intn): size(n) v=newintsize; for(inti=0; isize; i+) vi=Pi; Val
16、Array()deletev; boolequals(constValArray&other); voidprint(ostream&out)const out; for(inti: 0; isize一 1; i+) outvi“, “; outvsize1; ; voidwriteToFile(constchar*; main cpp #include“ValArray h“ boolValArray: equals(constValArray&other) *333* *666* intmain() constinta=1, 2, 3, 4, 5; constintb=1, 2, 3, 4
17、; constintC=1, 2, 3, 4, 6; constintd=1, 2, 3, 4, 5; ValArrayv1(a, 5); ValArrayv2(b, 4); ValArrayv3(C, 5); ValArrayv4(d, 5); cout“v1=“; v1 print(cout); coutend1; cout“v2=“; v2 print(cout); coutend1; cout“v3=“; v3 print(cout); coutend1; cout“v4=“; v4 print(cout); coutend1; cout“v1“(v1 equals(v2)? “i=“
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 模拟 87 答案 解析 DOC
