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

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

1、国家二级 C+机试(操作题)模拟试卷 128及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 projl下的工程 projl,此工程包含一个源程序文件 projl cpp。文件中将表示数组元素个数的常量 Size定义为 4,并用 int类型对类模板进行了实例化。文件中位于每个注释 “ERROR*found*”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: 1234 注意:模板参数名用 T。只修改注释 “ ERROR*found*”的下一行语句,不要改动程序中的其他内容。 projl cpp #include using namespace std;

2、 将数组元素个数 Size定义为 4 ERROR*found* const int Size; template class MyClass public: MyClass(T*P) for(int i=0; i ERROR*found* void MyClass: Print() for(int i=0; iobj(intArray); obj Print(); cout using namespace std; class Book “书 ”类 char*title; 书名 int num_pages;页数 char*writer; 作者姓名 public: Book(const char

3、*the title, int pages, const char*thewriter): numpages(pages) title=new charstrlen(the title)+1; strcpy(title, thetitle); *found* strcpy(writer, the_writer); ) *found* 一 Book()_ int numOfPages()constreturn num pages; ) 返回书的页数 const char*theTitle()constreturn title; 返国书名 const char*theWriter()constre

4、turn writer 返回作着名 ; class TeachingMaterial: public Book “教材 ”类 char*course; public: TeachingMaterial(const char*the title, int pages, const char*the writer, const char*the_course) *found* : _ course=new charstrlen(thecourse)+1 ; strcpy(course, the course); 一 TeachingMaterial()deletecourse; const cha

5、r*theCourse()constre turn course; ) 返回相关课程的名称 ; int main() TeachingMaterial a book(ttc+语言程序设计 ”, 299, “张三 ”,面向对象的程序设计 ); cout #include using namespace std; template 数制为 base的数 class Number int n; 存放数的当前值 public: Number(int i): n(i) i必须小于 base int advance(int k); 当前值增加 k个单位 int value()constreturn n;

6、返回 数的当前值 ; class TimeOfDay public: Numberhours; 小时 (02 3) Numberminutes; 分 (05 9) *1* *found* _;秒 (05 9) Numbermilliseconds; 毫秒 (0999) TimeOfDay(int h=0, int m=0, int S =0, int milli=0) : hours(h), minutes(m), seconds(S), milliseconds(milli) void advanceMilliS(int k)ad- VanceSeconds(milliseconds adv

7、ance (k); ) 前进 k毫秒 void advanceSeconds(int k) 前进 k秒 *2* * found* _;: void advanceMinutes(int k)advanceHour(minutes advance(k); 前进 k分钟 void advanceHour(int k)hours ad- vance(k); 前进 k小时 void show()const 按 “小时:分:秒毫秒 ”的格式显示时间 int C=cout fill(0); 将填充字符设置为 0 cout int Number: advance(int k) n+=k;增加 k个单位 in

8、t s=0; s用来累计进位 *3* * found* while(n=base) n到达或超过 base即进位 return S; 返回进位 int main() TimeOfDay time(1, 2, 3, 4); 初始时间: 1小时 2分 3秒 4毫秒 time show(); 显示时间 time advanceHour(5); 前进 5小时 time advanceSeconds(122); 前进 122秒 (2分零 2秒 ) time advanceMillis(1017); 前进 1017毫秒 (1秒 零 17毫秒 ) cout: Print() (3)MyClass0bj(in

9、tArray); 【试题解析】 主要考查的是模板类 MyClass,其中涉及构造函数、成员函数和const变量。 const变量必须进行初始化,因为 const确定了该变量 Size不能改变。模板类的成员在定义时要加上模板符号 “”,调用时也要注意添加相应的类型。 【解题思路】 (1)主要考查考生对 const变量的掌握,因为 eonst变量不能修改,所以在定义的同时必须初始化。 (2)主要考查考生对模板类的成员函数定义的掌握,因为 MyClass类是模板类,所以在定义该函数时要加上模板标识符 “”,即语句 void MyClass:Print()。 (3)主要考查考生对模板类构造函数的调用的

10、理解,从上一条语句 int intArraySize=l, 2, 3, 4;中可以知道 intArray为 int型,因此定义 0bj时要使用 ,即 MyClassobj(intArray);。 【解题宝典】 对于模板类,不论是其成员函数还是构造函数,调用时都要使用标识符 “”。 二、简单应用题 2 【正确答案】 (1)writer=new charstrlen(thewriter)+1; (2)deletetitle, writer; (3)Book(the_title, pages, thewriter) (4)a_book theCourse()seconds (2)advanceMin

11、utes(seconds advance(k) (3)s+; n一 =base; 【试题解析】 主要考查的是模板类 Number、构造函数、 const函数及TimeOfDay类。 【解题思路】 (1)主要考查考生对模板类的掌握,这里 是一个定义数据成员 seconds的语句,seconds用来表示 “秒 ”,可以根据小时、分、毫秒的定义形式填写,即Numberseconds。 (2)主要考查考生对成员函数的掌握,此处是函数 advanceSeconds中的一条语句,它使时间前进 k秒。将前后语句进行对比,可以知道应该填人语句advanceMinutes(seeonds advance(k)。 (3)考查 while循环语句,此处是函数 advance中的一条语句,它确定增加 k后 n的当前值和进位,并返回进位。变量 s表示累加进位,当 n到达或 超过 base即进位,进位时 s要自加 1,因此为 s+; n一: base。

展开阅读全文
相关资源
猜你喜欢
  • 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