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

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

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

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

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

    1、二级 C+-65及答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文件夹 proj1下的工程 proj1。此工程中包含程序文件main.cpp,其中有类 Door(“门”)和主函数 main的定义。程序中位于每个“/ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: 打开 503号门门是锁着的,打不开。 打开 503号门的锁锁开了。 打开 503号门门打开了。 打开 503号门门是开着的,无须再开门。 锁上 503号门先关门门锁上了。 注意:只修改每个“/ERR

    2、OR *found*”下的那一行,不要改动程序中的其他内容。 #include iostream using namespace std; class Door int num; /门号 boom closed; /true 表示门关着 bool locked; /true 表示门锁着 public: / ERROR * found* Door (int n): num(n), closed (true), lock (true) bool isClosed () const return closed; /门关着时返回 true,否则返回 false bool isOpened () con

    3、st return ! closed; /门开着时返回 true ,否则返回 false bool isLocked () const return locked; /门锁着时返回 true,否则返回 false boom isUnlocked () const return ! locked; /门未锁时返回 true,否则返回 false /ERROR * found* void open()const /开门 cout endl “打开“ num “号门.“; if(! closed) cout “门是开着的,无须再开门。“; else if (locked) cout “门是锁着的,打

    4、不开。“; else closed = false; cout “门打开了。“; void close () /关门 cout endl “关上“ num “号门.“; if (closed) cout “门是关着的,无须再关门。“; else closed=true; cout “门关上了。“; void lock() /锁门 cout endl “锁上“ num “号门.“; if (locked) cout “门是锁着的,无须再锁门。“; else / ERROR * found* if (closed) cout “先关门.“; closed = true; locked = true

    5、; cout “门锁上了。“; void unlock () /开锁 cour endl “打开“ num “号门的锁.“; if(! locked) else locked = false; cout “锁开了。“; ; int main () Door door (503); door.open (); door.unlock (); door.open (); door.open (); door.lock (); return 0; (分数:30.00)_二、B简单应用题/B(总题数:1,分数:30.00)2.请使用 VC6或使用答题菜单打开考生文件夹 proj2下的工程 proj2。

    6、此工程中包含一个源程序文件main.cpp,其中有日期类 Date、人员类 Person及排序函数 sortByAge和主函数 main的定义。请在横线处填写适当的代码并删除横线,以实现该程序。该程序的正确输出结果应为: 排序前: 张三 男 出生日期:1978 年 4月 20日 王五 女 出生日期:1965 年 8月 3日 杨六 女 出生日期:1965 年 9月 5日 李四 男 出生日期:1973 年 5月 30日 排序后: 张三 男 出生日期:1978 年 4月 20日 李四 男 出生日期:1973年 5月 30日 杨六 女 出生日期:1965 年 9月 5日 王五 女 出生 13期:196

    7、5 年 8月 3日 注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/*found*”。 #include iostream using namespace std; class Date /日期类 int year, month, day; /年、月、日 public: Date(int year, int month, int day): year (year), month (month), day (day) int getYear()const return year; int getMonth () const return month; int get

    8、Day()const return day; ; class Person /人员类 char name14; /姓名 bool is_male; /性别,为 true时表示男性 Date birth date; /出生日期 public: Person (char * name, bool is_male,Date birth_date):is_male (is male),birth_date (birth_date) /* found* strcpy (this - name, _); const char * getName () const return name; bool isM

    9、ale () const return is_male; Date getBirthdate () const returnbirth_date; int compareAge (const Person n = p. birth date. getYear () - birth_date.getYear ();if(n!=0) return n; /* found* _ if(n!=0) return n; return p.birth date.getDay ()- birth_date .getDay (); void show () cout endl; cout name “ /显示

    10、姓名 /* found* _/显示性别(“男”或“女”,双引号内不含空格) “出生日期:“ /显示出生日期 birth_date.getYear() “年“ birth date.getMonth() “月“ birth date.getDay() “日“; ; void sortByAge(Person ps, int size) for (int i = 0; i size -1; i+) /采用挑选排序算法 int m=i; for (int j =i+1; jsize; j+) if (psj. compareige (psm)0) m=j; if (mi) /* found* Per

    11、son p =_ psm =psi; psi =p; int main () Person staff = Person (“张三“, true, Date (1978, 4, 20), Person (“王五“, false, Date (1965, 8, 3), Person (“杨六“, false, Date (1965, 9, 5), Person (“李四“, true, Date (1973, 5, 30) ; const int size = sizeof (staff)/sizeof (staff0); int i; cout endl “排序前:“; for(i =0; i

    12、size; i+) staffi. show (); sortByAge (staff, size); cout endl endl “排序后:“; for(i=0; isize; i+) staffi. show (); cout endl; return 0; (分数:30.00)_三、B综合应用题/B(总题数:1,分数:40.00)3.请使用 VC6或使用答题菜单打开考生文件夹 proj3下的工程 proj3,其中包含了类 Integers和主函数 main的定义。一个 Integers对象就是一个整数的集合,其中包含 0个或多个可重复的整数。成员函数add的作用是将一个元素添加到集合中

    13、,成员函数 remove的作用是从集合中删除指定的元素(如果集合中存在该元素),成员函数 filter的作用是去除集合中的所有负整数。请编写这个 filter函数。此程序的正确输出结果应为: 5 28 2 -4 5 3 2 -75 27 66 31 5 28 2 -4 5 3 2 -75 27 66 31 6 5 28 2 -4 5 3 2 -75 27 66 31 6 -19 5 28 2 -4 5 3 -75 27 66 31 6 -19 5 28 2 -4 5 3 -75 27 66 31 6 -19 4 5 28 2 5 3 27 66 31 6 4 要求: 补充编制的内容写在“/*3

    14、33*”与“/*666*”之间,不得修改程序的其他部分。 注意:相关文件包括:main.cpp、Integers.h。 程序最后将调用 writeToFile函数,使用另一组不同的测试数据,将不同的运行结果输出到文件 out.dat中。输出函数 writeToFile已经编译为 obj文件。 /Integevs.h #ifndef INTEGERS #define INTEGERS #include iostream using namespace std; const intMAXELEMENTS =i00; /集合最多可拥有的元素个数 class Integers int elemMAXE

    15、LEMENTS; /用于存放集合元素的数组 int counter; /用于记录集合中元素个数的计数器 public: Integers(): counter(0) Integers(int data, int size); /利用数组提供的数据创建一个整数集合 void add(int element); void remove (int element); /删除集合中指定的元素 int getCount ()const return counter; /返回集合中元素的个数 int getElement(int i)const return elemi; /返回集合中指定的元素 void

    16、 filter(); /删除集合中的负整数 void show()const; ; void writeToFile(const char * path); #endif /main.cpp #include “Integers.h“ #include iomanip Integers:Integers (int data, int size): counter(0) for(int i=0; isize; i+) add (datai); void Integers:add (int element) if (counterMAXELEMENTS) elemcounter+ =element

    17、; void Integers:remove (int element int j; for(j =counter-1; j=0; j-) if (elemj =element) break; for(int i=j; icounter-1; i+ elemi =elemi+l; counter-; void Integers:filter () /* 333* /* 666* void Integers:show () const for(int i=0; igetCount (); i+ cout setw(4) getElement(i); coutendl; int main () i

    18、nt d=5, 28, 2, -4, 5, 3, 2, -75, 27, 66, 31; Integers s(d, 11); s.show(); s.add(6); s.show(); s.add(-19); s.show (); s.remove(2); s.show(); s.add(4); s.show(); s.filter(); s.show(); writeToFile (“); return 0; (分数:40.00)_二级 C+-65答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生

    19、文件夹 proj1下的工程 proj1。此工程中包含程序文件main.cpp,其中有类 Door(“门”)和主函数 main的定义。程序中位于每个“/ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: 打开 503号门门是锁着的,打不开。 打开 503号门的锁锁开了。 打开 503号门门打开了。 打开 503号门门是开着的,无须再开门。 锁上 503号门先关门门锁上了。 注意:只修改每个“/ERROR *found*”下的那一行,不要改动程序中的其他内容。 #include iostream using namespace std; class Door

    20、int num; /门号 boom closed; /true 表示门关着 bool locked; /true 表示门锁着 public: / ERROR * found* Door (int n): num(n), closed (true), lock (true) bool isClosed () const return closed; /门关着时返回 true,否则返回 false bool isOpened () const return ! closed; /门开着时返回 true ,否则返回 false bool isLocked () const return locked

    21、; /门锁着时返回 true,否则返回 false boom isUnlocked () const return ! locked; /门未锁时返回 true,否则返回 false /ERROR * found* void open()const /开门 cout endl “打开“ num “号门.“; if(! closed) cout “门是开着的,无须再开门。“; else if (locked) cout “门是锁着的,打不开。“; else closed = false; cout “门打开了。“; void close () /关门 cout endl “关上“ num “号门

    22、.“; if (closed) cout “门是关着的,无须再关门。“; else closed=true; cout “门关上了。“; void lock() /锁门 cout endl “锁上“ num “号门.“; if (locked) cout “门是锁着的,无须再锁门。“; else / ERROR * found* if (closed) cout “先关门.“; closed = true; locked = true; cout “门锁上了。“; void unlock () /开锁 cour endl “打开“ num “号门的锁.“; if(! locked) else

    23、locked = false; cout “锁开了。“; ; int main () Door door (503); door.open (); door.unlock (); door.open (); door.open (); door.lock (); return 0; (分数:30.00)_正确答案:(1)Door(int n):num(n), closed(true), locked(true) (2)void open()/开门 (3)if(!closed)解析:考点 本题考查 Door类,其中涉及 bool型私有成员、构造函数和成员函数。 解析 (1)主要考查考生对构造函数

    24、的掌握,使用成员列表初始化,注意私有成员是 locked,而不是 lock。 (2)主要考查考生对 const函数的掌握,函数体内有语句 closed=false,使成员值发生改变,因此不能使用 const。 (3)结合上下文即可得知当门不处于 closed状态时,输出:先关门。二、B简单应用题/B(总题数:1,分数:30.00)2.请使用 VC6或使用答题菜单打开考生文件夹 proj2下的工程 proj2。此工程中包含一个源程序文件main.cpp,其中有日期类 Date、人员类 Person及排序函数 sortByAge和主函数 main的定义。请在横线处填写适当的代码并删除横线,以实现该

    25、程序。该程序的正确输出结果应为: 排序前: 张三 男 出生日期:1978 年 4月 20日 王五 女 出生日期:1965 年 8月 3日 杨六 女 出生日期:1965 年 9月 5日 李四 男 出生日期:1973 年 5月 30日 排序后: 张三 男 出生日期:1978 年 4月 20日 李四 男 出生日期:1973年 5月 30日 杨六 女 出生日期:1965 年 9月 5日 王五 女 出生 13期:1965 年 8月 3日 注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/*found*”。 #include iostream using namespace s

    26、td; class Date /日期类 int year, month, day; /年、月、日 public: Date(int year, int month, int day): year (year), month (month), day (day) int getYear()const return year; int getMonth () const return month; int getDay()const return day; ; class Person /人员类 char name14; /姓名 bool is_male; /性别,为 true时表示男性 Date

    27、 birth date; /出生日期 public: Person (char * name, bool is_male,Date birth_date):is_male (is male),birth_date (birth_date) /* found* strcpy (this - name, _); const char * getName () const return name; bool isMale () const return is_male; Date getBirthdate () const returnbirth_date; int compareAge (cons

    28、t Person n = p. birth date. getYear () - birth_date.getYear ();if(n!=0) return n; /* found* _ if(n!=0) return n; return p.birth date.getDay ()- birth_date .getDay (); void show () cout endl; cout name “ /显示姓名 /* found* _/显示性别(“男”或“女”,双引号内不含空格) “出生日期:“ /显示出生日期 birth_date.getYear() “年“ birth date.getM

    29、onth() “月“ birth date.getDay() “日“; ; void sortByAge(Person ps, int size) for (int i = 0; i size -1; i+) /采用挑选排序算法 int m=i; for (int j =i+1; jsize; j+) if (psj. compareige (psm)0) m=j; if (mi) /* found* Person p =_ psm =psi; psi =p; int main () Person staff = Person (“张三“, true, Date (1978, 4, 20),

    30、Person (“王五“, false, Date (1965, 8, 3), Person (“杨六“, false, Date (1965, 9, 5), Person (“李四“, true, Date (1973, 5, 30) ; const int size = sizeof (staff)/sizeof (staff0); int i; cout endl “排序前:“; for(i =0; isize; i+) staffi. show (); sortByAge (staff, size); cout endl endl “排序后:“; for(i=0; isize; i+)

    31、 staffi. show (); cout endl; return 0; (分数:30.00)_正确答案:(1)name (2)n=p.birth_date.getMonth()-birth_date.getMonth(); (3)(is_male?“男“:“女“) (4)psm;)解析:考点 本题考查 Date类和 Person类,其中涉及构造函数、const 函数、bool 函数和成员函数。 解析 (1)主要考查考生对 strcpy()函数的掌握,strcpy()函数的功能是复制字符串,其格式为:sercpy(字符串 1,字符串 2);。 (2)主要考查考生对成员函数的掌握,函数功能是

    32、比较两个人的年龄,返回正数、0 或负数分别表示大于、等于和小于。前面语句比较了年份,因此这里应该比较月份。 (3)主要考查考生对成员函数的掌握,程序要求显示性别(“男”或“女”,双引号内不含空格),因此这里要进行判断,使用三日运算符?:完成语句。 (4)这里是一个变量交换操作,使用中间变量 p交换 psm和 psi的值。三、B综合应用题/B(总题数:1,分数:40.00)3.请使用 VC6或使用答题菜单打开考生文件夹 proj3下的工程 proj3,其中包含了类 Integers和主函数 main的定义。一个 Integers对象就是一个整数的集合,其中包含 0个或多个可重复的整数。成员函数a

    33、dd的作用是将一个元素添加到集合中,成员函数 remove的作用是从集合中删除指定的元素(如果集合中存在该元素),成员函数 filter的作用是去除集合中的所有负整数。请编写这个 filter函数。此程序的正确输出结果应为: 5 28 2 -4 5 3 2 -75 27 66 31 5 28 2 -4 5 3 2 -75 27 66 31 6 5 28 2 -4 5 3 2 -75 27 66 31 6 -19 5 28 2 -4 5 3 -75 27 66 31 6 -19 5 28 2 -4 5 3 -75 27 66 31 6 -19 4 5 28 2 5 3 27 66 31 6 4

    34、要求: 补充编制的内容写在“/*333*”与“/*666*”之间,不得修改程序的其他部分。 注意:相关文件包括:main.cpp、Integers.h。 程序最后将调用 writeToFile函数,使用另一组不同的测试数据,将不同的运行结果输出到文件 out.dat中。输出函数 writeToFile已经编译为 obj文件。 /Integevs.h #ifndef INTEGERS #define INTEGERS #include iostream using namespace std; const intMAXELEMENTS =i00; /集合最多可拥有的元素个数 class Inte

    35、gers int elemMAXELEMENTS; /用于存放集合元素的数组 int counter; /用于记录集合中元素个数的计数器 public: Integers(): counter(0) Integers(int data, int size); /利用数组提供的数据创建一个整数集合 void add(int element); void remove (int element); /删除集合中指定的元素 int getCount ()const return counter; /返回集合中元素的个数 int getElement(int i)const return elemi;

    36、 /返回集合中指定的元素 void filter(); /删除集合中的负整数 void show()const; ; void writeToFile(const char * path); #endif /main.cpp #include “Integers.h“ #include iomanip Integers:Integers (int data, int size): counter(0) for(int i=0; isize; i+) add (datai); void Integers:add (int element) if (counterMAXELEMENTS) elem

    37、counter+ =element; void Integers:remove (int element int j; for(j =counter-1; j=0; j-) if (elemj =element) break; for(int i=j; icounter-1; i+ elemi =elemi+l; counter-; void Integers:filter () /* 333* /* 666* void Integers:show () const for(int i=0; igetCount (); i+ cout setw(4) getElement(i); couten

    38、dl; int main () int d=5, 28, 2, -4, 5, 3, 2, -75, 27, 66, 31; Integers s(d, 11); s.show(); s.add(6); s.show(); s.add(-19); s.show (); s.remove(2); s.show(); s.add(4); s.show(); s.filter(); s.show(); writeToFile (“); return 0; (分数:40.00)_正确答案:(for (int i=counter-1; i=0; i-) /i 从 counter-1开始到 0遍历数组 elem if(elemi0) /如果 elemi小于零 for(int j =i; jcounter-1; j+) /j 从 i到 counter-2 遍历 elemj=elemj+1; /把 elemj+1赋值给 elemj counter-; /counter自减 )解析:考点 本题考查的是 Integers类,其中涉及数组、构造函数、成员函数和 const函数。 解析 主要考查考生对数组的掌握,函数要求去除集合中的所有负整数,程序使用循环语句遍历整数数组,使用条件语句判断当前整数是否为负数,如果是,则将该元素删除并使后面的所有元素前移一个位置。


    注意事项

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




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

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

    收起
    展开