【计算机类职业资格】二级C++机试-133及答案解析.doc
《【计算机类职业资格】二级C++机试-133及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级C++机试-133及答案解析.doc(8页珍藏版)》请在麦多课文档分享上搜索。
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
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 机试 133 答案 解析 DOC
