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

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

1、国家二级( C+)机试模拟试卷 107及答案与解析 一、选择题 1 在软件开发中,需求分析阶段可以使用的工具是 ( )。 ( A) N S图 ( B) DFD图 ( C) PAD图 ( D)程序流程图 2 有如下函数定义: void func(int a, int b+; 若执行代码段: int x = 0, y = 1; func(x, y); 则变量 x和 y的值分别是 ( )。 ( A) 0和 1 ( B) 1和 1 ( C) 0和 2 ( D) 1和 2 3 下列代码段中声明了 3个类: class Person ; class Student : public Person ; cl

2、ass Undergraduate : Student ; 下列关于这些类之间关系的描述中,错误的是 ( )。 ( A)类 Person是类 Undergraduate的基类 ( B)类 Undergraduate 从类 Student公有继承 ( C)类 Student是类 Person的派生类 ( D)类 Undergraduate是类 Person的派生类 4 数据库系统的三级模式不包括 ( )。 ( A)概念模式 ( B)内模式 ( C)外模式 ( D)数据模式 5 计算数列第 n 项的函数定义如下: int a(int n) if (n = 0) return 0; else if

3、(n = 1) return 1; else if (n = 2) return 2; else return a(n-1)+a(n-3); 若执行函数调用表达式 a(4),函数 a 被调用的次数是 ( A) 3 ( B) 4 ( C) 5 ( D) 6 6 有如下程序: #include #include using namespace std; class Instrument public: Instrument(string t=“乐器 “,string n=“无名 “):type(t),name(n) virtual string GetType() const return “乐器

4、 “; 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();

5、delete pi; return 0; 运行时的输出结果是 ( A)乐器 -星空 ( B)乐器 -无名 ( C)钢琴 -星空 ( D)钢琴 -无名 7 ( A)自然连接 ( B)交 ( C)投影 ( D)并 8 有如下程序: #include using namespace std; class XA int a; public: static int b; XA(int aa):a(aa) b+; XA() int get() return a; ; int XA:b=0; int main() XA d1(2),d2(3); coutvoidswap(Ta,Tb,intsize); (

6、B) templatevoidswap(intsize,Ta,Tb); ( C) templatevoidswap(T1a,T2b,intsize); ( D) templatevoidswap(T1a,T2b,intsize); 10 有如下程序: #include using namespace std; int main() int sum = 0; for(int i = 0; i double 由此可知 ( )。 ( A)这可能是一个函数模板的声明 ( B)这可能是一个类模板的声明 ( C)这既可能是一个函数模板的声明,也可能是一个类模板的声明 ( D)这肯定是一个错误的模板声明 2

7、3 下列关于 return语句的叙述中,正确的是 ( A)任何函数的函数体中至少有一个 return语句 ( B)任何函数的函数体中最后一条语句必须是 return语句 ( C)如果函数的返回类型为 void,则其函数体中可以没有 return语句 ( D)如果函数的返回类型为 int,则其函数体中可以没有 return语句 24 有如下程序: #include #include using namespace std; class MyBag public: MyBag(string br=“ABC“):brand(br) coutvoidswap(Ta,Tb,intsize); ( B)

8、templatevoidswap(intsize,Ta,Tb); ( C) templatevoidswap(T1a,T2b,intsize); ( D) templatevoidswap(T1a,T2b,intsize); 28 有如下程序段: int i=0; while(1) i+; if(i = 30) break; if(i/20 = 0) cout using namespace std; class Point public: Point(int xx=0,int yy=0):x(xx),y(yy) void SetX(int xx) x=xx; void SetY(int yy

9、) y=yy; private: int x,y; ; class Circle:Point public: Circle(int r):radius(r) int GetRadius() return radius; private: void SetRadius(int r) radius=r; int radius; ; int main() Circle c1(5); c1.SetX(1); / c1.SetY(2); / c1.SetRadius(10); / cout #include using namespace std; class MyBag public: friend

10、int NancyShow(MyBag 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; i usingnamespacestd; 宠物类别:狗、猫、鸟、鱼、爬行动物、昆虫、其他 enumPetTypeDOG, CAT, BIRD, FISH, REPTILE, INSECT, OTHER;

11、classPet宠物类 PetTypetype;类别 charname20;名字 public: Pet(PetTypetype, charname) this-type=type; 将参数 name中的字符串复制到作为数据 成员的 name数组中 ERROR*found* this-name=name; ERROR*found* PetTypegetType()constreturn PetType; constchar*getName()constreturnname; constchar*getTypeString()const switch(type) caseDOG: return“

12、adog“; caseCAT: return“acat“; caseBIRD: return“abird“; caseFISH: return“afish“; caseREPTILE: return“areptile“; caseINSECT: return“aninsect“; 返回 个字符串,以便产生要求的输出 ERROR*found* returnOTHER; voidshow()const cout usingnamespacestd; classMyString public: MyString(constchar*s) *found* mstr=newchar_; strcpy(m

13、_str,s); MyString() *found* _; ? voidreverse() intn: strlen(m_str); for(inti=0; i USingnamespacestd; classDataList数据表类 intlen; double*d; public: DataList(intlen, doubledata=NULL); DataList()deleted; intlength()constreturnfen; 数据表长度 (即数据元素的个数 ) doublegetElement(inti)constreturndi;, voidsort();数据表排序 v

14、oidshow()const;显示数据表 ; voidwriteToFile(char*, const DataList ); main cpp #include“DataList h“ DataList: DataList(intlen, double data): len(len) d: newdoublelen; for(inti=0; idouble 这里就可以看出这是一个函数模板的声明。 23 【正确答案】 C 【试题解析】 本题考查函数返回类型,函数如果返回为 void,那么函数体内可以没有 return语句,如果函数有返回值,那么在函数体中就必须有 return语句。 24 【正

15、确答案】 D 【试题解析】 本题考查构造函数的应用,题目中 A、 B、 C、 D,都定义了包含两个元素的一维数组, A、 B、 C都执行题目中的构造函数,并且输出 “ABCABC“,而 D选项中由于构造函数参数不为 ABC,所以输出为 “CityLifeMicky“ 25 【正确答案】 C 【试题解析】 根据软件设计原理提出如下优化准则: 划分模块时,尽量做到高内聚、低耦合,保持模块相对独立性,并以此原则优化初始的软件结构。 一个模块的作用范围应在其控制范围之内,且判定所在的模块应与受其影响的模块在层次上 尽量靠近。 软件结构的深度、宽度、扇入、扇出应适当。 模块的大小要适中。 C正确。 26

16、 【正确答案】 D 【试题解析】 本题考查如何引用类的数据成员,本题中要引用类的非静态数据成员,可以直接引用,所以 A选项正确。 27 【正确答案】 B 【试题解析】 本题中使用模板 swap(a,b,10)时,第一个和第二个参数为数组,第三个参数为整型变量,而 B 选项第一参数为整型变量与调用的时候不符合,所以B 选项错误。 28 【正确答案】 C 【试题解析】 程序首先定义一个整型变量 i并初始 化为 0, while循环条件为 1,所以循环结束时,必然执行 break 语句; while循环体中,首先对 i自增 1,接着判断 i=30时退出循环,最后判断 i/20=0(即, iname,

17、name); (2)PetType getType() const return type; (3)return “an unknown animal“; 【试题解析】 (1)主要考查字符串复制函数 strcpy(),其格式为 :strcpy(字符串 1,字符串 2)或 strcpy(指向字符串 1的指针 ,指向字符串 2的指针 ),功能是将字符串 2拷贝到字符串 1中 ,本题使用第二种格式。 (2)主要考查考生对成员函数的掌握 ,根据私有成员的定义类型 PetType type,可知要返回的是 type。 (3)主要考查考生对 switch 语句的掌握 ,当在 switch 语句体中找不到相

18、应的字段时 ,跳出 switch 语句 ,程序返回 “an unkown animal“。 三、简单应用题 42 【正确答案】 (1)strlen(s) + 1 (2)delete m_str (3)m_strn-i-1 (4)m_strn-i-1 = tmp 【试题解析】 (1)考查使用 new 语句动态分配内存空间 ,要分配空间大小应为字符串的长度加 1。 (2)主要考查考生对析构函数的掌握 ,析构函数使用 delete语句释放指针。 (3)和 (4)主要考查考生对成员函数的掌握 ,这里是一个变量交换操作 ,通过中间变量tmp 交换。 四、综合应用题 43 【正确答案】 for(inti=0; idj) di和 dj比较人,如果大于,就 di和 dj值交换 inttemp=di; 把临时整型变量 temp赋值为 di di=dj; 把 dj赋值给 di dj=temp;

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

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

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