[计算机类试卷]国家二级C++机试(操作题)模拟试卷296及答案与解析.doc
《[计算机类试卷]国家二级C++机试(操作题)模拟试卷296及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(操作题)模拟试卷296及答案与解析.doc(9页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 296及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 proj1,其中有点类 Point和线段类 Line和主函数 main的定义,程序中位于每个 “ ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出应为: p1 (8, 4)p2 (3, 5) 注意:只修改两个 “ ERROR *found*”下的那一行,不要改动程序中的其他内容。 #include iostream #include cmath using namespace std; class Point doubl
2、e x, y; public: Point(double x 0 0, double y 0 0) ERROR *found* x x; y y; ) double getX()constreturn x; double getY()constreturn y; ERROR *found* void show()constcout ( x , y ) ; class Line Point p1, p2; public: Line(Point pt1, Point pt2) ERROR *found* pt1 p1; pt2 p2; Point getP1()constreturnp1; Poi
3、nt getP2()constreturnp2; ; int main() Line line(Point(8, 4), Point(3, 5); cout “p1 “; line getPl() show(); cout “p2 “; line getP2() show(); cout end1; return 0; 二、简单应用题 2 请使用 VC6或使用【答题】菜单打开考生文件夹 proj2下的工程 proj2,其中有整数栈类 IntList、顺序栈类 SeqList和链接栈类 LinkList的定义。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为
4、: 4 6 3 1 8 4 6 3 1 8 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动 “*found*”。 #include iostream using namespace std; class IntStack 整数栈类 public: virtual void push(int) 0; 入栈 virtual int pop() 0; 出栈并返回出栈元素 virtual int topElement() const 0; 返回栈顶元素,但不出栈 virtual bool isEmpty()const 0; 判断是否栈空 ; class SeqStack:
5、 public IntStack int data100;存放栈元素的数组 int top; 栈顶元素的下标 public: *found* SeqStack(): _ 把 top初始化为 1表示栈空 void push(int n)data top n; *found* int pop()return_; int topElement()constreturn datatop; bool isEmpty()constreturn top 1; ; struct Node int data; NOde * next; ; class LinkStack: public IntStack Nod
6、e * top; public: *found* LinkStack(): _ 把 top初始化为 NULL表示栈空 void push(int n) Node *P new Node; p data n; *found* _; top P; int pop() int d top data; top top next; return d; int topElement()const return top data; bool isEmpty()constreturn top NULL; ; void pushData(IntStack&st) st push(8); st push(1);
7、st push(3); st push(6); st push(4); void popData(IntStack&st) while(!st isEmpty() cout st pop() “; int main() SeqStack st1; pushData(st1); popData(st1); cout end1; LinkStack st2; pushData(st2); popData(st2); cout end1; return 0; 三、综合应用题 3 请使用 VC6或使用【答题】菜单打开考生文件夹 proj3下的工程 proj3,其中声明 IntSet是一个用于表示正整数
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 操作 模拟 296 答案 解析 DOC
