欢迎来到麦多课文档分享! | 帮助中心 海量文档,免费浏览,给你所需,享你所想!
麦多课文档分享
全部分类
  • 标准规范>
  • 教学课件>
  • 考试资料>
  • 办公文档>
  • 学术论文>
  • 行业资料>
  • 易语言源码>
  • ImageVerifierCode 换一换
    首页 麦多课文档分享 > 资源分类 > DOC文档下载
    分享到微信 分享到微博 分享到QQ空间

    【计算机类职业资格】二级C++-70及答案解析.doc

    • 资源ID:1324128       资源大小:48.50KB        全文页数:5页
    • 资源格式: DOC        下载积分:5000积分
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    二维码
    微信扫一扫登录
    下载资源需要5000积分(如需开发票,请勿充值!)
    邮箱/手机:
    温馨提示:
    如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如需开发票,请勿充值!如填写123,账号就是123,密码也是123。
    支付方式: 支付宝扫码支付    微信扫码支付   
    验证码:   换一换

    加入VIP,交流精品资源
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    【计算机类职业资格】二级C++-70及答案解析.doc

    1、二级 C+-70及答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文件夹 proj1下的工程 proj1,此工程中包含源程序文件main.cpp,其中有类 Book(“书”)和主函数 main的定义。程序中位于每个“/ERROR *found*”之后的一行语句行有错误,请加以改正。改正后程序的输出结果应该是: 书名:C+语言程序设计 总页数:299 已把“C+语言程序设计”翻到第 50页 已把“C+语言程序设计”翻到第 51页 已把书合上。 书是合上的。 已把“C+语言程序设计”翻到第 1页 注意:

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

    3、endl “书名:“title “总页数:“ num_pages; Book) delete title; / ERROR * found* bool isOpen () const return num_pages!=0; /书打开时返回 true,否则返回false int numOfPages()const return num_pages; /返回书的页数 int currentPage()const return cur_page; /返回打开页面的页码 void openAtPage(int page no) /把书翻到指定页 cout endl; if(page_no 1 |pa

    4、ge_no num_pages) cout “无法翻到第“ cur_page“页。“; close(); else cur_page = page_no; cout “已把“ title “”翻到第“ cur_page “页“; void openAtPrevPage) openAtPage (cur page-1); /把书翻到上一页 void openAtNextPage () openAtPage (cur_page +1); /把书翻到下一页 void close () /把书合上 cout endl; if(! isOpen () cout “书是合上的。“; else /ERROR

    5、 * found* num_pages =0; cout “已把书合上。“; cout endl; ; int main () Book book (“C+语言程序设计“, 299); book.openAtPage (50); book.openAtNextPage (); book.close (); book.close (); book.openAtNextPage (); return 0; (分数:30.00)_二、B简单应用题/B(总题数:1,分数:30.00)2.请使用 VC6或使用答题菜单打开考生文件夹 proj2下的工程 proj2。此工程中包含一个源程序文件main.cp

    6、p,其中有类 AutoMobile(“汽车”)及其派生类 Car(“小轿车”)、Truck(“卡车”)的定义,以及主函数 main的定义。请在横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为: 车牌号:冀 ABC1234 品牌:ForLand 类别:卡车 当前档位:0 最大载重量:12 车牌号:冀 ABC1234 品牌:ForLand 类别:卡车 当前档位:2 最大载重量:12 车牌号:沪 XYZ5678 品牌:QQ 类别:小轿车 当前档位:0 座位数:5 车牌号:沪 XYZ5678 品牌:QQ 类别:小轿车 当前档位:-1 座位数:5 注意:只在横线处填写适当的

    7、代码,不要改动程序中的其他内容,也不要删除或移动“/*found*”。 #include iostream #include iomanip #include cmath using namespace std; class AutoMobile /“汽车“类 char * brand; /汽车品牌 char * number; /车牌号 int speed; /档位:1、2、3、4、5,空档:0,倒档:-1 public: AutoMobile(const char * the_brand, const char * the_number): speed(0) /* found* _; st

    8、rcpy(brand, the_brand); number = new charstrlen (the_number) +1; /* found* _; AutoMobile () delete brand; delete number; const char * theBrand() const return brand; /返回品牌名称 const char * theNumber()const return number; /返回车牌号 int currentSpeed () const return speed; /返回当前档位 void changeGearTo (int the_

    9、speed) /换到指定档位 if (speed= -1 virtual const char * category () const =0; /类别:卡车、小轿车乖 virtual void show()const cout “车牌号:“ theNumber() “品牌:“theBrand() /* found* “类别:“ “当前档位:“ currentSpeed (); ; class Car: public AutoMobile /“小汽车“类 int seats; /座位数 public: Car (const char * the_brand, const char * the_n

    10、umber, int the_seats): AutoMobile(the_brand, the_number), seats(the_seats) int numberOfSeat () const return seats; /返回座位数 const char * category()const return “小轿车“; /返回汽车类别 void show () const AutoMobile:show (); cout “座位数:“ numberOfSeat () endl; ; class Truck: public AutoMobile /“卡车”类 int max load;

    11、/最大载重量 public: Truck (const char * the _brand, const char * the_number, int the_max_load): AutoMobile (the_brand, the_number), maxload (the_maxload) int maxLoad () const return max load; /返回最大载重量 const char * category()const return “卡车“; /返回汽车类别 void show () const /调用基类的 show()函数 /* found* _ cout “最

    12、大载重量:“ maxmoad () endl; ; int main () Truck truck (“ForLand“, “冀 ABC1234“, 12); truck.show (); truck.changeGearTo (2); truck.show (); Car car (“QQ“, “沪 XYZ5678“, 5); car.show (); car.changeGearTo (-1); car.show (); cout endl; return 0; (分数:30.00)_三、B综合应用题/B(总题数:1,分数:40.00)3.请使用 VC6或使用答题菜单打开考生文件夹 pro

    13、j3下的工程 prog3,其中声明的 MyString类是一个用于表示字符串的类。成员函数 endsWith的功能是判断此字符串是否以指定的后缀结束,其参数 s用于指定后缀字符串。如果参数 S表示的字符串是 MyString对象表示的字符串的后缀,则返回 true;否则返回 false。注意,如果参数 s是空字符串或等于 MyString对象表示的字符串,则结果为 true。 例如,字符串“cde”是字符串“abcde”的后缀,而字符串“bde”不是字符串“abcde”的后缀。请编写成员函数endsWith。在 main函数中给出了一组测试数据,此种情况下程序的输出应为: s1=abcde s

    14、2=cde s3=bde s4= s5=abcde s6=abcdef s1 endsWith s2:true s1 endsWith s3:false s1 endsWith s4:true s1 endsWith s5:true s1 endsWith s6:false 要求: 补充编制的内容写在“/*333*”与“/*666*”之间。不得修改程序的其他部分。 注意:程序最后将结果输出到文件out.dat中,输出函数 writeToFile已经编译为 obj文件,并且在本程序中调用。 /Mystring.h #include iostream #include string.h using

    15、 namespace std; class MyString public: MyString(const char* s) size = strlen(s); str = new charsize + 1; strcpy(str, s); MyString() delete str; bool endsWith(const char* s) const; private: char* str; int size; ; void writeToFile(const char * ); /main.cpp #include “MyString.h“ bool MyString:endsWith

    16、(const char* s) const /* 333* /* 666* int main () char s1 = “abcde“; char s2 = “cde“; char s3 = “bde“; char s4 = “ ; char s5 = “abcde“; char s6 = “abcdef“; MyString str (s1); cout “s1 = “ s1 endl “s2 = “ s2 endl “s3 = “ s3 endl “s4 = “ s4 endl “s5 = “ s5 endl “s6 = “ s6 endl; cout boolalpha “s1 ends

    17、With s2 :“ str.endsWith(s2) endl “s1 endsWith s3 :“ str.endsWith(s3) endl “s1 endsWith s4 :“ str.endsWith(s4) endl “s1 endsWith s5 :“ str.endsWith(sS) endl “s1 endsWith s6 :“ str.endsWith(s6) endl; writeToFile (“); return 0; (分数:40.00)_二级 C+-70答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使

    18、用 VC6或使用答题菜单打开考生文件夹 proj1下的工程 proj1,此工程中包含源程序文件main.cpp,其中有类 Book(“书”)和主函数 main的定义。程序中位于每个“/ERROR *found*”之后的一行语句行有错误,请加以改正。改正后程序的输出结果应该是: 书名:C+语言程序设计 总页数:299 已把“C+语言程序设计”翻到第 50页 已把“C+语言程序设计”翻到第 51页 已把书合上。 书是合上的。 已把“C+语言程序设计”翻到第 1页 注意:只修改每个“/ERROR *found*”下的一行,不要改动程序中的其他内容。 #include iostream using n

    19、amespace std; class Book char * title; int num_pages; /页数 int cur page; /当前打开页面的页码,0 表示书未打开 public: Boek(const char * theTitle, int pages):num pages(pages) /ERROR * found* title =new charstrlen(theTitle); strcpy(title, theTitle); cout endl “书名:“title “总页数:“ num_pages; Book) delete title; / ERROR * f

    20、ound* bool isOpen () const return num_pages!=0; /书打开时返回 true,否则返回false int numOfPages()const return num_pages; /返回书的页数 int currentPage()const return cur_page; /返回打开页面的页码 void openAtPage(int page no) /把书翻到指定页 cout endl; if(page_no 1 |page_no num_pages) cout “无法翻到第“ cur_page“页。“; close(); else cur_pag

    21、e = page_no; cout “已把“ title “”翻到第“ cur_page “页“; void openAtPrevPage) openAtPage (cur page-1); /把书翻到上一页 void openAtNextPage () openAtPage (cur_page +1); /把书翻到下一页 void close () /把书合上 cout endl; if(! isOpen () cout “书是合上的。“; else /ERROR * found* num_pages =0; cout “已把书合上。“; cout endl; ; int main () B

    22、ook book (“C+语言程序设计“, 299); book.openAtPage (50); book.openAtNextPage (); book.close (); book.close (); book.openAtNextPage (); return 0; (分数:30.00)_正确答案:(1)title=new charstrlen(theTitle)+1; (2)bool isOpen()constreturn cur_page !=0; (3)cur_page=0;)解析:考点 本题考查的是 Book类,其中涉及构造函数、析构函数、bool 函数和 const函数。 解

    23、析 (1)主要考查考生对动态分配的掌握情况,如果要复制字符串 theTitle,就要分配空间,空间大小应该为theTitle的长度加 1。 (2)主要考查考生对 bool函数的掌握情况,根据私有成员定义:int cur_page;/当前打开页面的页码,0 表示书未打开,可知应该返回 cur_page !=0;。 (3)主要考查考生对成员函数的掌握情况,根据私有成员定义:int cur_page;/当前打开页面的页码,0 表示书未打开,可知应给 cur_page赋值为 0。二、B简单应用题/B(总题数:1,分数:30.00)2.请使用 VC6或使用答题菜单打开考生文件夹 proj2下的工程 pr

    24、oj2。此工程中包含一个源程序文件main.cpp,其中有类 AutoMobile(“汽车”)及其派生类 Car(“小轿车”)、Truck(“卡车”)的定义,以及主函数 main的定义。请在横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为: 车牌号:冀 ABC1234 品牌:ForLand 类别:卡车 当前档位:0 最大载重量:12 车牌号:冀 ABC1234 品牌:ForLand 类别:卡车 当前档位:2 最大载重量:12 车牌号:沪 XYZ5678 品牌:QQ 类别:小轿车 当前档位:0 座位数:5 车牌号:沪 XYZ5678 品牌:QQ 类别:小轿车 当前档

    25、位:-1 座位数:5 注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/*found*”。 #include iostream #include iomanip #include cmath using namespace std; class AutoMobile /“汽车“类 char * brand; /汽车品牌 char * number; /车牌号 int speed; /档位:1、2、3、4、5,空档:0,倒档:-1 public: AutoMobile(const char * the_brand, const char * the_number):

    26、speed(0) /* found* _; strcpy(brand, the_brand); number = new charstrlen (the_number) +1; /* found* _; AutoMobile () delete brand; delete number; const char * theBrand() const return brand; /返回品牌名称 const char * theNumber()const return number; /返回车牌号 int currentSpeed () const return speed; /返回当前档位 voi

    27、d changeGearTo (int the_speed) /换到指定档位 if (speed= -1 virtual const char * category () const =0; /类别:卡车、小轿车乖 virtual void show()const cout “车牌号:“ theNumber() “品牌:“theBrand() /* found* “类别:“ “当前档位:“ currentSpeed (); ; class Car: public AutoMobile /“小汽车“类 int seats; /座位数 public: Car (const char * the_b

    28、rand, const char * the_number, int the_seats): AutoMobile(the_brand, the_number), seats(the_seats) int numberOfSeat () const return seats; /返回座位数 const char * category()const return “小轿车“; /返回汽车类别 void show () const AutoMobile:show (); cout “座位数:“ numberOfSeat () endl; ; class Truck: public AutoMobi

    29、le /“卡车”类 int max load; /最大载重量 public: Truck (const char * the _brand, const char * the_number, int the_max_load): AutoMobile (the_brand, the_number), maxload (the_maxload) int maxLoad () const return max load; /返回最大载重量 const char * category()const return “卡车“; /返回汽车类别 void show () const /调用基类的 show

    30、()函数 /* found* _ cout “最大载重量:“ maxmoad () endl; ; int main () Truck truck (“ForLand“, “冀 ABC1234“, 12); truck.show (); truck.changeGearTo (2); truck.show (); Car car (“QQ“, “沪 XYZ5678“, 5); car.show (); car.changeGearTo (-1); car.show (); cout endl; return 0; (分数:30.00)_正确答案:(1)brand=new charstrlen(

    31、the_brand)+1 (2)strcpy(number, the_number) (3)category() (4)AutoMobile:show();)解析:考点 本题考查的是 AutoMobile类及其派生类 Car类和 Truck类,其中涉及构造函数、const 函数、析构函数、纯虚函数和成员函数。 解析 (1)主要考查考生对动态分配的掌握情况,要复制字符串就要先给 brand分配空间。 (2)主要考查考生对 strcpy函数的掌握情况,该函数用于复制字符串。 (3)主要考查考生对成员函数的掌握情况,纯虚函数 category()返回汽车类型。 (4)主要考查考生对虚函数的掌握情况,

    32、调用基类的虚函数 show。三、B综合应用题/B(总题数:1,分数:40.00)3.请使用 VC6或使用答题菜单打开考生文件夹 proj3下的工程 prog3,其中声明的 MyString类是一个用于表示字符串的类。成员函数 endsWith的功能是判断此字符串是否以指定的后缀结束,其参数 s用于指定后缀字符串。如果参数 S表示的字符串是 MyString对象表示的字符串的后缀,则返回 true;否则返回 false。注意,如果参数 s是空字符串或等于 MyString对象表示的字符串,则结果为 true。 例如,字符串“cde”是字符串“abcde”的后缀,而字符串“bde”不是字符串“ab

    33、cde”的后缀。请编写成员函数endsWith。在 main函数中给出了一组测试数据,此种情况下程序的输出应为: s1=abcde s2=cde s3=bde s4= s5=abcde s6=abcdef s1 endsWith s2:true s1 endsWith s3:false s1 endsWith s4:true s1 endsWith s5:true s1 endsWith s6:false 要求: 补充编制的内容写在“/*333*”与“/*666*”之间。不得修改程序的其他部分。 注意:程序最后将结果输出到文件out.dat中,输出函数 writeToFile已经编译为 obj

    34、文件,并且在本程序中调用。 /Mystring.h #include iostream #include string.h using namespace std; class MyString public: MyString(const char* s) size = strlen(s); str = new charsize + 1; strcpy(str, s); MyString() delete str; bool endsWith(const char* s) const; private: char* str; int size; ; void writeToFile(cons

    35、t char * ); /main.cpp #include “MyString.h“ bool MyString:endsWith (const char* s) const /* 333* /* 666* int main () char s1 = “abcde“; char s2 = “cde“; char s3 = “bde“; char s4 = “ ; char s5 = “abcde“; char s6 = “abcdef“; MyString str (s1); cout “s1 = “ s1 endl “s2 = “ s2 endl “s3 = “ s3 endl “s4 =

    36、 “ s4 endl “s5 = “ s5 endl “s6 = “ s6 endl; cout boolalpha “s1 endsWith s2 :“ str.endsWith(s2) endl “s1 endsWith s3 :“ str.endsWith(s3) endl “s1 endsWith s4 :“ str.endsWith(s4) endl “s1 endsWith s5 :“ str.endsWith(sS) endl “s1 endsWith s6 :“ str.endsWith(s6) endl; writeToFile (“); return 0; (分数:40.0

    37、0)_正确答案:(int s_size=strlen(s); /把字符串 s的长度赋值给 s_size for(int i=0; is_size; i+) /i从 0到 s_size-1开始遍历 if(strsize-s_size+i !=si) /如果 strsize_s_size+i不等于 si return false; /返回 false return true; /否则返回 true)解析:考点 本题考查的是 MyString类,其中涉及构造函数、析构函数和 bool函数。 解析 主要考查考生对字符串的掌握情况,根据题目要求可知,函数用来判断此字符串是否以指定的后缀结束。判断过程是先求形参的长度,从形参的第一个字符开始判断字符串是否一致。该函数是 bool函数,最后要确定是返回 true还是 false。


    注意事项

    本文(【计算机类职业资格】二级C++-70及答案解析.doc)为本站会员(postpastor181)主动上传,麦多课文档分享仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文档分享(点击联系客服),我们立即给予删除!




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

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

    收起
    展开