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

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

1、国家二级( C+)机试模拟试卷 96及答案与解析 一、选择题 1 有如下类定义: class Test public: Test() a = 0; c = 0; / int f(int a) const this-a = a; / static int g() return a; / void h(int b) Test:b = b; ; / private: int a; static int b; const int c; ; int Test:b = 0; 在标注号码的行中,能被正确编译的是 ( )。 ( A) ( B) ( C) ( D) 2 软件按功能可以分为:应用软件、系统软件和支

2、撑软件 (或工具软件 )。下面属于应用软件的是 ( )。 ( A)编译程序 ( B)操作系统 ( C)教务管理系统 ( D)汇编程序 3 下列关于函数的描述中,错误的是 ( )。 ( A)函数可以没有返回值 ( B)函数可以没有参数 ( C)函数可以是一个类的 成员 ( D)函数不能被定义为模板 4 有如下类声明: class Base protected: int amount; public: Base(int n=0): amount(n) int getAmount()const return amount; ; class Derived: public Base protected

3、: int value; public: Derived(int m, int n):value(m), Base(n) int getData()const return value+amount; ; 已知 x是一个 Derived对象,则下列表达式中正确的是 ( )。 ( A) x.value+x.getAmount() ( B) x.getData()-x.getAmount() ( C) x.getData()-x.amount ( D) x.value+x.amount 5 下面描述中,不属于软件危机表现的是 ( )。 ( A)软件过程不规范 ( B)软件开发生产率低 ( C)软件

4、质量难以控制 ( D)软件成本不断提高 6 下列关于运算符重载的叙述中,错误的是 ( A)不能通过运算符重载在 C+中创建新的运算符 ( B)赋值运算符只能重载为成员函数 ( C)运算符函数重载为类的成员函数时,第一操作数是该类对象 ( D)重载类型转换运算符时,应声明返回类型为 void 7 有如下程序: #include #include using namespace std; class Appliance public: Appliance(string t=“A“):type(t) Appliance() coutTabs(Tx)returnxTabs(Tx)returnxabs(

5、Tx)returnx using namespace std; class AA public: AA() cout using namespace std; class Obj static int i; public: Obj() i+; Obj() i-; static int getVal() return i; ; int Obj:i=0; void f() Obj ob2; coutgetVal(); delete ob3; cout #include using namespace std; class MyBag public: friend int NancyShow(MyB

6、ag MyBag(string br=“ABC“):brand(br) private: string brand; ; int NancyShow(MyBag else return 0; int main() int count=0; MyBag arrays3=MyBag(“CityLife“),MyBag(“Coach“); for(int i=0; iTabs(Tx); ( B) templateclassTabs(Tx); ( C) templateTabs(Tx); ( D) templateTabs(Tx); 31 要定义整型数组 x,使之包括初值为 1的三个元素,下列语句正确

7、的是 ( A) staticintx3=1; ( B) intx3;x1=x2=x3=1; ( C) intx3=1,1,1; ( D) intx=1,1,1; 32 有如下类定义: class Base int m; public: int n; protected: int p; ; class Derived: private Base int k; public: void f(); ; 则允许成员函数 f访问的数据成员的个数是 ( A) 1 ( B) 2 ( C) 3 ( D) 4 33 在软件开发中,需求分析阶段可以使用的工具是 ( )。 ( A) N S图 ( B) DFD图 (

8、 C) PAD图 ( D)程序流程图 34 有如下程序: #include using namespace std; class A public: static int a; void init() a = 1; A(int a = 2) init(); a+; ; int A:a = 0; A obj; int main() cout using namespace std; class Appliance public: Appliance() cout #include usingnamespacestd; classBase ERROR*found* private: char*ms

9、g; public: Base(char*str) ERROR*found* msg=newcharstrlen(str); strcpy(msg, str); cout us ing rlame space std; class BaSe public: Base(int ml, int m2) meml=m1 ; mere2=m2; int sum()return metal+mere2; private: int meml, mere2;基类的数据成员 ; 派生类 Derived从基类 Base公有继承 * found* class Derived: _ public: 构造函数声明 D

10、erived(int m1, int m2, int m3); sum函数定义,要求返回 metal、 mere2和 mem3之和 *found* int SLIm()return_+mem3; private: int mere3; 派生类本身的数据成员 ; 构造函数的类外定义,要求由 m1和 m2分别初始化 mem1和 mem2,由 m3初始化 mem3 *found* _Derived(int m1, int m2, int m3): *found* _, mem3(m3) int main() Base a(4, 6); Derived b(1 0, 15, 2 0); int SLI

11、m=a sum()+b SLIm(); tout #include usingnamespacestd; classMyString public: MyString(constchar*s) str=newcharstrlen(s)+1; strcpy(str, s); MyString()deletestr; voidreverse(); friendostream (3)Base() delete msg; 【试题解析】 (1)主要考查保护成员 ,因为在 Base类的派生类中直接调用了 msg,所以这里应该是保护成员。 (2)主要考查考生对动态分配的掌握 ,由下一条语句 :strcpy(

12、msg,str)可知 ,程序要将字符串 str复制给 msg,因此要给 msg分配空间 ,空间大小应该为 str的长度加 1。 (3)主要考查考生对析构函数的掌握 ,delete语 句要加上标识符 。 三、简单应用题 42 【正确答案】 (1)publicBase (2)Base: sum() (3)Derived: (4)Base(m1, m2) 【试题解析】 (1)主要考查考生对公有继承的掌握情况,根据题目要求:派生类Derived从基类 Base公有继承,因此这里使用 pubfic来公有继承。 (2)主要考查考生对成员函数的掌握情况,根据题目对 sum函数的要求: sum函数定义,要求返

13、回 mem1、 mem2和 mem3 之和,因此这里直接调用基类的 sum函数,再加上 mem3 就满足题目要求。 (3)主要考查考生对构造函数的掌握情况,由于 Derived的构造函数在类外定义,因此要加上类名和作用域符,即 Derived:。 (4)主要考查考生对构造函数的掌握情况,因为 Derived是 Base类的派生类,所以其构造函数要使用成员列表初始化先给 Base初始化。 四、综合应用题 43 【正确答案】 Intlength=strlen(str); 把字符串 str的长度赋值给 lenth for(inti=0, j=length一 1; ij; i+, j-) 从 i=0,

14、 j=length一 1, ij为条件开始遍历,并把 stri和 strj交换 chartemp=stri; 给定义的临时变量 temp赋值为 stri stri=strj; 给 stri赋值 strj strj=temp; 给 strj赋值为 temp 【试题解析】 主要考查考生对动态数组的掌握,先看题目要求:成员函数reverse的功能是将字符串进行 “反转 ”。再由类的定义可知,字符串存放在动态数组 str中,由 strlen 函数得出字符串的长度,最后一个字符的下标为 length 一 1,第一个字符的下标为 0,将这两个字符交换,然后 j依次减 1同时 i依次加 1,继续交换,直到 i大于 j时停止循环即可。

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

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

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