[计算机类试卷]国家二级C++机试(操作题)模拟试卷467及答案与解析.doc

上传人:eveningprove235 文档编号:497562 上传时间:2018-11-28 格式:DOC 页数:8 大小:35KB
下载 相关 举报
[计算机类试卷]国家二级C++机试(操作题)模拟试卷467及答案与解析.doc_第1页
第1页 / 共8页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷467及答案与解析.doc_第2页
第2页 / 共8页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷467及答案与解析.doc_第3页
第3页 / 共8页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷467及答案与解析.doc_第4页
第4页 / 共8页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷467及答案与解析.doc_第5页
第5页 / 共8页
点击查看更多>>
资源描述

1、国家二级 C+机试(操作题)模拟试卷 467及答案与解析 一、基本操作题 1 使用 VC6打开考生文件夹下的 proj1工程目录内的 proj1 dsw文件,其中在编辑窗口内显示的主程序文件中定义有 Xabc类和主函数 main。在程序文本中位于每行 ” ERROR*found*下面的一行有错误,请加以更正。 更正后程序的输出为: 57 注意:只允许修改每个 “ ERROR*found*下面的一行语句,不允许改动程序中的其他任何内容。 #include usng namespace std; class Xabc int*a; int n; public: Xabc(int aa, int n

2、n): n (nn) a=new intn; for(int i=0; i using namespace std; const int Size=5; class Stack; class Item public: *found* Item(const int&val): _ 构造函数对 item进行初始化 private: int item; Item * next; friend class Stack; ; class Stack public: Stack(): top(NULL) Stack(); int Pop(); void Push(const int&); private:

3、 Item*top; ; Stack: Stack() Item*p=top, *q; while(p!=NULL) q=p-next; *found* _; 释放 p所指向的节点 p=q; int Stack: Pop() Item*temp; int ret; *found* _; 使 temp指向栈顶节点 ret=top-item; top=top-next; delete temp; return ret; void Stack: Push(const int&val) Item*temp=new Item(val); *found* _; 使新节点的 next指针指向栈顶数据 top

4、=temp; int main() Stack s; for(int i=1; i #include using namespace std; class MyString public: MyString(const char*s) str=new charstrlen(S)+1; strcpy(str, s); MyString()deletestr; ) void reverse(); friend ostream&operator void MyString: reverse() *333* *666* int main() char inname128, pathname 80 ;

5、strcpy(pathname, “); sprintf(inname, “in dat“, pathname); coutnext=top 【试题解析】 (1)主要考查构造函数, 对私有成员进行初始化,即 item(val)。 (2)主要考查使用 delete语句释放指针,一般格式为: delete+指针。 (3)指向栈顶节点的是 top指针,要使 temp指向栈顶节点,故使用语句temp=top;。 (4)指向栈顶节点的是 top指针,要使新节点的 next指针指向栈顶数据,故使用语句 temp-next=top;。 三、综合应用题 3 【正确答案】 Int length=str上 en(

6、Str); 把字符串 str的长度赋值给 lenth for(int i=0, j=length-1; ij ; i+, j-) 从 i=0, j=length-1, ij为条件开始遍历,并把 Stri和 Strj交换 char temp=stri; 给定义的临时变量 temp赋值为 stri stri=strj; 给 Stri赋值 Strj strj=temp; 给 Strj赋值为 temp 【试题解析】 主要考查考生对动态数组的掌握,先看题目要求:成员函数reverse的功能是将字符串进行 “反转 ”。再由类的定义可 知,字符串存放在动态数组 str中,由 strlen函数得出字符串的长度,最后一个字符的下标为 length-1,第一个字符的下标为 0,将这两个字符交换,然后 j依次减 1同时 i依次加 1,继续交换,直到 i大于 j时停止循环即可。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试资料 > 职业资格

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1