电大开放教育C++语言程序设计期末考试试题及答案小抄参考.doc_第1页
电大开放教育C++语言程序设计期末考试试题及答案小抄参考.doc_第2页
电大开放教育C++语言程序设计期末考试试题及答案小抄参考.doc_第3页
电大开放教育C++语言程序设计期末考试试题及答案小抄参考.doc_第4页
电大开放教育C++语言程序设计期末考试试题及答案小抄参考.doc_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

专业好文档C+语言程序设计 期末考试试题及答案姓名 _ 学号 _ 班号 _ 题 号一二(1)二(2)三总 分成 绩一、填空1在类中必须声明成员函数的 原型 ,成员函数的 实现 部分可以写在类外。2如果需要在被调函数运行期间,改变主调函数中实参变量的值,则函数的形参应该是 引用 类型或 指针 类型。3 抽象 类只能作为基类使用,而不能声明它的对象。4进行函数重载时,被重载的同名函数如果都没有用const修饰,则它们的形参 个数 或 类型 必须不同。5通过一个 常 对象只能调用它的常成员函数,不能调用其他成员函数。6函数的递归调用是指函数直接或间接地调用 自身 。7拷贝构造函数的形参必须是 本类对象的引用 。二、阅读下列程序,写出其运行时的输出结果 如果程序运行时会出现错误,请简要描述错误原因。1请在以下两题中任选一题,该题得分即为本小题得分。如两题都答,则取两题得分之平均值为本小题得分。(1)程序:- 10 -#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: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();运行结果:1Base 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;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); 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;Vector: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; protected: 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 age:7bs 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 #include /类定义部分template class Node private: Node *next; /指向后继节点的指针 public: T data; /数据域 Node (const T& item, Node* ptrnext = NULL); / 构造函数 void InsertAfter(Node *p); /在本节点之后插入一个同类节点p Node *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); / 生成新节点,数据域为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 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 void MergeList(LinkedList* la, LinkedList* lb,LinkedList* lc)/合并链表la和lb,构成新链表lc。/函数结束后,程序的数据所占内存空间总数不因此函数的运行而增加。 while ( !la-ListEmpty() &!lb-ListEmpty() 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 (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年中央电大期末复习考试小抄大全,电大期末考试必备小抄,电大考试必过小抄Basketball 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 tournament 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 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 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 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 height 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.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 considerable 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 International 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 required 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 asking 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 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 allotted 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 size 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 enthusiasts 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 immediately. 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) larger 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 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 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 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. 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 championships 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 were 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 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 international 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 two joined to form the National Basketball Association (NBA) in 1949. A rival American Basketball Association (ABA) was inaugurated in 1967 and challenged the NBA for college talent and market share for almost ten years. In 1976, this league disbanded, but four of its teams remained as NBA teams. Unification came just in time for major television support. Several womens professional leagues were attempted and failed, including the Womens Professional Basketball League (WBL) and the Womens World Basketball Association, before the WNBA debuted in 1997 with the support of the NBA. James Naismith, originally from Al-monte, Ontario, invented basketball at the International YMCA Training School in Springfield, Massachusetts, in 1891. The game was first played with peach baskets (hence the name) and a soccer ball and was intended to provide indoor exercise for football players. As a result, it was originally a rough sport. Although ten of Naismiths original thirteen rules remain, the game soon changed considerably, and the founder had little to do with its evolution. The first intercollegiate game was played in Minnesota in 1895, with nine players to a side and a final score of nine to three. A year later, the first five-man teams played at the University of Chicago. Baskets were now constructed of twine nets but it was not until 1906 that the bottom of the nets were open. In 1897, the dribble was first used, field goals became two points, foul shots one point, and the first professional game was played. A year later, the first professional league was started, in the East, while in 1900, the first intercollegiate league began. In 1910, in order to limit rough play, it was agreed that four fouls would disqualify players, and glass backboards were used for the first time. Nonetheless, many rules still differed, depending upon where the games were played and whether professionals, collegians, or YMCA players were involved. College basketball was played from Texas to Wisconsin and throughout the East through the 1920s, but most teams played only in their own regions, which prevented a national game or audience from developing. Professional basketball was played almost exclusively in the East before the 1920s, except when a team would barnstorm into the Midwest to play local teams, often after a league had folded. Before the 1930s very few games, either professional or amateur, were played in facilities suitable for basketball or with a perfectly round ball. Some were played in arenas with chicken wire separating the players from fans, thus the word cagers, others with posts in the middle of the floor and often with balconies overhanging the corners, limiting the areas from which shots could be taken. Until the late 1930s, all players used the two-hand set shot, and scores remained low. Basketball in the 1920s and 1930s became both more organized and more popular, although it still lagged far behind both baseball and college football. In the pros, five urban, ethnic teams excelled and played with almost no college graduates. They were the New York Original Celtics; the Cleveland Rosenblums, owned by Max Rosenblum; Eddie Gottliebs Philadelphia SP

温馨提示

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

评论

0/150

提交评论