最新电大开放教育C语言程序设计期末考试试题及答案小抄参考.doc

上传人:来看看 文档编号:5023526 上传时间:2020-01-29 格式:DOC 页数:12 大小:89.50KB
返回 下载 相关 举报
最新电大开放教育C语言程序设计期末考试试题及答案小抄参考.doc_第1页
第1页 / 共12页
最新电大开放教育C语言程序设计期末考试试题及答案小抄参考.doc_第2页
第2页 / 共12页
最新电大开放教育C语言程序设计期末考试试题及答案小抄参考.doc_第3页
第3页 / 共12页
最新电大开放教育C语言程序设计期末考试试题及答案小抄参考.doc_第4页
第4页 / 共12页
最新电大开放教育C语言程序设计期末考试试题及答案小抄参考.doc_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《最新电大开放教育C语言程序设计期末考试试题及答案小抄参考.doc》由会员分享,可在线阅读,更多相关《最新电大开放教育C语言程序设计期末考试试题及答案小抄参考.doc(12页珍藏版)》请在三一文库上搜索。

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

2、类对象的引用 。二、阅读下列程序,写出其运行时的输出结果 如果程序运行时会出现错误,请简要描述错误原因。1请在以下两题中任选一题,该题得分即为本小题得分。如两题都答,则取两题得分之平均值为本小题得分。(1)程序:- 15 -#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) coutnendlmsgendl; ;class Derived1:public Baseprivate:

3、int n;public:Derived1(int m=1):Base(Base,m-1) n=m; void output(void) coutnendl; Base:output();class Derived2:public Derived1private:int n;public:Derived2(int m=2):Derived1(m-1) n=m; void output(void) coutnendl; Derived1:output();int main()Base B(Base Class,1);Derived2 D;B.output();D.output();运行结果:1B

4、ase Class210Base(2)程序:#include class Samppublic:void Setij(int a,int b)i=a,j=b;Samp()coutDestroying.iendl;int GetMuti()return i*j; protected:int i;int j;int main()Samp *p;p=new Samp5;if(!p)coutAllocation errorn;return 1;for(int j=0;j5;j+)pj.Setij(j,j);for(int k=0;k5;k+)coutMutik is: pk.GetMuti()endl

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

6、; Vector(void); protected: int size; int *buffer;Vector:Vector(int s)buffer=new intsize=s;int& Vector:Elem(int ndx)if(ndx=size)couterror in indexendl;exit(1);return bufferndx;void Vector:Display(void)for(int j=0; jsize; j+)coutElem(j)endl;void Vector:Set(void)for(int j=0; jsize; j+)Elem(j)=j+1;Vecto

7、r:Vector(void)delete buffer;int main()Vector a(10);Vector b(a);a.Set();b.Display();运行结果:12345678910最后出现错误信息,原因是:声明对象b是进行的是浅拷贝,b与a共用同一个buffer,程序结束前调用析构函数时对同一内存区进行了两次释放。(2)程序:#includeclass CAT public: CAT(); CAT(const &CAT); CAT(); int GetAge() return *itsAge; void SetAge( int age ) *itsAge=age; prote

8、cted: int * itsAge;CAT:CAT()itsAge=new int;*itsAge=5;CAT:CAT()delete itsAge;itsAge=NULL;int main()CAT a;coutas age:a.GetAge()endl;a.SetAge(6);CAT b(a);coutas age:a.GetAge()endl;coutbs age:b.GetAge()endl;a.SetAge(7);coutas age:a.GetAge()endl;coutbs age:b.GetAge()endl;运行结果:as age:5as age:6bs age:6as a

9、ge:7bs age:7最后出现错误信息,原因是:声明对象b是进行的是浅拷贝,b与a共用同一个buffer,程序结束前调用析构函数时对同一内存区进行了两次释放。三、阅读下列程序及说明和注释信息,在方框中填写适当的程序段,使程序完成指定的功能 程序功能说明:从键盘读入两个分别按由小到大次序排列的整数序列,每个序列10个整数,整数间以空白符分隔。用这两个序列分别构造两个单链表,每个链表有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 Node private: Node *next; /指向后继节点的指针 public: T data; /数据域 Node (const T& item, Node* ptrnext = NULL); / 构造函数 void InsertAfter(Node *p); /在本节点之后插入一个同类节点p Node

11、*DeleteAfter(void); /删除本节点的后继节点,返回其地址 Node *NextNode(void) const; / 获取后继节点的地址;template class LinkedList private: Node *front, *rear; / 表头和表尾指针 Node *prevPtr, *currPtr; /记录表当前遍历位置的指针,由插入和删除操作更新 int size; / 表中的元素个数 int position; / 当前元素在表中的位置序号。由函数Reset使用 Node *GetNode(const T& item,Node *ptrNext=NULL)

12、; / 生成新节点,数据域为item,指针域为ptrNext void FreeNode(Node *p); /释放节点 void CopyList(const LinkedList& L); / 将链表L 拷贝到当前表 /(假设当前表为空)。被拷贝构造函数、operator=调用 public: LinkedList(void); / 构造函数 LinkedList(const LinkedList& L); /拷贝构造函数 LinkedList(void); / 析构函数 LinkedList& operator= (const LinkedList& L);/重载赋值运算符 int Li

13、stSize(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)

14、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 voi

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

16、() if (la-Data()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 la, lb, lc; int item, i;/读如数据建立链表la for

17、 (i=0;i item; la.InsertRear(item); la.Reset();/读如数据建立链表lb for (i=0;i item; lb.InsertRear(item); lb.Reset();MergeList(&la, &lb, &lc);/合并链表 lc.Reset();/ 输出各节点数据,直到链表尾 while(!lc.EndOfList() cout lc.Data() ; lc.Next(); / 使currPtr指向下一个节点 cout endl;请您删除一下内容,O(_)O谢谢!2016年中央电大期末复习考试小抄大全,电大期末考试必备小抄,电大考试必过小抄B

18、asketball can make a true claim to being the only major sport that is an American invention. From high school to the professional level, basketball attracts a large following for live games as well as television coverage of events like the National Collegiate Athletic Association (NCAA) annual tourn

19、ament and the National Basketball Association (NBA) and Womens National Basketball Association (WNBA) playoffs. And it has also made American heroes out of its player and coach legends like Michael Jordan, Larry Bird, Earvin Magic Johnson, Sheryl Swoopes, and other great players. At the heart of the

20、 game is the playing space and the equipment. The space is a rectangular, indoor court. The principal pieces of equipment are the two elevated baskets, one at each end (in the long direction) of the court, and the basketball itself. The ball is spherical in shape and is inflated. Basket-balls range

21、in size from 28.5-30 in (72-76 cm) in circumference, and in weight from 18-22 oz (510-624 g). For players below the high school level, a smaller ball is used, but the ball in mens games measures 29.5-30 in (75-76 cm) in circumference, and a womens ball is 28.5-29 in (72-74 cm) in circumference. The

22、covering of the ball is leather, rubber, composition, or synthetic, although leather covers only are dictated by rules for college play, unless the teams agree otherwise. Orange is the regulation color. At all levels of play, the home team provides the ball. Inflation of the ball is based on the hei

23、ght of the balls bounce. Inside the covering or casing, a rubber bladder holds air. The ball must be inflated to a pressure sufficient to make it rebound to a height (measured to the top of the ball) of 49-54 in (1.2-1.4 m) when it is dropped on a solid wooden floor from a starting height of 6 ft (1

24、.80 m) measured from the bottom of the ball. The factory must test the balls, and the air pressure that makes the ball legal in keeping with the bounce test is stamped on the ball. During the intensity of high school and college tourneys and the professional playoffs, this inflated sphere commands c

25、onsiderable attention. Basketball is one of few sports with a known date of birth. On December 1, 1891, in Springfield, Massachusetts, James Naismith hung two half-bushel peach baskets at the opposite ends of a gymnasium and out-lined 13 rules based on five principles to his students at the Internat

26、ional Training School of the Young Mens Christian Association (YMCA), which later became Springfield College. Naismith (1861-1939) was a physical education teacher who was seeking a team sport with limited physical contact but a lot of running, jumping, shooting, and the hand-eye coordination requir

27、ed in handling a ball. The peach baskets he hung as goals gave the sport the name of basketball. His students were excited about the game, and Christmas vacation gave them the chance to tell their friends and people at their local YMCAs about the game. The association leaders wrote to Naismith askin

28、g for copies of the rules, and they were published in the Triangle, the school newspaper, on January 15,1892. Naismiths five basic principles center on the ball, which was described as large, light, and handled with the hands. Players could not move the ball by running alone, and none of the players

29、 was restricted against handling the ball. The playing area was also open to all players, but there was to be no physical contact between players; the ball was the objective. To score, the ball had to be shot through a horizontal, elevated goal. The team with the most points at the end of an allotte

30、d time period wins. Early in the history of basketball, the local YMCAs provided the gymnasiums, and membership in the organization grew rapidly. The size of the local gym dictated the number of players; smaller gyms used five players on a side, and the larger gyms allowed seven to nine. The team si

31、ze became generally established as five in 1895, and, in 1897, this was made formal in the rules. The YMCA lost interest in supporting the game because 10-20 basketball players monopolized a gymnasium previously used by many more in a variety of activities. YMCA membership dropped, and basketball en

32、thusiasts played in local halls. This led to the building of basketball gymnasiums at schools and colleges and also to the formation of professional leagues. Although basketball was born in the United States, five of Naismiths original players were Canadians, and the game spread to Canada immediatel

33、y. It was played in France by 1893; England in 1894; Australia, China, and India between 1895 and 1900; and Japan in 1900. From 1891 through 1893, a soccer ball was used to play basketball. The first basketball was manufactured in 1894. It was 32 in (81 cm) in circumference, or about 4 in (10 cm) la

34、rger than a soccer ball. The dedicated basketball was made of laced leather and weighed less than 20 oz (567 g). The first molded ball that eliminated the need for laces was introduced in 1948; its construction and size of 30 in (76 cm) were ruled official in 1949. The rule-setters came from several

35、 groups early in the 1900s. Colleges and universities established their rules committees in 1905, the YMCA and the Amateur Athletic Union (AAU) created a set of rules jointly, state militia groups abided by a shared set of rules, and there were two professional sets of rules. A Joint Rules Committee

36、 for colleges, the AAU, and the YMCA was created in 1915, and, under the name the National Basketball Committee (NBC) made rules for amateur play until 1979. In that year, the National Federation of State High School Associations began governing the sport at the high school level, and the NCAA Rules

37、 Committee assumed rule-making responsibilities for junior colleges, colleges, and the Armed Forces, with a similar committee holding jurisdiction over womens basketball. Until World War II, basketball became increasingly popular in the United States especially at the high school and college levels.

38、 After World War II, its popularity grew around the world. In the 1980s, interest in the game truly exploded because of television exposure. Broadcast of the NCAA Championship Games began in 1963, and, by the 1980s, cable television was carrying regular season college games and even high school cham

39、pionships in some states. Players like Bill Russell, Wilt Chamberlain, and Lew Alcindor (Kareem Abdul-Jabbar) became nationally famous at the college level and carried their fans along in their professional basketball careers. The womens game changed radically in 1971 when separate rules for women w

40、ere modified to more closely resemble the mens game. Television interest followed the women as well with broadcast of NCAA championship tourneys beginning in the early 1980s and the formation of the WNBA in 1997. Internationally, Italy has probably become the leading basketball nation outside of the

41、 United States, with national, corporate, and professional teams. The Olympics boosts basketball internationally and has also spurred the womens game by recognizing it as an Olympic event in 1976. Again, television coverage of the Olympics has been exceptionally important in drawing attention to int

42、ernational teams. The first professional mens basketball league in the United States was the National Basketball League (NBL), which debuted in 1898. Players were paid on a per-game basis, and this league and others were hurt by the poor quality of games and the ever-changing players on a team. After the Great Depression, a new NBL was organized in 1937, and the Basketball Association of America was organized in 1946. The two leagues came to agree that players had to be assigned to teams on a contract basis and that high standards had to govern the game; under these premises, the t

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

当前位置:首页 > 研究报告 > 商业贸易


经营许可证编号:宁ICP备18001539号-1