[计算机类试卷]国家二级(C++)机试模拟试卷74及答案与解析.doc

上传人:diecharacter305 文档编号:502526 上传时间:2018-11-29 格式:DOC 页数:31 大小:75.50KB
下载 相关 举报
[计算机类试卷]国家二级(C++)机试模拟试卷74及答案与解析.doc_第1页
第1页 / 共31页
[计算机类试卷]国家二级(C++)机试模拟试卷74及答案与解析.doc_第2页
第2页 / 共31页
[计算机类试卷]国家二级(C++)机试模拟试卷74及答案与解析.doc_第3页
第3页 / 共31页
[计算机类试卷]国家二级(C++)机试模拟试卷74及答案与解析.doc_第4页
第4页 / 共31页
[计算机类试卷]国家二级(C++)机试模拟试卷74及答案与解析.doc_第5页
第5页 / 共31页
点击查看更多>>
资源描述

1、国家二级( C+)机试模拟试卷 74及答案与解析 一、选择题 1 有如下程序: #include using namespace std; int main() void function(double val); double val; function(val); cout #include using namespace std; class Instrument public: Instrument(string t=“乐器 “,string n=“无名 “):type(t),name(n) virtual string GetType() const return “乐器 “; vi

2、rtual string GetName() const return “无名 “; protected: string type,name; ; class Piano:public Instrument public: Piano(string n,string t=“钢琴 “):Instrument(t,n) string GetType() const return “钢琴 “; string GetName() const return name; ; int main() Instrument *pi=new Piano(“星空 “); coutGetType()GetName()

3、; delete pi; return 0; 运行时的输出结果是 ( A)钢琴 -星空 ( B)钢琴 -无名 ( C)乐器 -星空 ( D)乐器 -无名 6 定义无符号整数类为 UInt,下面可以作为类 UInt实例化值的是 ( )。 ( A) 369 ( B) 369 ( C) 0.369 ( D)整数集合 1,2,3,4,5 7 下列关于运算符重载的叙述中,错误的是 ( A)可以通过运算符重载在 C+中创建新的运算符 ( B)赋值运算符只能重载为成员函数 ( C)运算符重载为类的成员函数时,第一操作数就是该类对象本身 ( D)重载类型转换运算符时不需要声明返回类型 8 有函数模板声明和一些

4、变量定义如下: template T1 sum(T2, T3); double d1,d2; 则下列调用中,错误的是 ( A) sum(d1,d2); ( B) sum(d1,d2); ( C) sum(d1,d2); ( D) sum(d1,d2); 9 若有定义语句 “doublea=2/3.0;“,则语句 cout using namesapce std; int return r; int main() int a=1,3,5,7; cout using namespace std; class Music public: void setTitle(char* str) strcpy

5、(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)程序编译时语句 和 都出错 22 已知枚举类型声明语句为: enum COLOR WHITE, YELLOW, GREEN=5, RED, B

6、LACK=10 ; 则下列说法中错误的是 ( )。 ( A)枚举常量 YELLOW的值为 1 ( B)枚举常量 RED的值为 6 ( C)枚举常量 BLACK的值为 10 ( D)枚 举常量 WHITE的值为 1 23 有如下类定义: 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) 24 软件按功能可以分为应用

7、软件、系统软件和支撑软件 (或工具软件 )。下面属于应用软件的是 ( )。 ( A)学生成绩管理系统 ( B) C语言编译程序 ( C) UNIX操作系统 ( D)数据库管理系统 25 下列函数原型声明中,错误的是 ( A) intfunction(int,int); ( B) intfunction(int=3,int=0); ( C) intfunction(intm=3,intn); ( D) intfunction(int 26 有如下程序: #include #include using namespace std; class Animal public: virtual stri

8、ng GetType() const return “Animal“; virtual string GetVoice() const return “Voice“; ; class Dog:public Animal public: string GetType() const return “Dog“; string GetVoice() const return “Woof“; ; class Cat:public Animal public: string GetType() const return “Cat“; string GetVoice() const return “Mia

9、ow“; ; void Type(Animal class Base private: void fun1() const cout using namespace std; class MyClass public: MyClass() +count; MyClass() -count; static int getCount() return count; private: static int count; ; int MyClass:count=0; int main() MyClass obj; cout usingnamespacestd; clasSXabc int*a; int

10、n; public: Xabc(intaa, intnn)构造函数 ERROR*found* nn=n; ERROR*found* a=new(n); for(inti=0; i usingnamespacestd; 集合类的操作接口 classCollection public: 向集合中添加一个元素 virtualvoidadd(inte)=0; 获取指定位置的元素 virtualintget(unsignedinti) cons1z=0; ; 实现了集合接口 classArray: publicCollection public: Array(unsignedints) *found*

11、a=new_; size=s; num=0; Array() *found* _; virtualvoidadd(inte) if(num usingnames1pacest=d; className protected: char*sLizrlaiile;姓 char*firstname;名 public: Name()deleteSLlrFlalne; delete firstname; ) virtualvoidshow()=0; ; className1: publicName public: Name1(constchar*name); *1*found* voidshow()_;

12、; className2: publicName public: Name2(constchar*name); voidshow() coutshow(); coutshow(); cout“必须作为成员函数,将这些运算符重载为非成员函数将在编译时标记为错误;选项 A中,运算符 “+“可以作为友元函数重载;选项 B、 C中的流运算符 “必须作为非成员函数重载;答案为 D。 33 【正确答案】 B 【试题解析】 本题 考查保护继承中派生类对基类的访问属性,受保护继承中,基类的公用成员和保护成员在派生类中成了保护成员,其私有成员仍为基类私有,保护基类的所有成员在派生类中都被保护起来,在类外不能访问

13、,所以 错误。 34 【正确答案】 A 【试题解析】 本题考查指针和引用。 为引用,使用正确; 中 (2)delete a; (3)anum (4)return ai; 【试题解析】 (1)主要考查考生对构造函数的掌握情况 ,要使用 new给动态数组分配空间。 (2)主要考查考生对析构函数的掌握情况 ,使用 delete 释放空间。 (3)主要考查考生对成员 函数的掌握情况 ,为数组添加元素 ,使用语句 :anum = e;。 (4)主要考查考生对成员函数的掌握情况 ,返回数组元素。 四、综合应用题 43 【正确答案】 (1)coutfirstname”surname (2)laeadi=starti (3)retumnewName2(s); elsereturnnewNamel(s) 【试题解析】 (1)主要考查考生对成员函数的掌握,题目要求按先名后姓的格式输出姓名,因此输出语句的顺序应该是先输出 firstname,然后再输出 sunlallle,注意它们之间还要输出 个空格。 (2)主要考查考生对字符串复制的掌握,题目要求把一个字符序列复制到 head 所指向的字符空间中,复制从 start所指向的字符开始,共复制 end start个字符。程

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试资料 > 职业资格

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1