【计算机类职业资格】二级C++分类模拟120及答案解析.doc
《【计算机类职业资格】二级C++分类模拟120及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级C++分类模拟120及答案解析.doc(9页珍藏版)》请在麦多课文档分享上搜索。
1、二级 C+分类模拟 120 及答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.请使用 VC6 或使用【答题】菜单打开 proj1 下的工程 proj1,此工程包含一个源程序文件 proj1.cpp。其中位于每个注释“/ ERROR *found*”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为:You are fight. 注意:只修改注释“/ERROR *found*”的下一行语句,不要改动程序中的其他内容。 / proj1.cpp #include iostream using namespace std; class My
2、Class public: MyClass(int x):number(x) / ERROR *found* MyClass(int x) / ERROR *found* void Judge(MyClass private: int number; ; void Judge(MyClass else cout “Sorry“ endl; int main() / ERROR *found* MyClass object; Judge(object); return 0; (分数:30.00)_二、简单应用题(总题数:1,分数:30.00)2.请使用 VC6 或使用【答题】菜单打开 proj2
3、 下的工程 proj2,此工程中包含一个头文件 shape.h,其中包含了类 Shape、Point 和 Triangle 的声明;包含程序文件 shape.cpp,其中包含了类 Triangle 的成员函数和其他函数的定义;还包含程序文件 proj2.cpp,其中包含测试类 Shape、Point 和 Triangle 的程序语句。请在程序中的横线处填写适当的代码并删除横线,以实现上述功能。此程序的正确输出结果应为: 此图形是一个抽象图形,周长=0,面积=0 此图形是一个三角形,周长=6.82843,面积=2 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/
4、*found*”。 /shape.h class Shape public: virtual double perimeter() const return 0; /返回形状的周长 virtual double area() const return 0; /返回形状的面积 virtual const char * name() const return “抽象图形“; /返回形状的名称 ; class Point /表示平面坐标系中点的类 double x; double y; public: / *found* Point (double x0, double y0): _ /用 x0、y
5、0 初始化数据成员 x、y double getX() const return x; double getY() const return y; ; class Triangle: public Shape / *found* _; /定义 3 个私有数据成员 public: Triangle (Point p1, Point p2, Point p3): point1 (p1), point2 (p2), point3 (p3) double perimeter () const; double area() const; const char * name() const return
6、“三角形“; ; /shape.cpp #include “shape.h“ #include cmath double length (Point p1, Point p2) return sqrt (p1.getX() -p2.getX() * (p1.getX() -p2.getX() + (p1.getY() -p2.getY() * (p1.getY() -p2.getY(); double Triangle: perimeter () const /一个 return 语句,它利用 length 函数计算并返回三角形的周长 / *found* _; double Triangle:
7、area() const double s = perimeter()/2.0; return sqrt (s * (s - length (point1, point2) * (s - length (point2, point3) * (s - length (point3, point1); /proj2.cpp #include “shape.h“ #include iostream using namespace std; / *found* _ /show 函数的函数头(函数体以前的部分) cout “此图形是一个“ shape.name() “,周长=“ shape.perime
8、ter() “,面积=“ shape.area() endl; int main() Shape s; Triangle tri(Point(0,2), Point(2,0), Point(0,0); show(s); show(tri); return 0; (分数:30.00)_三、综合应用题(总题数:1,分数:40.00)3.请使用【答题】菜单命令或直接用 VC6 打开考生文件夹下的工程 proj3,其中声明的是一个人员信息类,补充编制程序,使其功能完整。在 main 函数中给出了一组测试数据,此种情况下程序的输出应该是:Zhang 20 Tsinghua。 注意:只能在函数 addre
9、ss_change 的“/ *333*”和“/ *666*”之间填入若干语句,不要改动程序中的其他内容。 程序最后将结果输出到文件 out.dat 中。输出函数 writeToFile 已经编译为 obj 文件,并且在本程序中调用。 /proj3.h #include iostream #include string using namespace std; class Person char name20; int age; char * address; public: Person() age = 0;address = 0; void name_change (char *_name)
10、; /名字修改函数 void age_change(int_age); /年龄修改函数 void address_change (char *_add); /地址修改函数 void info_display(); /人员信息显示 Person(); /析构函数 ; void writeToFile(const char * path); proj3.cpp #include iostream #include string #include “proj3.h“ using namespace std; void Person:name_change(char*_name) strcpy(nam
11、e, _name); void Person:age_change(int _age) age = _age; void Person:address _change (char * add) if (address!=NULL) deleteaddress; / *333* / *666* void Person:info_display() cout name “/t“ age “/t“; if(address!=NULL) cout address endl; cout endl; Person:Person() if(address!=NULL) delete address; voi
12、d main() Person p1; p1.name_change(“Zhang“); p1.age_change(20); p1.address_change(“Tsinghua University“); p1.address_change(“Tsinghua“); p1.info_display(); writeToFile(“ “); (分数:40.00)_二级 C+分类模拟 120 答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.请使用 VC6 或使用【答题】菜单打开 proj1 下的工程 proj1,此工程包含一个源程序文件
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 分类 模拟 120 答案 解析 DOC
