【计算机类职业资格】二级C++-69及答案解析.doc
《【计算机类职业资格】二级C++-69及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级C++-69及答案解析.doc(4页珍藏版)》请在麦多课文档分享上搜索。
1、二级 C+-69及答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文件夹 proj1下的工程 proj1,此工程中包含源程序文件main.cpp,其中有 ElectricFan(“电风扇”)类和主函数 main的定义。程序中位于每个“/ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是: 品牌:清风牌,电源:关,风速:0 品牌:清风牌,电源:开,风速:3 品牌:清风牌,电源:关,风速:0 注意:只修改每个“/ERROR *found*”下的那一行,不要改动程序中
2、的其他内容。 #include iostream using namespace std; class ElectricFan /“电扇“类 char * brand; int intensity; /风速: 0-关机 1-弱, 2-中, 3-强 public: ElectricFan (const char * the_brand) : intensity(0) brand = new char strlen (the_brand) +1; strcpy(brand, the_brand); ElectricFan() delete brand; const char * theBrand
3、() const return brand; /返回电扇品牌 int theIntensity () const return intensity; /返回风速 / ERROR * found* bool isOn()const return intensity=0; /返回电源开关状态 / ERROR * found* void turnOff () const intensity =0; /关电扇 void setIntensity (int inten) /开电扇并设置风速 if(inten=1 void show () cout “品牌:“ theBrand () “牌“ “,电源:“
4、 (isOn () ? “开“: “关“) “,风速:“ theIntensity() endl; ; int main() ElectricFan fan(“清风“); fan.show(); fan.setIntensity(3); fan.show(); fan.turnOff(); fan.show(); return 0; (分数:30.00)_二、B简单应用题/B(总题数:1,分数:30.00)2.请使用 VC6或使用答题菜单打开考生文件夹 proj2下的工程 proj2。此工程中包含一个源程序文件main.cpp,其中有“书”类 Book及其派生出的“教材”类 TeachingM
5、aterial的定义,还有主函数 main的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义和函数定义。该程序的正确输出结果应为: 教材名:C+语言程序设计 页数:299 作者:张三 相关课程:面向对象的程序设计 注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/*found*”。 #include iostream using namespace std; class Book /“书“类 char * title; /书 int num_pages; /页数 char * writer; /作者姓名 public: /* found* Book(con
6、st char * the title, int pages, const char * the writer): _ title =new char strlen (the_titie) +1; strcpy(title,the_title); /* found* _ strcpy(writer,the_writer); Book() delete title; delete writer; int numOfPages()const return numpages; /返回书的页数 const char * theTitle () const return title; /返回书名 con
7、st char * theWriter () const return 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 char strlen (the_course) +i; strcpy (course, the_cou
8、rse); TeachingMaterial () delete course; const char * theCourse () const return course; /返回相关课程的名称 ; int main () TeachingMaterial abook (“C+语言程序设计“, 299, “张三“, “面向对象的程序设计“); cout “教材名:“ a book.theTitle() endl “页数:“ a_book.numOfPages () endl “作者:“ a book.theWriter () endl /* found* “相关课程:“ _; cout en
9、dl; return 0; (分数:30.00)_三、B综合应用题/B(总题数:1,分数:40.00)3.请使用 VC6或使用答题菜单打开考生文件夹 proj3下的工程 proj3,其中声明的 IntSet是一个用于表示正整数集合的类。IntSet 的成员函数 Merge的功能是求当前集合与另一个集合的并集,在 Merge中可以使用成员函数 IsMemberOf判断一个正整数是否在集合中。请完成成员函数 Merge。在 main函数中给出了一组测试数据,此时程序的输出应该是: 求并集前: 1 2 3 5 8 10 2 8 9 11 30 56 67 求并集后:1 2 3 5 8 10 2 8
10、9 11 30 56 67 1 2 3 5 8 10 9 11 30 56 67 要求: 补充编制的内容写在“/*333*”与“/*666*”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件 out.dat中。输出函数 writeToFile已经编译为 obj文件,并且在本程序中调用。/Intset.h #include iostream using namespace std; const int Max=100; class IntSet public: IntSet() /构造一个空集合 end = -1; IntSet(int a, int size) /构造一个包含数组
11、a中 size个元素的集合 if (size =Max) end=Max-1; else end =size-1; for(int i=0; i=end; i+) elementi=ai; bool IsMemberOf(int a) /判断 a是否为集合中的元素 for(int i=0; i=end; i+) if (elementi=a) return true; return false; int GetEnd() return end; /返回最后一个元素的下标 int GetElement(int i) return elementi; /返回下标 i处的元素 IntSet Merg
12、e(IntSet /求当前集合与集合 set的并集 void Print() /输出集合中的所有元素 for(int i=0; i=end; i+) if(i+1)% 20=0) cout elementi endl; else cout elementi ; cout endl; private: int elementMax; int end; ; void writeToFile(const char * ); /main.cpp #include “IntSet.h“ IntSet IntSet:Merge(IntSet /* 333* /* 666* return IntSet(a,
13、 size); int main () int a = 1, 2, 3, 5, 8, 10; int b =2, 8, 9, 11, 30, 56, 67; IntSet set1(a, 6), set2(b, 7), set3; cout “求并集前:“ endl; set1.Print(); set2.Print(); set3.Print(); set3 =set1.Merge(set2); cout endl “求并集后: “ endl; set1.Print(); set2.Print(); set3.Print(); writeToFile(“); return 0; (分数:40
14、.00)_二级 C+-69答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文件夹 proj1下的工程 proj1,此工程中包含源程序文件main.cpp,其中有 ElectricFan(“电风扇”)类和主函数 main的定义。程序中位于每个“/ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是: 品牌:清风牌,电源:关,风速:0 品牌:清风牌,电源:开,风速:3 品牌:清风牌,电源:关,风速:0 注意:只修改每个“/ERROR *found*”下的那一行,不要改
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 C69 答案 解析 DOC
