ImageVerifierCode 换一换
格式:DOC , 页数:8 ,大小:40.50KB ,
资源ID:1324312      下载积分:5000 积分
快捷下载
登录下载
邮箱/手机:
温馨提示:
如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝扫码支付 微信扫码支付   
注意:如需开发票,请勿充值!
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【http://www.mydoc123.com/d-1324312.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

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

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

1、二级 C+机试-133 及答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:30.00)1.请使用“答题”菜单或使用 VC6 打开考生文件夹 proj1 下的工程 proj1。此工程定义了 Stop-Watch(秒表)类,用于表示时、分、秒信息,有构造函数 StopWatch()、设置时间函数 reset()、并且重载了前置和后置+运算符,用于实现增加秒的功能。程序中位于每个/ERROR*found*下的语句行有错误,请加以改正。改正后程序的输出应该是:00:00:0000:01:00注意:只能修改每个/ERROR*found*下的那一行,不要改动程序中的

2、其他内容。/源程序#includeiostream#includeiomanipusing namespace std;class StopWatch /“秒表”类int hours,minutes,seconds; /小时、分钟、秒public:StopWatch():hours(0),minutes (0),seconds(0)void reset()hours=minutes=seconds=0;StopWatch operator+(int) /后置+StopWatch old=*this;+(*this);return old;/前进 1 秒StopWatch operator+()

3、 /前置+/ERROR*found*if(seconds+=60)seconds=0;minutes+;if(minutes=60)minutes=0;hours+;/ERROR*found*return this:friend void show(StopWatch);;void show(StopWatch watch)coutsetfill(0);coutsetw(2)watch.hours:setw(2)watch.minutes:setw(2)watch.secondsendl;int main()StopWatch sw;show(sw);for (int i=0; i59; 1+

4、) sw+;/ERROR*found*show(sw+);return 0:(分数:30.00)_二、2简单应用题(总题数:1,分数:40.00)2.请使用“答题”菜单或使用 VC6 打开考生文件夹 proj2 下的工程 proj2。此工程定义了一个人员类Person,然后派生出学生类 Student 和教授类 Professor。请在程序中的画线处填写适当的代码,然后删除横线,以实现上述定义。此程序的正确输出结果应为:My name is Zhang.my name is Wang and my G.P.A.is 3.88My name is Li,I have 8 publications

5、注意:只能在画线处填写适当的代码,不要改动程序中的其他内容,也不能删除或移动“/*found*”。/源程序#include iostreamusing namespace std;class Personpublic:/*found*_name=NULL;Person(char*s) name=new charstrlen(s)+1;strcpy(name,s);Person() if(name!=NULL) deletename;/*found*_Disp() cout“My name is“name“./n“; /声明虚函数void setName(char*s) name=new cha

6、rstrlen(s)+1;strcpy(name,s); protected:char*name:;class Student: public Personpublic:/*found*Student(char*s,double g)_void Disp() cout“my name is“name“and my G.P.A.is ilgpa“./n“; private:float gpa;class Professor: public Personpublic:void setPubls(int n)publs=n;void Disp() cout“My name is“name“,I ha

7、ve“publs“publications./n“; private:int publs;int main()/*found*_;Person x(“Zhang“);p=x;p-Disp();Student y(“Wang“,3.88);p=y;p-Disp();Professor z:z.setName(“Li“);z.setPubls(8);p=z;p-Disp();return 0:(分数:40.00)_三、3综合应用题(总题数:1,分数:30.00)3.请使用“答题”菜单或使用 VC6 打开考生文件夹 proj3 下的工程 proj3,其中声明了 MyString 类。MyString

8、 是一个用于表示字符串的类。成员函数 startsWith 的功能是判断此字符串是否以指定的前缀开始,其参数 s 用于指定前缀字符串。如果参数 s 表示的字符串是 MyString 对象表示的字符串的前缀,则返回 true;否则返回 false。注意,如果参数 s 是空字符串或等于 MyString 对象表示的字符串,则结果为 true。例如:字符串“abc“是字符串“abcde“的前缀,而字符串“abd“不是字符串“abcde“的前缀。请编写成员函数startsWith。在 main 函数中给出了一组测试数据,此情况下程序的输出应该是:s1=abcdes2=abcs3=abds4=s5=ab

9、cdes6=abcdefs1 startsWith s2:trues1 startsWith s3 falses1 startsWith s4 trues1 startsWith s5 f trues1 startsWith s6 false要求:补充编制的内容写在/*333*与/*666*两行之间,不得修改程序的其他部分。注意:程序最后已经将结果输出到文件 out.dat 中。输出函数 writeToFile 已经编译为 obj 文件,并且在本程序中调用。/源程序#include“MyString.h“bool MyString:startsWith(const char*s)const/*

10、333*/*666*int main()char s1=“abcde“;char s2=“abc“;char s3=“abd“;char s4=“ “;char s5=“abcde“;char s6=“abcdef“;MyString str(s1);cout“s1=“s1endl“s2=“s2endl“s3=“s3endl“s4=“s4endl“s5=“s5endl“s6=“s6endl:coutboolalpha“s1 startsWith s2:“str.startsWith(s2)endl“s1 startsWith s3:“str.startsWith(s3)endl“s1 star

11、tsWith s4:“str.startsWith(s4)endl“s1 startsWith s5:“str.startsWith(s5)endl“s1 startsWith s6:“str.startsWith(s6)endl;/writeToFile(“K:/bl0/61000101/“);return 0:(分数:30.00)_二级 C+机试-133 答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:30.00)1.请使用“答题”菜单或使用 VC6 打开考生文件夹 proj1 下的工程 proj1。此工程定义了 Stop-Watch(秒表)类,用于

12、表示时、分、秒信息,有构造函数 StopWatch()、设置时间函数 reset()、并且重载了前置和后置+运算符,用于实现增加秒的功能。程序中位于每个/ERROR*found*下的语句行有错误,请加以改正。改正后程序的输出应该是:00:00:0000:01:00注意:只能修改每个/ERROR*found*下的那一行,不要改动程序中的其他内容。/源程序#includeiostream#includeiomanipusing namespace std;class StopWatch /“秒表”类int hours,minutes,seconds; /小时、分钟、秒public:StopWatc

13、h():hours(0),minutes (0),seconds(0)void reset()hours=minutes=seconds=0;StopWatch operator+(int) /后置+StopWatch old=*this;+(*this);return old;/前进 1 秒StopWatch operator+() /前置+/ERROR*found*if(seconds+=60)seconds=0;minutes+;if(minutes=60)minutes=0;hours+;/ERROR*found*return this:friend void show(StopWat

14、ch);;void show(StopWatch watch)coutsetfill(0);coutsetw(2)watch.hours:setw(2)watch.minutes:setw(2)watch.secondsendl;int main()StopWatch sw;show(sw);for (int i=0; i59; 1+) sw+;/ERROR*found*show(sw+);return 0:(分数:30.00)_正确答案:(1)if(+seconds=60)2)return*this;3)show(+sw);)解析:1)是在前置+运算符重载函数中,所以应该是+secnods

15、而不是 seconds+。2)函数类型是 StopWatch 对象,所以应该将本对象返回,而不是对象指针。为*this,而非 this。3)题目要求显示的是 00:01:00,调用 show(sw+)时显示的是 00:01:59,故知道该处应该改为调用前置重载运算符 show(+sw)。二、2简单应用题(总题数:1,分数:40.00)2.请使用“答题”菜单或使用 VC6 打开考生文件夹 proj2 下的工程 proj2。此工程定义了一个人员类Person,然后派生出学生类 Student 和教授类 Professor。请在程序中的画线处填写适当的代码,然后删除横线,以实现上述定义。此程序的正确

16、输出结果应为:My name is Zhang.my name is Wang and my G.P.A.is 3.88My name is Li,I have 8 publications注意:只能在画线处填写适当的代码,不要改动程序中的其他内容,也不能删除或移动“/*found*”。/源程序#include iostreamusing namespace std;class Personpublic:/*found*_name=NULL;Person(char*s) name=new charstrlen(s)+1;strcpy(name,s);Person() if(name!=NULL

17、) deletename;/*found*_Disp() cout“My name is“name“./n“; /声明虚函数void setName(char*s) name=new charstrlen(s)+1;strcpy(name,s); protected:char*name:;class Student: public Personpublic:/*found*Student(char*s,double g)_void Disp() cout“my name is“name“and my G.P.A.is ilgpa“./n“; private:float gpa;class Pr

18、ofessor: public Personpublic:void setPubls(int n)publs=n;void Disp() cout“My name is“name“,I have“publs“publications./n“; private:int publs;int main()/*found*_;Person x(“Zhang“);p=x;p-Disp();Student y(“Wang“,3.88);p=y;p-Disp();Professor z:z.setName(“Li“);z.setPubls(8);p=z;p-Disp();return 0:(分数:40.00

19、正确答案:(1)Person()name=NULL;2)virtual void Disp()cout“My name is“name“./n“;3)Student(char 术 s,double g):Person(s),gpa(g)4)Person *p;)解析:1)声明 Person 的无参构造函数。2)声明 Disp 为虚函数,而且 Disp 没有返回值,所以它的函数类型为 void。3)声明 Student 的构造函数,Student 继承了 Person 类,所以在派生类构造函数中一定要为基类的带参构造函数赋值,同时还要为派生类自己的数据成员初始化赋值。一般格式如下:派生类名(

20、参数总表):基类名(参数表),数据成员 1(初始值 1),4)由下面的程序,可知 p 在使用前要声明,故此此处是声明 p。三、3综合应用题(总题数:1,分数:30.00)3.请使用“答题”菜单或使用 VC6 打开考生文件夹 proj3 下的工程 proj3,其中声明了 MyString 类。MyString 是一个用于表示字符串的类。成员函数 startsWith 的功能是判断此字符串是否以指定的前缀开始,其参数 s 用于指定前缀字符串。如果参数 s 表示的字符串是 MyString 对象表示的字符串的前缀,则返回 true;否则返回 false。注意,如果参数 s 是空字符串或等于 MySt

21、ring 对象表示的字符串,则结果为 true。例如:字符串“abc“是字符串“abcde“的前缀,而字符串“abd“不是字符串“abcde“的前缀。请编写成员函数startsWith。在 main 函数中给出了一组测试数据,此情况下程序的输出应该是:s1=abcdes2=abcs3=abds4=s5=abcdes6=abcdefs1 startsWith s2:trues1 startsWith s3 falses1 startsWith s4 trues1 startsWith s5 f trues1 startsWith s6 false要求:补充编制的内容写在/*333*与/*666*

22、两行之间,不得修改程序的其他部分。注意:程序最后已经将结果输出到文件 out.dat 中。输出函数 writeToFile 已经编译为 obj 文件,并且在本程序中调用。/源程序#include“MyString.h“bool MyString:startsWith(const char*s)const/*333*/*666*int main()char s1=“abcde“;char s2=“abc“;char s3=“abd“;char s4=“ “;char s5=“abcde“;char s6=“abcdef“;MyString str(s1);cout“s1=“s1endl“s2=“

23、s2endl“s3=“s3endl“s4=“s4endl“s5=“s5endl“s6=“s6endl:coutboolalpha“s1 startsWith s2:“str.startsWith(s2)endl“s1 startsWith s3:“str.startsWith(s3)endl“s1 startsWith s4:“str.startsWith(s4)endl“s1 startsWith s5:“str.startsWith(s5)endl“s1 startsWith s6:“str.startsWith(s6)endl;/writeToFile(“K:/bl0/61000101/

24、);return 0:(分数:30.00)_正确答案:(/*333*if(s=NULL) return true,elsefor(int i=0;istrlen(s);i+)if(stri!=si)return false;return true:/*666*)解析:解析 首先判断传人的形参 s 是否为空字符串,如果是,则直接返回为 true,否则进行比较。按照 s 的字符长度进行比较。如果 strlen(s)size,显然为 false;如果 strlen(s)=size,则逐个位置元素比较。如果出现不相等,则直接返回 fasle;如果循环完毕仍然相等,则说明 s 被包含在 str 中,返回 true。

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