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

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

1、国家二级( C+)机试模拟试卷 91及答案与解析 一、选择题 1 下列关于基类和派生类关系的叙述中,正确的是 ( )。 ( A)每个类最多只能有一个直接基类 ( B)派生类中的成员可以访问基类中的任何成员 ( C)基类的构造函数必须在派生类的构造函数体中调用 ( D)派生类除了继承基类的成员,还可以定义新的成员 2 下列叙述中正确的是 ( )。 ( A)栈是 “先进先出 “的线性表 ( B)队列是 “先进后出 “的线性表 ( C)循环队列是非线性结构 ( D)有序线性表既可以采用顺序存储结构,也可以采 用链式存储结构 3 执行下列语句段后,输出字符 “*“的个数是 ( )。 for(inti=

2、50;i1;i-=2)cout #include using namespace std; class MyBag public: friend 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 using namespace std; void f

3、un(int i) cout #include using namespace std; class Instrument public: Instrument(string t=“乐器 “,string n=“无名 “):type(t),name(n) virtual string GetType() const return “乐器 “; virtual string GetName() const return “无名 “; protected: string type,name; ; class Piano:public Instrument public: Piano(string

4、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)乐器 -星空 ( D)乐器 -无名 24 下列枚举类型的定义中,包含枚举值 3的是 ( A) enumtestLEFT,UP,RIG

5、HT,DOWN; ( B) enumtestLEFT,UP=5,RIGHT,DOWN; ( C) enumtestLEFT=-1,UP,RIGHT,DOWN; ( D) enumtestLEFT,UP,RIGHT=6,DOWN; 25 下列有关继承和派生的表述中,正确的是 ( A)作为虚基类的类不能被实例化 ( B)派生类不能访问基类的保护成员 ( C)派生类应当向基类的构造函数传递参数 ( D)虚函数必须在派生类中重新实现 26 一棵二叉树中共有 80个叶子结点与 70个度为 1的结点,则该二叉树中的总结点数为 ( A) 219 ( B) 229 ( C) 230 ( D) 231 27 若

6、要在 Viz类中将 *重载为一元运算符,下列重载函数声明中肯定有错的是 ( A) Vizoperator*(); ( B) Vizoperator*(Viz); ( C) intoperator*(Viz); ( D) Vizoperator*(Viz,Viz); 28 有如下程序: #include #include using namespace std; class Father public: Father(string s):name(s) cout using namespace std; class AA public: virtual void disp() cout #inc

7、lude using namespace std; class TV public: TV(int s=41):size(s) coutPrint(); delete room3; return 0; 运行时的输出结果是 ( A) NC54 ( B) NCN54D ( C) NNN54DDD ( D) NCN54DDD 38 下列叙述中,错误的是 ( A) false是一个逻辑型常量 ( B) 0是一个字符型常量 ( C) 1481是一个 int常量 ( D) 1.732是一个 double常量 39 有如下程序: #include #include using namespace std;

8、class MyBag public: MyBag(string br=“ABC“):brand(br) cout usingnamespacestd; classElectricFan “电扇 ”类 char*brand; intintensity; 风速: 0一关机 1一弱, 2一中, 3一强 public: ElectricFan(constchar*thebrand): intensity(0) brand=newcharstrlen(thebrand)+1; strcpy(brand, thebrand); ElectricFan()deletebrand; constchar。 t

9、heBrand()constreturnbrand; 返回电扇品牌 inttheIntensity()constreturn intensity; 返回风速 ERROR*found* boolisOn()constreturnintensity=0; 返回电源开关状态 ERROR*found* voidturnOff()constintensity= 0; 关电扇 voidsetIntensity(intinten) 开电扇并设置风速 if(inten=1 /返回电源开关状态 (2)void turnOff() intensity=0; /关电扇 (3)intensity = inten; 【

10、试题解析】 (1)主要考查考生对 bool函数的掌握情况 ,理清函数的逻辑关系。 (2)主要考查考生对成员函数的掌握 ,理清函数的逻辑关系。函数中有 intensity=0;参数值改变 ,因此函数不能为 const。 (3)主要考查考生对成员函数的掌握情况 ,intensity是类的私有成员。 三、简单应用题 42 【正确答案】 (1)item(val) (2)deletep (3)temp=top (4)temp-next=top 【试题解析】 (1)主要考查构造函数,对私有成员进行初始化,即 item(val)。 (2)主要考查使用 delete语句释放指针,一般格式为: delete+指

11、针。 (3)指向栈顶节点的是 top 指针,要使 temp 指向栈 顶节点,故使用语句temp=top;。 (4)指向栈顶节点的是 top 指针,要使新节点的 next指针指向栈顶数据,故使用语句 temp-next=top;。 四、综合应用题 43 【正确答案】 n = r.n; p = new intn; for (int index = 0; index n; index+) pindex = r.pindex; 【试题解析】 主要考查考生对拷贝构造函数的掌握 ,拷贝构造函数要复制动态数组 ,应先使用 new分配空间 ,然后使用循环语句逐个复制 ,注意这里不能使用 strcpy函数复制 ,因为 p 是整型动态数组。

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

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

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