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

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

1、国家二级 C+机试(操作题)模拟试卷 464及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 proj1,此工程中含有一个源程序文件 proj1 cpp。其中位于每个注释 “ERROR*found*”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: NUM=0 Value=1 注意:只修改注释 “ ERROR *found*”的下一行语句,不要改动程序中的其他内容。 proj1 cpp #incclude using namespace std; class MyClass int i; friend VOid Increment

2、 (MyClass& f); public: const int NUN; ERROR*found* MyClass(int i=0)NUN=0; i=i; int GetValue()constreturn i; ; ERROR*found* void Increment()f i+; int main() NyClass obj; ERROR *found* NyClass: Increment(obj); cout using namespace std; const int MAXNUM=100; class Set private: int num; 元素个数 char setdat

3、aMAXNUM; 字符数组,用于存储集合元素 public: Set(char *s); 构造函数,用字符串 S构造一个集合对象 Bool InSet(char C); 判断一个字符 c是否在集合中,若在,返回 true,否则返回 false void Print()const; 输出集合中所有元素 ; Set: Set(char*s) num=0; while(*s) *found* if(_) TODO:添加代码,测试元素在集合中不存在 *found* _; TODO:添加一条语句,加入元素至集合中 s+; bool Set: InSet(char c) for(int i=0; i us

4、ing namespace std; const int MAXELEMENTS=100; 集合最多可拥有的元素个数 class IntegerSet int elemMAXELEMENTS; 用于存放集合元素的数组 int counter; 用于记录集合中元素个数的计数器 public: IntegerSet(): counter(0) 创建一个空集合 IntegerSet(int data, int size); 利用数组提供的数据创建一个整数集合 void add(int element); 添加一个元素到集合中 void remove(int element); 删除集合中指定的元素

5、int getCount()constreturn counter; 返回集合中元素的个数 int getElement(int i)const return elemi; 返回集合中指定的元素 void show()const; ; void WriteToFile(char*); #endif main cpp #include“IntegerSet h“ #include IntegerSet: IntegerSet(int data, int size): counter(0) for(int i=0; i0; j-) if(element=elemj-1) break; 如果找到的是

6、等于 element的元素,说明要添加的元素已经存在,直接返回 if(j0) if(element=elemj一 1) return; 如果找到的是小于 element的元素, j就是要添加的位置 该元素及 其后面的元素依次后移,腾出插入位置 for(int k=counter; kj; k-) elemk=elemk-1; elemj=element; 将 element插入到该位置 counter+; 计数器加 1 void IntegerSet: remove(int element) *333* *666* void IntegerSet: show()const for(int i=

7、0; igetCount(); i+) coutsetw(4)getElement(i); coutendl; int main() int d=5, 28, 2, 4, 5, 3, 2, 75, 27, 66, 31; IntegerSet s(d, 11); s show (); s add(6); s show(); s add(19); s show(); s remove(2); s show(); s add(4); s show(); WriteToFile(“); return 0; 国家二级 C+机试(操作题)模拟试卷 464答案与解析 一、基本操作题 1 【正确答案】 (1

8、)MyClass(int i=0): NUM(0) (2)void Increment(MyClass&f)f _i+; (3)Increment(obj); 【试题解析】 (1)主要考查考生对常量数据成员初始化方法的掌握,常量数据成员的初始化只能通过构造函 数的成员初始化列表进行,并且要使用关键字 const修饰。该题的前一条语句 const int NUM;,说明 NUM是常量数据成员。 (2)主要考查考生对友元函数的掌握,友元函数的定义与声明要一致,先看该友元函数的声明部分: friend void Increment(MyClass&f);,返回类型为 void,函数参数为 MyCla

9、ss&f;再比较出错的语句: void Increment()f _i+; ,错误在于该函数没有参数,应把 MyClass&f填在括号内。 (3)主要考查友元函数的调用 ,友元函数并不属于类,因此调用友元函数时不需要添加类名及作用域,只需要像调用普通函数一样即可。 二、简单应用题 2 【正确答案】 (1)!InSet(*s) (2)setdatanum+=*s (3)c=setdatai (4)return true 【试题解析】 (1)主要考查考生对成员函数的掌握,题目要求:添加代码,测试元素在集合中不存在,由类的定义可知函数 bool InSet(char c)可以测试字符 c是否在集合中

10、,因此这里直接调用函数 bool InSet(char c)即可 。 (2)题目要求:添加一条语句,加入元素至集合中,集合用数组 setdata表示,直接把元素添加到数组中即可。 (3)主要考查考生对 if语句的掌握,题目要求:测试元素 c是否与集合中某元素相同。前一条语句是个 for循环,利用下标 i遍历整个集合,通过 if语句中的判断条件判断 c是否在集合中,用 “=”判断。 (4)主要考查考生对成员函数的掌握,先看函数的注释:判断一个字符 c是否在集合中,若在,返回 true,否则返回 false。 if语句成立时,说明字符 c存在于集合中,因此应该返回 true c。 三、综合应用题

11、3 【正确答案】 for(int i=0; 1counter; 1+) 遍历整个集合 (数组 elem) if(element=elemi) 如果 element等于 elemi for(int j=i; jcounteri; j+)从 i开始集合 elem elemj=elemj+1; 把 elemj+1赋值给 elemj counter-; elem长度自减 1 return; 返回 【试题解析】 主要考查考生对有序数组的掌握,题目要求成员函数 remove从集合中删除指定的元素 (如果集合中存在该元素 )。遍历数组 elem中的元素,找出与形参 element相等的元素,并将其删除,每删除一个元素,即将该元素之后的每个元素前移一位,如果不存在与形参 element相等的元素则没有操作。使用下标 i遍历数组, if语句判断是否与 element相等。

展开阅读全文
相关资源
猜你喜欢
  • BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf
  • BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf
  • BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf
  • BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf
  • BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf
  • BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf
  • BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf
  • BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf
  • BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf
  • 相关搜索

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

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