【计算机类职业资格】二级C++-64及答案解析.doc
《【计算机类职业资格】二级C++-64及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级C++-64及答案解析.doc(4页珍藏版)》请在麦多课文档分享上搜索。
1、二级 C+-64及答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文件夹 proj1下的工程 proj1。程序中位于每个“/ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是: Name:Smith Age:21 ID:99999 CourseNum:12 Record:970 注意:只修改每个“/ERROR *found*”下的一行,不要改动程序中的其他内容。 #include iostream using namespace std; class Stude
2、ntInfo protected: / ERROR * found* char Name; int Age; int ID; int CourseNum; float Record; public: / ERROR * found* void StudentInfo(char * name, int age, int ID, int courseNum, float record); / ERROR * found* void StudentInfo () delete Name; float AverageRecord() return Record/CourseNum; void show
3、()const; ; StudentInfo:StudentInfo (char *name, int age, int ID, int courseNum,float record) Name = strdup(name); Age = age; this-ID = ID; CourseNum = courseNum; Record = record; void StudentInfo:show()const cout “Name: “ Name “Age: “ Age“ID: “ ID “CourseNum: “ CourseNum “Record: “ Record endl; int
4、main() StudentInfo st (“Smith“, 21, 99999, 12, 970); st.show(); return 0; (分数:30.00)_二、B简单应用题/B(总题数:1,分数:30.00)2.请使用 VC6或使用答题菜单打开考生文件夹 proj2下的工程 proj2,其中包含抽象类 Shape的声明,以及在此基础上派生出的类 Rectangle和 Circle的声明,二者都有计算对象面积的函数 GetArea()和计算对象周长的函数 GetPerim()。程序中位于每个“/*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是: The
5、area ofthe Circle is 78.5 The perimeter of the Circle is 31.4 The area of the Rectangle is 24 The perimeter of the Rectangle is 20 注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/*found*”。 #include iostream using namespace std; class Shape public: Shape() Shape() /* found* _float GetArea() =0; /* found* _flo
6、at GetPerim () =0; ; class Circle : public Shape public: Circle (float radius): itsRadius (radius) Circle() float GetArea () return 3.14 * itsRadius * itsRadius; float GetPerim () return 6.28 * itsRadius; private: float itsRadius; ; class Rectangle : public Shape public: /* found* Rectangle(float le
7、n, float width): _; Rectangle(); virtual float GetArea() return itsLength * itsWidth; float GetPerim () return 2 * itsLength + 2 * itsWidth; virtual float GetLength() return itsLength; virtual float GetWidth () return itsWidth; private: float itsWidth; float itsLength; ; int main() /* found* _ sp =
8、new Circle(5); cout “The area of the Circle is“ sp-GetArea () endl; cout “The perimeter of the Circle is“ sp-GetPerim () endl; delete sp; sp = new Rectangle(4, 6); cout “The area of the Rectangleis“ sp-GetArea() endl; cout “The perimeter of the Rectangle is“ sp - GetPerim () endl; delete sp; return
9、0; (分数:30.00)_三、B综合应用题/B(总题数:1,分数:40.00)3.请使用 VC6或使用答题菜单打开考生文件夹 proj3下的工程 proj3,其中声明的 CDeepCopy是一个用于表示动态数组的类。请编写其中的复制构造函数。 要求: 补充编制的内容写在“/*333*”与“/*666*”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件 out.dat中。输出函数 writeToFile已经编译为 obj文件,并且在本程序中调用。/CDeepCopy.h #include iostream #include string using namespace std;
10、class CDeepCopy public: int n; /动态数组的元素个数 int * p; /动态数组首地址 CDeepCopy (int); CDeepCopy (); CDeepCopy(const CDeepCopy /复制构造函数 ; void writeToFile (char * ); /main. cpp #include “CDeepCopy. h“ CDeepCopy: CDeepCopy () delete p; CDeepCopy:CDeepCopy (int k) n = k; p=new intn; CDeepCopy: CDeepCopy ( const
11、CDeepCopy a.p0 =1; d.p0 =666; /对象 a,d 数组元素的赋值 CDeepCopy b (a); a.p0 =88; cout b.p0; /显示内层局部对象的数组元素 cout d.p0; /显示 d数组元素 a.p0的值 cout “ d fade away; /n“; cout a. pO; /显示 a数组元素 a.p0的值 writeToFile (“); return 0; (分数:40.00)_二级 C+-64答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文
12、件夹 proj1下的工程 proj1。程序中位于每个“/ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是: Name:Smith Age:21 ID:99999 CourseNum:12 Record:970 注意:只修改每个“/ERROR *found*”下的一行,不要改动程序中的其他内容。 #include iostream using namespace std; class StudentInfo protected: / ERROR * found* char Name; int Age; int ID; int CourseNum; floa
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 C64 答案 解析 DOC
