2014年电大《C++语言程序设计》期末考试试题及答案参考

上传人:细*** 文档编号:1169851 上传时间:2017-06-01 格式:DOC 页数:11 大小:24.20KB
返回 下载 相关 举报
2014年电大《C++语言程序设计》期末考试试题及答案参考_第1页
第1页 / 共11页
2014年电大《C++语言程序设计》期末考试试题及答案参考_第2页
第2页 / 共11页
2014年电大《C++语言程序设计》期末考试试题及答案参考_第3页
第3页 / 共11页
2014年电大《C++语言程序设计》期末考试试题及答案参考_第4页
第4页 / 共11页
2014年电大《C++语言程序设计》期末考试试题及答案参考_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《2014年电大《C++语言程序设计》期末考试试题及答案参考》由会员分享,可在线阅读,更多相关《2014年电大《C++语言程序设计》期末考试试题及答案参考(11页珍藏版)》请在金锄头文库上搜索。

1、文档下载 免费文档下载http:/ 年电大C+语言程序设计期末考试试题及答案小抄参考C 语言程序设计 期末考试试题及答案姓名 _ 学号 _ 班号 _一、填空 1在类中必须声明成员函数的,成员函数的 2如果需要在被调函数运行期间,改变主调函数中实参变量的值,则函数的形参应该是 引用 类型或 指针 类型。34进行函数重载时,被重载的同名函数如果都没有用 const 修饰,则它们的形参数 或 类型 必须不同。5通过一个 6函数的递归调用是指函数直接或间接地调用。 7拷贝构造函数的形参必须是二、阅读下列程序,写出其运行时的输出结果如果程序运行时会出现错误,请简要描述错误原因。文档下载 免费文档下载ht

2、tp:/ (1)程序:1#include #include class Base private: char msg30; protected: int n; public:Base(char s,int m=0):n(m) strcpy(msg,s); void output(void)coutclass Derived1:public Base private: int n; public:Derived1(int m=1):Base(Base,m-1)n=m; void output(void)coutclass Derived2:public Derived1 private: int

3、 n; public:Derived2(int m=2):文档下载 免费文档下载http:/ void output(void) coutint main() Base B(Base Class,1); Derived2 D; B.output(); D.output(); (2)程序:#include class Samp public:void Setij(int a,int b)i=a,j=b; Samp() int GetMuti()return i*j;coutprotected: ;int main() int i; int j;2文档下载 免费文档下载http:/ *p; p=n

4、ew Samp5; if(!p) for(int j=0;jcoutpj.Setij(j,j);coutfor(int k=0;kdeletep; return 0;2请在以下两题中任选一题,该题得分即为本小题得分。如两题都答,则取两题得分之平均值为本小题得分。 (1)程序:#include #include class Vector public:文档下载 免费文档下载http:/ s=100); int& Elem(int ndx); void Display(void); void Set(void); Vector(void); protected: int size; int *bu

5、ffer; ;Vector:Vecthttp:/ s) buffer=new intsize=s; int& Vector:Elem(int ndx) if(ndx=size) coutreturn bufferndx; void Vector:Display(void) for(int j=0; jcout3void Vector:Set(void) for(int j=0; j文档下载 免费文档下载http:/ delete buffer; Elem(j)=j 1;int main() Vector a(10); Vector b(a); a.Set(); b.Display(); (2)

6、程序:#include class CAT public:CAT();CAT(const &CAT); CAT();int GetAge() return *itsAge; void SetAge( int age ) *itsAge=age; protected: ;int * itsAge;文档下载 免费文档下载http:/ CAT:CAT() int main() delete itsAge; itsAge=NULL; itsAge=new int; *itsAge=5;4CAT a;coutcout:/ 10 个整数,整数间以空白符分隔。用这两个序列分别构造两个单链表,每个链表有 10

7、 个结点,结点的数据分别按由小到大次序排列。然后将两个链表合成为一个新的链表,新链表的结点数据仍然按由小到大次序排列。最后按次序输出合并后新链表各结点的数据。程序运行结果如下,带下划线部分表示输入内容,其余是输出内容:文档下载 免费文档下载http:/ 3 5 7 9 11 13 15 17 19 2 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 Node private:Node *next; /指向后继节点的指针

8、public:T data; /数据域Node (const T& item, Node* ptrnext = NULL); / 构造函数 void InsertAfter(Node *p); /在本节点之后插入一个同类节点 p Node *DeleteAfter(void); /删除本节点的后继节点,返回其地址 Node *NextNode(void) const; / 获取后继节点的地址 ;5template class LinkedList private:Node *front, *rear; / 表头和表尾指针文档下载 免费文档下载http:/ *prevPtr, *currPtrh

9、ttp:/ /记录表当前遍历位置的指针,由插入和删除操作更新 int size; / 表中的元素个数int position; / 当前元素在表中的位置序号。由函数 Reset 使用 Node *GetNode(const T& item,Node *ptrNext=NULL);/ 生成新节点,数据域为 item,指针域为 ptrNext void FreeNode(Node *p); /释放节点void CopyList(const LinkedList& L); / 将链表 L 拷贝到当前表/(假设当前表为空) 。被拷贝构造函数、operator=调用 public:LinkedList(

10、void); / 构造函数LinkedList(const LinkedList& L); /拷贝构造函数 LinkedList(void); / 析构函数LinkedList& operator= (const LinkedList& L);/重载赋值运算符 int ListSize(void) const; /返回链表中元素个数( size) int ListEmpty(void) const; /size 为 0 时返回 TRUE,否则返回 FALSE void Reset(int pos = 0); /将指针 currPtr 移动到序号为 pos 的节点, /prevPtr相应移动,p

11、osition 记录当前节点的序号 void Next(void); /使 prevPtr 和currPtr 移动到下一个节点int EndOfList(void) const; / currPtr 等于 NULL 时返回 TRUE, 否则返回 FALSE int CurrentPosition(void) const; /返回数据成员posithttp:/ 免费文档下载http:/ InsertFront(const T& item); /在表头插入一个数据域为 item 的节点 void InsertRear(const T& item); /在表尾添加一个数据域为 item 的节点 vo

12、id 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 void MergeList(LinkedList* la, LinkedList* lb,LinkedList* lc) - 6 -/合并链表 la 和 lb,构成新链表 l

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 资格认证/考试 > 自考

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