欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > DOC文档下载  

    电大C++语言程序设计期末考试试题及答案小抄参考.doc

    • 资源ID:2198385       资源大小:152.51KB        全文页数:12页
    • 资源格式: DOC        下载积分:8金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要8金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    电大C++语言程序设计期末考试试题及答案小抄参考.doc

    专业好文档C+语言程序设计 期末考试试题及答案姓名 _ 学号 _ 班号 _ 题 号一二(1)二(2)三总 分成 绩一、填空1在类中必须声明成员函数的 原型 ,成员函数的 实现 部分可以写在类外。2如果需要在被调函数运行期间,改变主调函数中实参变量的值,则函数的形参应该是 引用 类型或 指针 类型。3 抽象 类只能作为基类使用,而不能声明它的对象。4进行函数重载时,被重载的同名函数如果都没有用const修饰,则它们的形参 个数 或 类型 必须不同。5通过一个 常 对象只能调用它的常成员函数,不能调用其他成员函数。6函数的递归调用是指函数直接或间接地调用 自身 。7拷贝构造函数的形参必须是 本类对象的引用 。二、阅读下列程序,写出其运行时的输出结果 如果程序运行时会出现错误,请简要描述错误原因。1请在以下两题中任选一题,该题得分即为本小题得分。如两题都答,则取两题得分之平均值为本小题得分。(1)程序:- 12 -#include <iostream.h>#include <string.h>class Base private: char msg30; protected: int n; public: Base(char s,int m=0):n(m) strcpy(msg,s); void output(void) cout<<n<<endl<<msg<<endl; ;class Derived1:public Baseprivate:int n;public:Derived1(int m=1):Base("Base",m-1) n=m; void output(void) cout<<n<<endl; Base:output();class Derived2:public Derived1private:int n;public:Derived2(int m=2):Derived1(m-1) n=m; void output(void) cout<<n<<endl; Derived1:output();int main()Base B("Base Class",1);Derived2 D;B.output();D.output();运行结果:1Base Class210Base(2)程序:#include <iostream.h>class Samppublic:void Setij(int a,int b)i=a,j=b;Samp()cout<<"Destroying."<<i<<endl;int GetMuti()return i*j; protected:int i;int j;int main()Samp *p;p=new Samp5;if(!p)cout<<"Allocation errorn"return 1;for(int j=0;j<5;j+)pj.Setij(j,j);for(int k=0;k<5;k+)cout<<"Muti"<<k<<" is:" <<pk.GetMuti()<<endl;deletep;return 0;运行结果:Muti0 is:0Muti1 is:1Muti2 is:4Muti3 is:9Muti4 is:16Destroying.4Destroying.3Destroying.2Destroying.1Destroying.02请在以下两题中任选一题,该题得分即为本小题得分。如两题都答,则取两题得分之平均值为本小题得分。(1)程序:#include <iostream.h>#include <stdlib.h>class Vector public: Vector(int s=100); int& Elem(int ndx); void Display(void); void Set(void); Vector(void); protected: int size; int *buffer;Vector:Vector(int s)buffer=new intsize=s;int& Vector:Elem(int ndx)if(ndx<0|ndx>=size)cout<<"error in index"<<endl;exit(1);return bufferndx;void Vector:Display(void)for(int j=0; j<size; j+)cout<<Elem(j)<<endl;void Vector:Set(void)for(int j=0; j<size; j+)Elem(j)=j+1;Vector:Vector(void)delete buffer;int main()Vector a(10);Vector b(a);a.Set();b.Display();运行结果:12345678910最后出现错误信息,原因是:声明对象b是进行的是浅拷贝,b与a共用同一个buffer,程序结束前调用析构函数时对同一内存区进行了两次释放。(2)程序:#include<iostream.h>class CAT public: CAT(); CAT(const &CAT); CAT(); int GetAge() return *itsAge; void SetAge( int age ) *itsAge=age; protected: int * itsAge;CAT:CAT()itsAge=new int;*itsAge=5;CAT:CAT()delete itsAge;itsAge=NULL;int main()CAT a;cout<<"a's age:"<<a.GetAge()<<endl;a.SetAge(6);CAT b(a);cout<<"a's age:"<<a.GetAge()<<endl;cout<<"b's age:"<<b.GetAge()<<endl;a.SetAge(7);cout<<"a's age:"<<a.GetAge()<<endl;cout<<"b's age:"<<b.GetAge()<<endl;运行结果:a's age:5a's age:6b's age:6a's age:7b's age:7最后出现错误信息,原因是:声明对象b是进行的是浅拷贝,b与a共用同一个buffer,程序结束前调用析构函数时对同一内存区进行了两次释放。三、阅读下列程序及说明和注释信息,在方框中填写适当的程序段,使程序完成指定的功能 程序功能说明:从键盘读入两个分别按由小到大次序排列的整数序列,每个序列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 <iostream.h>#include <stdlib.h>/类定义部分template <class T>class Node private: Node<T> *next; /指向后继节点的指针 public: T data; /数据域 Node (const T& item, Node<T>* ptrnext = NULL); / 构造函数 void InsertAfter(Node<T> *p); /在本节点之后插入一个同类节点p Node<T> *DeleteAfter(void); /删除本节点的后继节点,返回其地址 Node<T> *NextNode(void) const; / 获取后继节点的地址;template <class T>class LinkedList private: Node<T> *front, *rear; / 表头和表尾指针 Node<T> *prevPtr, *currPtr; /记录表当前遍历位置的指针,由插入和删除操作更新 int size; / 表中的元素个数 int position; / 当前元素在表中的位置序号。由函数Reset使用 Node<T> *GetNode(const T& item,Node<T> *ptrNext=NULL); / 生成新节点,数据域为item,指针域为ptrNext void FreeNode(Node<T> *p); /释放节点 void CopyList(const LinkedList<T>& L); / 将链表L 拷贝到当前表 /(假设当前表为空)。被拷贝构造函数、operator=调用 public: LinkedList(void); / 构造函数 LinkedList(const LinkedList<T>& L); /拷贝构造函数 LinkedList(void); / 析构函数 LinkedList<T>& operator= (const LinkedList<T>& L);/重载赋值运算符 int ListSize(void) const; /返回链表中元素个数(size) int ListEmpty(void) const; /size为0时返回TRUE,否则返回FALSE void Reset(int pos = 0); /将指针currPtr移动到序号为pos的节点, /prevPtr相应移动,position记录当前节点的序号 void Next(void); /使prevPtr和currPtr移动到下一个节点 int EndOfList(void) const; / currPtr等于NULL时返回TRUE, 否则返回FALSE int CurrentPosition(void) const; /返回数据成员position void InsertFront(const T& item); /在表头插入一个数据域为item的节点 void InsertRear(const T& item); /在表尾添加一个数据域为item的节点 void InsertAt(const T& item); /在当前节点之前插入一个数据域为item的节点 void InsertAfter(const T& item); /在当前节点之后插入一个数据域为item的节点 T DeleteFront(void); /删除头节点,释放节点空间,更新prevPtr、currPtr和size void DeleteAt(void); /删除当前节点,释放节点空间,更新prevPtr、currPtr和size T& Data(void); / 返回对当前节点成员data的引用 void ClearList(void); / 清空链表:释放所有节点的内存空间。;/类实现部分略.template <class T>void MergeList(LinkedList<T>* la, LinkedList<T>* lb,LinkedList<T>* lc)/合并链表la和lb,构成新链表lc。/函数结束后,程序的数据所占内存空间总数不因此函数的运行而增加。 while ( !la->ListEmpty() &&!lb->ListEmpty() if (la->Data()<=lb->Data() lc->InsertRear(la->Data(); la->DeleteAt(); else lc->InsertRear(lb->Data(); lb->DeleteAt(); while ( !la->ListEmpty() ) lc->InsertRear(la->Data(); la->DeleteAt(); while ( !lb->ListEmpty() ) lc->InsertRear(lb->Data(); lb->DeleteAt();int main() LinkedList<int> la, lb, lc; int item, i;/读如数据建立链表la for (i=0;i < 10;i+) cin>>item; la.InsertRear(item); la.Reset();/读如数据建立链表lb for (i=0;i < 10;i+) cin>>item; lb.InsertRear(item); lb.Reset();MergeList(&la, &lb, &lc);/合并链表 lc.Reset();/ 输出各节点数据,直到链表尾 while(!lc.EndOfList() cout <<lc.Data() << " " lc.Next(); / 使currPtr指向下一个节点 cout << endl;"If we don't do that it will go on and go on. We have to stop it; we need the courage to do it."His comments came hours after Fifa vice-president Jeffrey Webb - also in London for the FA's celebrations - said he wanted to meet Ivory Coast international Toure to discuss his complaint.CSKA general director Roman Babaev says the matter has been "exaggerated" by the Ivorian 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 the spirit of football and against the visiting team. It is all nonsense."We can do something better to fight racism and discrimination."This is one of the villains we have today in our game. But it is only with harsh sanctions that racism and discrimination can be washed out of football."The (lack of) air up there Watch mCayman Islands-based Webb, the head of Fifa's anti-racism taskforce, is in London for the Football Association's 150th anniversary celebrations and will attend City's Premier League match at Chelsea on Sunday."I am going to be at the match tomorrow and I have asked to meet Yaya Toure," he told BBC Sport."For me it's about how he felt and I would like to speak to him first to find out what his experience was."Uefa has opened disciplinary proceedings against CSKA for the "racist behaviour of their fans" during City's 2-1 win.Michel Platini, president of European football's governing body, has also ordered an immediate investigation into the referee's actions.CSKA said they were "surprised and disappointed" by Toure's complaint. In a statement the Russian side added: "We found no racist insults from fans of CSKA."Baumgartner the disappointing news: Mission aborted.The supersonic descent could happen as early as Sunda.The weather plays an important role in this mission. Starting at the ground, conditions have to be very calm - winds less than 2 mph, with no precipitation or humidity and limited cloud cover. The balloon, with capsule 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 airliners (5.6 miles/9.17 kilometers) and into the stratosphere. As he crosses the boundary layer (called the tropopause),e can expect a lot of turbulence.The balloon will slowly drift to the edge of space at 120,000 feet ( Then, I would assume, he will slowly step out onto something resembling an Olympic diving platform.Below, the Earth becomes the concrete bottom of a swimming pool that he wants to land on, but not too hard. Still, he'll be traveling fast, so despite the distance, 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 jumpWhen he jumps, he is expected to reach the speed of sound - 690 mph (1,110 kph) - in less than 40 seconds. Like hitting the top of the water, he will begin to slow as he approaches the more dense air closer to Earth. But this will not be enough to stop him completely.If he goes too fast or spins out of control, he has a stabilization parachute that can be deployed to slow him down. His team hopes it's not needed. Instead, he plans 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 have to slow to 172 mph (277 kph). He will have a reserve parachute that will open automatically if he loses consciousness at mach speeds.Even if everything goes as planned, it won't. Baumgartner still will free fall at a speed that would cause you and me to pass out, and no parachute is guaranteed to work higher than 25,000 feet (7,620 meters).cause there

    注意事项

    本文(电大C++语言程序设计期末考试试题及答案小抄参考.doc)为本站会员(仙人指路1688)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开