【计算机类职业资格】二级C++分类模拟130及答案解析.doc
《【计算机类职业资格】二级C++分类模拟130及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级C++分类模拟130及答案解析.doc(9页珍藏版)》请在麦多课文档分享上搜索。
1、二级 C+分类模拟 130 及答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.请使用 VC6 或使用【答题】菜单打开 proj1 下的工程 proj1,此工程中包含了类 Pets(“宠物”)和主函数 main 的定义。程序中位于每个“/ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: Name:sonny Tvpe:dog Name:John Type:dog Name:Danny Type:cat Name:John Type:dog 注意:只修改每个“/ ERROR *found*”下的那一行,不
2、要改动程序中的其他内容。 #include iostream using namespace std; enum Pets_type dog, cat, bird, fish; class Pets private: char * name; Pets_type type; public: Pets (const char * name = “sonny“, Pets_type type = dog); Pets Pets(); void show() const; ; Pets:Pets (const char * name, Pets_type type) /构造函数 this - nam
3、e = new charstrlen(name) + 1; strcpy(this - name, name); / ERROR *found* type = type; Pets: Pets() /构造函数,释放 name 所指向的字符串 / ERROR *found* name = “/0“; Pets delete name; name = new char strlen (s.name) + 1; / ERROR *found* strcpy (this - name, name); type = s.type; return * this; void Pets:show() cons
4、t cout “Name:“ name “Type:“; switch (type) case dog: cout “dog“; break; case cat: cout “cat“; break; case bird: cout “bird“; break; case fish: cout “fish“; break; cout endl; int main() Pets mypet1, mypet2 (“John“, dog); Pets youpet(“Danny“, cat); mypet1.show(); mypet2.show(); youpet.show(); youpet =
5、 mypet2; youpet.show(); return 0; (分数:30.00)_二、简单应用题(总题数:1,分数:30.00)2.请使用 VC6 或使用【答题】菜单打开 proj2 下的工程 proj2,该工程中包含一个程序文件 main.cpp,其中有类 CPolygon(“多边形”)、CRectangle(“矩形”)、CTriangle(“三角形”)的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。该程序的正确输出结果应为: 20 10 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/ *found*”。 #include iostre
6、am using namespace std; class CPolygon public: / *found* _/纯虚函数 area 声明 void printarea (void) / *found* cout _ endl; ; class CRectangle: public CPolygon int width; /长方形宽 int height; /长方形高 public: CRectangle (int w, int h): width (w), height (h) int area (void) return (width * height); ; class CTrian
7、gle : public CPolygon int length; /三角形一边长 int height; /该边上的高 public: CTriangle (int 1, int h): length (1), height (h) / *found* int area (void) return (_)/2; ; int main() CRectangle rect (4,5); CTriangle trgl (4,5); / *found* _*ppoly1, *ppoly2; ppoly1 = ppoly2 = ppoly1 - printarea(); ppoly2 - printa
8、rea(); return 0; (分数:30.00)_三、综合应用题(总题数:1,分数:40.00)3.请使用【答题】菜单命令或直接用 VC6 打开 下的工程 prog3,其中声明了 ValArray 类,该类在内部维护一个动态分配的整型数组。ValArray 类的复制构造函数应实现对象的深层复制。请编写 ValArray 类的复制构造函数。在 main 函数中给出了一组测试数据,此种情况下程序的输出应该是: ValArray v1=1,2,3,4,5 ValArray v2=1,2,3,4,5 要求: 补充编制的内容写在“/ *333*”与“/*666*”之间,不得修改程序的其他部分。 注
9、意:程序最后将结果输出到文件 out.dat 中。输出函数 writeToFile 已经编译为 boj 文件,并且在本程序中调用。 /ValArray.h #include iostream using namespace std; class ValArray int * v; int size; public: ValArray (const int * p, int n) : size(n) v = new intsize; for (int i = 0; i size; i +) vi = pi; ValArray (const ValArray ValArray() delete v
10、; void print (ostream for (int i = 0; i size -1; i +) out vi “,“; out vsize-1 “; void setArray (int i, int val) vi = val; ; void writeToFile(const char *); /main.cpp #include “ValArray.h“ ValArray: ValArray (const ValArray ValArray v1(a, 5); cout “ValArray v1 =“; v1.print(cout); cout endl; ValArray
11、v2(v1); cout “ValArray v2 =“; v2.print(cout); cout endl; writeToFile(“ “); return 0; (分数:40.00)_二级 C+分类模拟 130 答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.请使用 VC6 或使用【答题】菜单打开 proj1 下的工程 proj1,此工程中包含了类 Pets(“宠物”)和主函数 main 的定义。程序中位于每个“/ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: Name:sonny Tvpe
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 分类 模拟 130 答案 解析 DOC
