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

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

1、国家二级 C+机试(操作题)模拟试卷 344及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 proj1,此工程中包含一个源程序文件 main cpp,其中有类 Book(“书 ”)和主函数 main的定义。程序中位于每个 “ ERROR*found*”下的语句行有错误,请加以改正。改正后程序的输出结果应该是: 书名: C+语句程序设计总页数: 299 已把 “C+语言程序设计 ”翻到第 50页 已把 “C+语言程序设计 ”翻到第 51页 已把 “C+语言程序设计 ”翻到第 52页 已把 “C+语言程序设计 ”翻到第 5l页 已把书合上。 当

2、前页: 0 注意:只修改每个 “ ERROR*found*”下的那一行,不要改动程序中的其他内容。 #include using namespace std; class Book char*title; int num_pages; /页数 int cur page;当前打开页面的页码, 0 表示书未打开 public: ERROR*found* Book(const char*theTitle, int pages)num_pages(pages) title=new charstrlen(theTitie)+1; strcpy(title, theTitle); coutnum_pa g

3、es) cout using namespace std; class Point , public: ERROR*found* Point(double X, double Y)_X(x), _y (Y) double GetX()constreturn X; ) double GetY()constreturn_y; ) ERROR*found* void Move (double xOff, double yOff)const x+=xOff; y+=yOff; ) protected: double x,y; ; int main() Point pt(1 5, 2 5); pt Mo

4、ve(2 5, 1 5); ERROR*found* 以下语句输出 pt成一 X和 _y的值 cout using namespace std; class Department “部门 ”类 public: Department (const char * name, const char*office) strcpy(this一 name, name); *found* const char*getName()constre- turn name; ) 返回部门名称 *found* const char*getOffice()const _ 返回办公室房号 void changeOffic

5、eT0(const char*office) 改换为指定房号的另一个办公室 strcpy(this一 office, office); private: char name20;部门名称 char office20;部门所在办公室房号 ; class Staff “职工 ”类 public: /*found* Staff(const char*my id, const char*my_name, Department 用于记录集合中元素个数的计数器 public: IntegerSet(): counter(0)( 创建一个空集合 IntegerSet(int data, int size);

6、 利用数组提供的数据创建一个整数集合 void add(int element); 添加一个元素到集合中 void remove(int element); 删除集合中指定的元素 int getCount()constreturn counter; ) 返回集合中元素的个数 int getElement(int i)constreturn elemi;)返回集合中指定的元素 void show()const; ; void WriteToFile(char*); #endif main cpp #include”IntegerSet h” #include IntegerSet: Intege

7、rSet(int data, int Size): counter(0) for(int i=0; i0;j一一 ) if(element=elemj1)break; 如果找到的是等于 element的元素,说明要添加的元素已经存在,直接返回 if(j0) if(element=elemj一 1)return; 如果找到的是小于 element的元素, j就是要添加的位置 该元素及其后面的元素依次后移,腾出插入位置 for(int k=counter; kj;k一一 ) elemk=elemk1; elemj=element; 将 element插入到该位置 counter+; 计数器加 1

8、void IntegerSet: remove(int ele。 ment) *333* *666* void IntegerSet: show()const for(int i=0; ioffice, office); (2)return office; (3)dept(my_dept) (4)dept changeOfliceTo(”311”); 【试题解析】 (1)主要考查考生对 strcpy函数的掌握情况,根据上一条语句:strcpy(this一 nallle, name);可知,这条语句复制的是 office,即 strcpy(this-office, office);。 (2)主要

9、考查考生对成员函数的掌握情况,根据语句的注释:返回办公室房号可知,要填写的是一条 return语句。在私有成员里: char office20;部门所在办公室房号,表明 office即为办公室房号。因此直接返回 offiee即可。 (3)主要考查考生对构造函数的掌握情况,根据函数体: stacpy(this-staff_id, my_id); strcpy(this一 name, my_name); 可知,只有 dept没有初始化,而空格前有字符 “: ”,这是成员列表初始化的标识符,因此填写 dept(my_dept)即可。 (4)主要考查考生对成员函数的调用的掌握情况,根据题目要求:人事处

10、办公室由521搬到 311。在 Department类中有函数 void changeOfficeTo(const char*office)可以修改办公室的房间号,直接调用即可。 三、综合应用题 4 【正确答案】 for(int i=0; icounter; 1+) 遍历整个集合 (数组 elem) if(element=elemij) 如果 element等于 elemi for(int j: i; jcounter一 1; 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