电大C语言程序设计期末考试试题及答案参考

上传人:仙*** 文档编号:84621348 上传时间:2022-05-04 格式:DOC 页数:14 大小:100KB
收藏 版权申诉 举报 下载
电大C语言程序设计期末考试试题及答案参考_第1页
第1页 / 共14页
电大C语言程序设计期末考试试题及答案参考_第2页
第2页 / 共14页
电大C语言程序设计期末考试试题及答案参考_第3页
第3页 / 共14页
资源描述:

《电大C语言程序设计期末考试试题及答案参考》由会员分享,可在线阅读,更多相关《电大C语言程序设计期末考试试题及答案参考(14页珍藏版)》请在装配图网上搜索。

1、C+语言程序设计期末考试试题及答案姓名 学号班号 题号-一一二(1)二(2)三三总分成绩一、填空1在类中必须声明成员函数的原型 ,成员函数的 实现 部分可以写在类外。2. 如果需要在被调函数运行期间,改变主调函数中实参变量的值,则函数的形参应该是引用 类型或 指针 类型。3. 抽象类只能作为基类使用,而不能声明它的对象。4. 进行函数重载时,被重载的同名函数如果都没有用const修饰,则它们的形参个数 或 类型 必须不同。5. 通过一个 常 对象只能调用它的常成员函数,不能调用其他成员 函数。6. 函数的递归调用是指函数直接或间接地调用自身 。7. 拷贝构造函数的形参必须是本类对象的引用。二、

2、阅读下列程序,写出其运行时的输出结果 如果程序运行时会出现错误,请简要描述错误原因。1. 请在以下两题中任选一题,该题得分即为本小题得分。如两题都答, 则取两题得分之平均值为本小题得分。(1)程序:int n;public:#in elude #in clude class Base private:Base(char s,i nt m=0): n(m) strcpy(msg,s);char msg30;protected:void output(void) cout nen dlmsge ndl; ;class Derived1:public Baseprivate:int n;public

3、:Derived1(i nt m=1):Base(Base,m-1) n=m; void output(void) cout nen dl;Base:output();class Derived2:public Derived1private:int n;public:Derived2(i nt m=2):Derived1(m-1) n=m; void output(void) cout nen dl;Derived1:output();int mai n()Base B(Base Class,1);Derived2 D;B.output();D.output();运行结果:1Base Cla

4、ss210Base(2)程序:int GetMuti()return i*j; protected:int i;int j;#in clude class Samppublic:void Setij(i nt a,i nt b)i=a,j=b; Samp()coutDestro yin g.ie ndl;int mai n()Samp *p;p=new Samp5;if(!p)coutAllocati on error n;return 1;for(i nt j=0;j5;j+)pj.Setij(j,j);for(int k=0;k5;k+) coutMutik is:pk.GetMuti()

5、e ndl;deletep;return 0;运行结果:Muti0 is:0Muti1 is:1Muti2 is:4Muti3 is:9Muti4 is:16Destroyi ng.4Destroyi ng.3Destroyi ng.2Destroyi ng.1Destroyi ng.O2. 请在以下两题中任选一题,该题得分即为本小题得分。如两题都答, 则取两题得分之平均值为本小题得分。(1)程序:#i nclude #in clude class Vectorpublic:Vector(i nt s=100); int& Elem(i nt ndx); void Display(void);

6、 void Set(void); Vector(void);int size;int *buffer;Vector:Vector(i nt s)buffer=new in tsize=s;protected:for(i nt j=0; jsize; j+) Elem(j)=j+1;Vector:Vector(void)delete buffer;int mai n()Vector a(10);Vector b(a);a. Set();b. Display();int& Vector:Elem(i nt n dx)if(n dx=size)couterror in in dexe ndl; ex

7、it(1);retur n buffer ndx;void Vector:Display(void)for(i nt j=0; jsize; j+) coutElem(j)e ndl;void Vector:Set(void)运行结果:12345678910最后出现错误信息,原因是:声明对象 b是进行的是浅拷贝,b与a共用同 一个buffer,程序结束前调用析构函数时对同一内存区进行了两次释放。(2)程序:#in cludeclass CATpublic:CAT();CAT(co nst & CAT);CAT();int GetAge() return *itsAge; void SetAge

8、( int age ) *itsAge=age; protected:int * itsAge;CAT:CAT()itsAge=new int;*itsAge=5;CAT:CAT()delete itsAge;itsAge=NULL;int mai n()CAT a;coutas age:a.GetAge()e ndl;a.SetAge(6);CAT b(a);coutas age:a.GetAge()e ndl;coutbs age:b.GetAge()e ndl;a.SetAge(7);coutas age:a.GetAge()e ndl;coutbs age:b.GetAge()e nd

9、l;运行结果:as age:5as age:6bs age:6as age:7bs age:7最后出现错误信息,原因是:声明对象b是进行的是浅拷贝,b与a共用同一个buffer,程序结束前调用析构函数时对同一内存区进行了两次释放。三、阅读下列程序及说明和注释信息,在方框中填写适当的程序段, 使程序完成指定的功能程序功能说明:从键盘读入两个分别按由小到大次序排列的整数序列,每个 序列10个整数,整数间以空白符分隔。用这两个序列分别构造两个单链表,每个 void CopyList(const LinkedList& L); /将链表 L 拷贝到当前表链表有10个结点,结点的数据分别按由小到大次序排

10、列。然后将两个链表合成为 一个新的链表,新链表的结点数据仍然按由小到大次序排列。最后按次序输出合 并后新链表各结点的数据。程序运行结果如下,带下划线部分表示输入内容,其余是输出内容:1 3 5 7 9 11 13 15 17 192 4 6 8 10 12 14 16 18 201 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20#include #include /类定义部分template class Nodeprivate:指向后继节点的指针Node *next; /public:T data; /数据域Node (const T& ite

11、m, Node* ptrnext = NULL); /构造函数void lnsertAfter(Node *p); /在本节点之后插入一个同类节点pNode *DeleteAfter(void); /删除本节点的后继节点,返回其地址获取后继节点的地址Node *NextNode(void) const; /;template class LinkedListprivate:Node *front, *rear; /表头和表尾指针Node *prevPtr, *currPtr;/记录表当前遍历位置的指针,由插入和删除操作更新int size; /表中的元素个数int position; /当前元

12、素在表中的位置序号。由函数Reset使用Node *GetNode(const T& item,Node *ptrNext=NULL);/生成新节点,数据域为item,指针域为ptrNext/假设当前表为空)。被拷贝构造函数、 operator= 调用public:LinkedList(void); / 构造函数LinkedList(const LinkedList& L); /拷贝构造函数LinkedList(void); /析构函数LinkedList& operator= (const LinkedList& L);/重载赋值运算符int ListSize(void) const; /返

13、回链表中元素个数( size )int ListEmpty(void) const; /size void Reset(int pos = 0); /为0时返回TRUE否则返回FALSE将指针 currPtr 移动到序号为 pos 的节点,/prevPtr相应移动 ,position 记录当前节点的序号void Next(void); /使 prevPtr 和 currPtr 移动到下一个节点int EndOfList(void) const; / currPtr int CurrentPosition(void) const; / void InsertFront(const T& item

14、); / void InsertRear(const T& item); / void InsertAt(const T& item); / void InsertAfter(const T& item); /等于NULL时返回TRUE,否则返回FALSE返回数据成员 position在表头插入一个数据域为 item 的节点 在表尾添加一个数据域为 item 的节点 在当前节点之前插入一个数据域为 item 的节点T DeleteFront(void); /删除头节点 , 释放节点空间,更新 prevPtr 、currPtr 和 sizevoid DeleteAt(void); /删除当前节点

15、 , 释放节点空间,更新 prevPtr 、currPtr 和 sizeT& Data(void); /返回对当前节点成员 data 的引用在当前节点之后插入一个数据域为 item 的节点void ClearList(void); /清空链表:释放所有节点的内存空间;/ 类实现部分略template void MergeList(LinkedList* la, LinkedList* lb,LinkedList* lc)/ 合并链表 la 和 lb, 构成新链表 lc 。/ 函数结束后,程序的数据所占内存空间总数不因此函数的运行而增加 while ( !la-ListEmpty() &!lb-

16、ListEmpty() if (la-Data()v=lb-Data() lc-l nsertRear(la-Data(); la-DeleteAt();elselc-I nsertRear(lb-Data();lb-DeleteAt();while ( !la-ListEmpty()lc-I nsertRear(la-Data(); la-DeleteAt();while ( !lb-ListEmpty()lc-I nsertRear(lb-Data(); lb-DeleteAt();int main()Lin kedListv int la, lb, lc;int item, i;/读如数

17、据建立链表lafor (i=0;i item;la.I nsertRear(item);la.Reset();/读如数据建立链表lbfor (i=0;i item;Ib.I nsertRear(item);lb.Reset();MergeList(&la, &b, & c);/合并链表lc.Reset(); 输出各节点数据,直到链表尾while(!lc.E ndOfList()cout vlc.Data() ;lc.Next(); /使currPtr指向下一个节点cout en dl;If we dont do that it will go on and go on. We have to

18、stop it; we need the courage to do it.His comme nts came hours after Fifa vice-preside nt Jeffrey Webb - also in London for the FAs celebrati ons - said he wan ted to meet Ivory Coast intern ati onal Toure to discuss his complai nt.CSKA gen eral director Roma n Babaev says the matter has bee n exagg

19、eratedby the Ivoria n and the British media.Blatter, 77, said: It has been decided by the Fifa congress that it is a nonsense for racism to be dealt with with fines. You can always find money from somebody to pay them.It is a nonsense to have matches played without spectators because it is against t

20、he spirit of football and against the visiting team. It is all nonsen se.We can do someth ing better to fight racism and discrim in atio n.This is one of the villains we have today in our game. But it is only with harsh sanctions that racism and discrim in ati on can be washed out of football.The (l

21、ack of) air up there ranENDENDLondon for the Football 150th anni versary will atte nd Citys Premierwatch m CaymanIsla nds-based Webb, the head of Fifas an ti-racism taskforce, is in Associatio ns celebrati ons and League match atChelsea on Sun day.I am going to be at the match tomorrow and I have as

22、ked to meet Yaya Toure, he told BBC Sport.For me its about how he felt and I would like to speak to him first to find out what his experie nee was.Uefa has opened disciplinary proceedings against CSKAfor the racist behaviour of their fans duri ng Citys 2-1 win.Michel Plati ni, preside nt of Europea

23、n footballs gover ning body, has also ordered an immediate in vestigati on into the referees acti ons. CSKA said they were surprised and disappo in ted by Toures compla int. In a statement the Russian side added: We found no racist insults from fans of CSKA.Baumgart ner the disappo in ti ng n ews: M

24、issi on aborted. The supers onic desce nt could happe n as early as Sun da.The weather plays an importa nt role in this missi on. Start ing at the ground, con diti ons have to be very calm - winds less tha n 2 mph, with no precipitati on or humidity and limited cloud cover. The balloon, with capsule

25、 attached, will move through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. It will climb higher than the tip of Mount Everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airli ners (5.6 miles/9.17 kilometers) an

26、d in to the stratosphere. As he crosses the boun dary layer (called the tropopause),e can expect a lot of turbule nee.The balloon will slowly drift to the edge of space at 120,000 feet (ENDThen, I would assume, he will slowly step out onto someth ing resembli ng an Olympic diving platform.Below, the

27、 Earth becomes the con crete bottom of a swim ming pool that he wants to land on, but not too hard. Still, hell be traveli ng fast, so despite the distanee, it will not be like diving into the deep end of a pool. It will be like he is diving into the shallow end.Skydiver preps for the big jumpWhe n

28、he jumps, he is expected to reach the speed of sound - 690 mph (1,110 kph) -in less tha n 40 sec on ds. Like hitt ing the top of the water,he will beg into slow as he approaches the more dense air closer to Earth. But this will not be eno ugh to stop him completely.If he goes too fast or spins out o

29、f con trol, he has a stabilizati on parachute that can be deployed to slow him dow n. His team hopes its not n eeded. In stead, he pla ns to deploy his 270-square-foot (25-square-meter) main chute at an altitude of around 5,000 feet (1,524 meters).In order to deploy this chute successfully, he will

30、have to slow to 172 mph (277 kph). He will have a reserve parachute that will ope n automatically if he loses con scious ness at mach speeds.Eve n if everythi ng goes as pla nn ed, it wont. Baumgart ner still will free fall at a speed that would cause you and me to pass out, and no parachute is guara nteed to work higher than 25,000 feet (7,620 meters).cause there

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!