11-12程序设计及算法语言Ⅱ上级考试试卷A(电类)答

上传人:pu****.1 文档编号:513152057 上传时间:2023-04-25 格式:DOC 页数:10 大小:51.16KB
返回 下载 相关 举报
11-12程序设计及算法语言Ⅱ上级考试试卷A(电类)答_第1页
第1页 / 共10页
11-12程序设计及算法语言Ⅱ上级考试试卷A(电类)答_第2页
第2页 / 共10页
11-12程序设计及算法语言Ⅱ上级考试试卷A(电类)答_第3页
第3页 / 共10页
11-12程序设计及算法语言Ⅱ上级考试试卷A(电类)答_第4页
第4页 / 共10页
11-12程序设计及算法语言Ⅱ上级考试试卷A(电类)答_第5页
第5页 / 共10页
点击查看更多>>
资源描述

《11-12程序设计及算法语言Ⅱ上级考试试卷A(电类)答》由会员分享,可在线阅读,更多相关《11-12程序设计及算法语言Ⅱ上级考试试卷A(电类)答(10页珍藏版)》请在金锄头文库上搜索。

1、程序设计与算法语言(电类) 2010 级机试(A 卷)(考试时间 80 分钟)说明:首先在网络 Z 盘建立一个以自己的学号+姓名命名的文件夹,在考试结束前根据机房要求,将要上交的源文件“学号-fa1.CPP”和“学号-fa2.CPP”复制到该文件夹中。注意:请在本机的 D 盘根目录上建立一个以自己学号命名的文件夹,将本次机试的两题所用的工程目录及文件均建立在此文件夹中。一、改错题 (50 分)【要求】调试程序,修改其中的语法错误及少量逻辑错误。只能修改、不能增加或删除整条语句,但可增加少量说明语句和编译预处理指令。 请在修改的语句后依次加上:/错误 1、/错误 2、。【注意】源程序以“学号-f

2、a1.cpp”命名,存入自己学号文件夹,然后在“学号-fa1.cpp”源文件中改错。请不要直接在此 WORD 文档上修改。【题目】以下程序实现了对字符串的选择排序,初始字符串为“Hello World!”,排序后输出字符串为“roollledWH!”。【含错误的源程序】#include using namespace std;void SelectSort( char )int main() int n=12; char listn=Hello World!; cout未排序字符串:listendl; SelectSort( listn ); cout已排序字符串:listnendl; ret

3、urn 0;void SelectSort( char slistn ) int i,j,k; char temp; for(i=0;in;i+) k=i; temp=slisti; for(j=0;jtemp)k=j;temp=slistj; if(k!=i) temp=slisti; slisti=slistk; slistk=temp;我编的:#include using namespace std;void SelectSort( char ,int );int main() int n=12; char list=Hello World!; cout未排序字符串:listendl;

4、SelectSort( list,n ); cout已排序字符串:listendl; return 0;void SelectSort( char slist,int n) int i,j,k; char temp; for(i=0;in;i+) k=i; temp=slisti; for(j=i;jtemp) k=j; temp=slistj; if(k!=i) temp=slisti; slisti=slistk; slistk=temp; 二、编程题(50 分)【注意】源程序以“学号-fa2.cpp”命名,存入自己学号文件夹。【题目】以下程序定义了一个链表类 List,其元素为整型数据结

5、点。链表可以通过流运算符从当前目录中的文件“ListA.txt”中读取数据,再向控制台输出。【说明】本程序的执行流程是,创建链表对象并通过文件设置链表初值,然后向链表中添加一些数据。请按以上说明和要求将下面程序补充完整,并调试运行。/此处添加代码class List;ostream& operator(istream &, List &);class Nodepublic: int info;/数据域 Node *link;/指针域 Node( const int data=0 ) info=data; link=NULL; ;class List Node *head, *tail;publ

6、ic: List(); List(); void Empty(); /清空整个链表 List &operator+=(const Node &a);/在当前表的最后添加一个元素 /用于直接输出链表对象/用于从文件输入链表对象friend ostream& operator(istream &, List &);List:List()/此处添加代码List:List() Empty(); delete head;void List:Empty()/此处添加代码List& List:operator+=(const Node &a)/此处添加代码ostream& operator(istream

7、&fs,List &a)/此处添加代码int main() List list; fstream file;/创建链表file.open(ListA.txt, ios:in);if( !file )cout Can not open input file!n list;file.close();file.clear();coutlist;for(int i=0;i3;i+)Node node(i);list += node;cout当前链表内容:endl;coutlist;return 0;/向链表中添加 3 个结点我编的:/此处添加代码#include#includeusing namesp

8、ace std;class List;ostream& operator(istream &, List &);class Nodepublic: int info;/数据域Node *link;/指针域Node( const int data=0 ) info=data; link=NULL; ;class List Node *head, *tail;public: List(); List(); void Empty(); /清空整个链表 List &operator+=(const Node &a); /在当前表的最后添加一个元素 friend ostream& operator(is

9、tream &, List &);/用于从文件输入链表对象;List:List()/此处添加代码 head=tail=new Node();List:List() Empty(); delete head;void List:Empty()/此处添加代码 Node* temp;while(head-link!=NULL) temp = head-link; head-link = temp-link; delete temp;tail=head;List& List:operator+=(const Node &a) Node* b = new Node(a.info);tail-link =

10、 b;tail = b;/此处添加代码return *this;ostream& operatorlink;while(temp)osinfotlink;return os;istream& operator(istream &fs,List &a) /此处添加代码 int aa; fsaa; /coutaa;while(1) Node* temp; temp = new Node(aa);a+=*temp;/coutaa;return fs;int main() List list; fstream file; /int y;/创建链表file.open(ListA.txt, ios:in);if( !file )cout Can not open input file!n endl;return 0;/cout#y;coutlist;file.close();file.clear();coutlist;for(int i=0;i3;i+)/向链表中添加 3 个结点 Node node(i); list += node;cout

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号