[计算机类试卷]国家二级(C++)机试模拟试卷110及答案与解析.doc
《[计算机类试卷]国家二级(C++)机试模拟试卷110及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级(C++)机试模拟试卷110及答案与解析.doc(33页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级( C+)机试模拟试卷 110及答案与解析 一、选择题 1 有如下程序: int x=3; do x-=2; cout using namespace std; class TV public: TV(int s=41):size(s) TV(const TV ; TV fun(TV return t; int main() TV x,y; x=fun(y); return 0; 则 TV 类的复制构造函数被调用的次数是 ( A) 1次 ( B) 2次 ( C) 3次 ( D) 4次 9 对长度为 n的线性表作快速排序,在最坏情况下,比较次数为 ( A) n ( B) n-1 ( C)
2、 n(n-1) ( D) n(n-1)/2 10 关于赋值运算符 =的重载,下列表述中错误的是 ( A) =的重载函数必须且只能有一个参数 ( B)一个类即使没有重载 =,也可以用 =为该类的对象赋值 ( C)为了实现像 “x=y=z;“这样的连续赋值, =的重载函数的返回值必须声明为引用 ( D) =可以重载为一个类的友元函数 11 有如下程序: #include using namespace std; class Shape /图形类 public: /图形绘制函数(用显示字母模拟) virtual void draw()const coutdraw(); t.draw(); plot(
3、t); delete ps; return 0; 运行这个程序的输出是 ( A) SCC ( B) SCS ( C) CSS ( D) CCC 12 计算机软件包括 ( A)算法和数据 ( B)程序和数据 ( C)程序和文档 ( D)程序、数据及相关文档 13 有如下类定义: class MyClass public: MyClass(double d=0.0):val(d) _ /后缀自增运算符 +的声明 private: double val; ; 若要使语句序列 MyClass x(2.1),y; y=x+; 能够正常运行,横线处的语句应为 ( A) MyClass ( B) MyCla
4、ss ( C) MyClassoperator+(int); ( D) MyClassoperator+(); 14 有如下类定义: class Pet char name30; public: Pet(char * n) strcpy(name, n); void bark() coutbark() ( D) ( class AA public: virtual void disp() cout) 或 格式 2: if() else 关于上面的语法格式,下列表述中错误的是 ( )。 ( A) 部分可以是一个 if语句,例如 if(if(a=0) ( B) 部分可以是一个 if语句,例如 if
5、()if() ( C)如果在 前加上逻辑非运算符 !并交换 和 的位置,语句功能不变 ( D) 部分可以是一个循环语句,例如 if()while() 21 派生类的成员函数不能访问基类的 ( )。 ( A)公有成员和保护成员 ( B)公有成员 ( C)私有成员 ( D)保护成员 22 软件测试的目的是 ( )。 ( A)评估软件可靠性 ( B)发现并改正程序中的错误 ( C)改正程序中的错误 ( D)发现程序 中的错误 23 下列运算符函数中,肯定不属于类 Number的成员函数的是 ( A) Numberoperator+(Number); ( B) Numberoperator-(Numb
6、er); ( C) Numberoperator*(int); ( D) Numberoperator/(Number,Number); 24 有如下程序: #include #include using namespace std; class Instrument public: Instrument(string t=“乐器 “,string n=“无名 “):type(t),name(n) string GetType() const return “乐器 “; virtual string GetName() const return “无名 “; protected: string
7、 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(); delete pi; return 0; 运行时的输出结果是 ( A)乐器 -星空 ( B)乐器 -无名 ( C)钢
8、琴 -星空 ( D)钢琴 -无名 25 下列叙述中,错误的是 ( A) false是一个逻辑型常量 ( B) 0是一个字符型常量 ( C) 1481是一个 int常量 ( D) 1.732是一个 double常量 26 有如下两个类定义: class XX private: double x1; protected: double x2; public: double x3; ; class YY: protected XX private: double y1; protected: double y2; public: double y3; ; 在类 YY中保护成员变量的个数是 ( A)
9、1 ( B) 2 ( C) 3 ( D) 4 27 某二叉树共有 12个结点,其中叶子结点只有 1个。则该二叉树的深度为(根结点在第 1层) ( A) 3 ( B) 6 ( C) 8 ( D) 12 28 下面是重载为非成员函数的运算符函数原型,其中错误的是 ( A) MyClassoperator*(MyClass); ( B) MyClassoperator+(MyClass,int); ( C) MyClass ( D) MyClass 29 有如下程序: #include using namespace std; class CC int k; public: CC(int n):k(
10、n) int get()const return k; ; int main() CC c3=CC(1),CC(2); return 0; 此程序编译时未能通过,原因是 ( A)数组只能定义为基本数据类型 ( B)类 CC缺少复制构造函数 ( C)对象数组只能作为类的数据成员 ( D)类 CC缺少默认的构造函数 30 有如下程序: #include using namespace std; void fun(char c) cout #include using namespace std; class Appliance public: Appliance(string t=“A“):typ
11、e(t) cout usingnamespacestd; enumPetstypedog, cat, bird, fish; classPets private: char*name; Pets_typetype; public: Pets(constchar*name=“sonny“, Pets_typetype=dog); Pets&operator=(constPets&s); Pets(); voidshow()const; ; Pets: Pets(constchar*name, Pets typetype) 构造函数 this-name=newcharstrlen (name)+1
12、; strcpy(this-name, name); ERROR*found* type=type; Pets: Pets()析构函数,释放 name 所指向的字符串 ERROR*found* name= 0; Pets&Pets: operator=(constPets&s) if(&s=this)确保不要向自身赋值 return*this; deletename, name=newcharstrlen(s name)+1; ERROR*found* strcpy(this-name, name); type=s type; return*this; voidPets: show()cons
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 模拟 110 答案 解析 DOC
