【计算机类职业资格】国家二级C++机试(操作题)模拟试卷338及答案解析.doc
《【计算机类职业资格】国家二级C++机试(操作题)模拟试卷338及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】国家二级C++机试(操作题)模拟试卷338及答案解析.doc(5页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 338 及答案解析(总分:8.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.请使用 VC6 或使用【答题】菜单打开考生文件夹 pmjl 下的工程 pmjl。其中有线段类 Line 的定义。程序中位于每个“ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是: End point 1=(1,8),End point 2=(5,2),length=72111。 注意:只修改每个“ERROR*found*”下的那一行,不要改动程序中的其他内容。#includeiostream#includecmat
2、husing namespace std;class Line;double length(Line); class Line 线段类 double x1,y1;线段端点 1 double x2,y2;线段端点2public:ERROR*found* Line(double x1,double yl,doublex2,double y2)const this-x1=x1; this-y1=y1; this-x2=x2; this-y2=y2; double getX1()constreturn x1; double getYl()constreturn y1; double getX2()co
3、nstreturn x2; double getY2()constreturn y2; void show()const tout”End point 1=(”x1”,”y1; cout”),End point 2=(”x2”,”y2;ERROR* found* cout”),length=”length(this) ”o”endl; ;double length(Line 1)ERROR*found* return sqrt(1x11x2)*(1x11x2)+(1y11y2)*(1y1 一 1y2);int main() Line r1(10,80,50,20); r1show();retu
4、rn 0;(分数:2.00)_二、简单应用题(总题数:2,分数:4.00)2.请使用 VC6 或使用【答题】菜单打开考生文件夹 proj2 下的工程 proj2,此工程中包含一个头文件shapeh,其中包含了类 Shape、Point 和 Triangle 的声明;包含程序文件 shapecpp,其中包含了类Tfiangle 的成员函数和其他函数的定义;还包含程序文件 proj2cpp,其中包含测试类 Shape、Point和 Triangle 的程序语句。请在程序中的横线处填写适当的代码并删除横线,以实现上述功能。此程序的正确输出结果应为: 此图形是一个抽象图形,周长=0,面积=0 此图形是
5、一个三角形,周长=682843,面积=2 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“*found*”。/shapeh class Shapepublic: virtual double perimeter()constreturn 0;) 返回形状的周长 virtual double area()constre-turn 0; 返回形状的面积 virtual const char* name()constreturn“抽象图形“;) 返回形状的名称;class Point表示平面坐标系中的点的类 double x; double Y;public:*foun
6、d* Point (double x0,double y0):_用x0、y0 初始化数据成员 x、y double getX()constreturn x;) double getY()const ( return y;) ; class Triangle:public Shape *found* _:定义 3 个私有数据成员 public: Triangle(Point p1,Point p2,Point p3):pointl(p1),point2(p2),point3(p3) double perimeter()cons t; double area()const; const char*
7、name()constreturn”三角形”;);shapecpp#include”shapeh”#includecmathdouble length(Point pl,Point p2) return sqrt(p1getX()一 p2getX()*(p1getX()一 p2getX()+(p1getY()一 p2getY()*(p1getY()一p2getY();double Triangle:perimeter()const一个 return 语句,它利用 length 函数计算并返回三角形的周长*found*_;double Triangle:area()const double s=
8、perimeter()20; return sqrt(s*(slength(pointl,point2)* (slength(point2,point3)* (Slength(point3,pointl);proj2cpp#include”shapeh”#includeiostreamusing namespace std;*found*show 函数的函数头(函数体以前的部分) cout“此图形是一个“shapename()”,周长=”shapeperimeter()”,面积=”shapearea()endl;int main() Shape s; Triangle tri(Point(0,
9、2),Point(2,0),Point(0,0); show(s); show(tri); return 0;(分数:2.00)_3.请使用 VC6 或使用【答题】菜单打开考生文件夹 proj2 下的工程 proj2,此工程包含有一个源程序文件proj2cpp,其中定义了 Stack 类和 ArrayStack 类。 Stack 是一个用于表示数据结构“栈”的类,栈中的元素是字符型数据。Stack 为抽象类,它只定义了栈的用户接口,如下所示: 公有成员函数 功能 push 入栈:在栈顶位置添加一个元素 pop 退栈:取出并返回栈顶元素 ArrayStack 是 Stack 的派生类,它实现了
10、Stack 定义的接口。ArrayStack 内部使用动态分配的字符数组作为栈元素的存储空间。数据成员 maxSize 表示的是栈的最大容量,top 用于记录栈顶的位置。成员函数 push 和 poP 分别实现具体的入栈和退栈操作。 请在程序中的横线处填写适当的代码,然后删除横线,以实现上述功能。此程序的正确输出结果应为: a,b,c c,b,a 注意:只在指定位置编写适当代码,不要改动程序中的其他内容,也不要删除或移动“*found*”。proj 2cpp#includeiostreamusing namespace std;class Stackpublic: virtual void p
11、ush(char c)=0; virtual char pop()=0;;class ArrayStack:public Stack char*P; int maxSize; int top;public: ArrayStack(int s) top=0; maxSize=s;/*found*p=_; 一 ArrayStack() /*found*_;void push(char c) if(top=maxSize) cerr”Overflow!n”; return; *found*_; top+; char pop() if(top=0) cerr”Underflow! n”; return
12、0; top-;/* found*_;;void f(Stack void writeTOFile(const char*); maincpp #include”ValArrayh” ValArray:ValArray(const ValArray v2print(cout); coutendl; writeToFile(”); return 0;(分数:2.00)_国家二级 C+机试(操作题)模拟试卷 338 答案解析(总分:8.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.请使用 VC6 或使用【答题】菜单打开考生文件夹 pmjl 下的工程 pmjl。其中有线
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 国家 二级 机试 操作 模拟 试卷 338 答案 解析 DOC
