




已閱讀5頁,還剩5頁未讀, 繼續(xù)免費閱讀
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
一、編程題。根據程序要求,寫出函數的完整定義。 ( 40 分) 1寫一個函數,找出給定字符串中大寫字母字符(即 A - Z這 26 個字母)的個數(如字符串” China Computer Wrold”中大寫字母字符的個數為 3 個)。 函數的原型: int CalcCapital (char *str); 函數參數: str 為所要處理的字符串; 函數返回值:所給字符串中數字字符的個數 答: int CalcCapital (char *str) if (str = NULL) return 0; /判斷字符指針是否為空 int num_of_Capital = 0; /記錄大寫字母字符個數的變量,初值為 0 for(int i=0; stri != 0x0; i+) if (stri = Z) num_of_ Capital +; /若是大寫字母,則總數加 1 return num_of_ Capital; /返回大寫字母字符數 2寫一個函數,用遞歸函數完成以下運算 : sum(n) = 1 1/2 + 1/3 1/4 + -(1/n)*(-1)n (其中 n0) 函數原型: float sum(int n); 函數參數: n 為正整數。 函數返回值:相應于給定的 n,右邊表達式運算結果。 提示:你可以使用遞歸表達式: sum(n) = sum(n-1) -(1/n)*(-1)n 答: float sum(int n) if (n = 1) return 1; else return sum(n-1) -(1.0/n)*(-1)n; 3. 給定新數值,在一個按節(jié)點所存放數值從大到小排序的鏈表中,找適當位置插一個新節(jié)點,仍保持有序的鏈表,寫一個函數,完成此操作。 函數的原型: Node * InsNode(Node * head, int newValue); 其中,鏈表節(jié)點的定義如下: struct Nodee int Value; /存放數值 Node * next; /指向鏈表中的下一個節(jié)點 ; 函數參數:函數的第一個參數 head 指向鏈表頭一節(jié)點的指針,如果鏈表為 空,則 head 的值為 NULL。第二個參數newValue 為所給定的插入新節(jié)點的新數值。 函數返回值:當成功地插入新的節(jié)點時,函數返回指向新鏈表頭一節(jié)點的指針,否則,若不能申請到內存空間,則返回 NULL。 答: Node * insNode(Node * head, int newValue) Node * newNode = new Node; /申請新的節(jié)點空間 if (newNode = NULL) return NULL;/ newNode-data = newValue; /填充新節(jié)點的內容 newNode-next = NULL; Node *pre, *cur; Pre = head; if (head = NULL) head = newNode; /插入到空鏈表的表頭 else if(newValue=head-Value) newNode-next=head; head = newNode; /插入到鏈表的表頭 else /在鏈 表尋找插入點 Node *cur,*pre = head; while(pre-next != NULL) cur = pre-next; if(newValue = cur-Value) break; else pre = cur; if(pre-next!= NULL) newNode-next = cur;/若非末尾,則有下一節(jié)點 pre-next = newNode; /將新節(jié)點插入 return head; 4寫一個函數,找出給定數組中具有最小值的元素。 函數的原型: char MinCode(char charAry); 函數參數: charAry 所要處理的字符數組名; 函數返回值:返回具有最小 ASCII 碼的字符。 答: char MinCode(char charAry,int len=10) char mixCode = 0x0; for(int i=0; i len; i+) if (charAry i mixCode) mixCode = stri; return mixCode; 二、理解問答題: ( 20 分) 下面的文件 stack.h 是一個堆棧類模板 Stack 的完整實現(xiàn)。在這個文件中,首先定義了一個堆棧元素類模板 StackItem,然后,在這個類的基礎上定義了堆棧類模板 Stack。在 Stack 中使用鏈表存放堆棧的各個元素, top 指針指向鏈表的第一個節(jié)點元素, bottom 指針指向鏈表的最后一個節(jié)點元素,成員函數 push()將一個新節(jié)點元素加入(壓進)到堆棧頂部, pop()從堆棧頂部刪除(彈出)一個節(jié)點元素。為方便起見,程序中加上了行號。閱讀程序,根據程序后面的問題作出相應解答。 1. /*-*/ 2. /* 文件 stack.h */ 3. /*-*/ 4. template 5. class Stack; 6. /* 定義模板類 StackItem */ 7. template 8. class StackItem 9. 10. public: 11. StackItem(const Type & elem):item(elem) 12. StackItem() 13. private: 14. Type item; 15. StackItem * nextItem; 16. friend class Stack; 17. ; 18. /* 定義模板類 Stack */ 19. template 20. class Stack 21. 22. public: 23. Stack():top( NULL), _(A)_ 24. Stack(); 25. Type pop(); 26. void push(const Type &); 27. bool is_empty() const return _(B) _ ; 28. private: 29. StackItem * top; 30. StackItem * bottom; 31. ; 32. /模板類 Stack 的函數成員 pop()的實現(xiàn)。 33. /從堆棧頂彈出一個節(jié)點,并返回該節(jié)點的值 34. template 35. Type Stack:pop() 36. 37. StackItem *ptop; /指向頂部節(jié)點的臨時指針 38. Type retVal; /返回值 39. _(C) _; 40. retVal = top-item; 41. top = top-nextItem; 42. delete ptop; 43. return retVal; 44. 45. /模板類 Stack 的函數成員 push()的實現(xiàn) 46. template 47. void Stack:push(const Type & newItem) 48. 49. StackItem *pNew = new StackItem( newItem); 50. _(D)_; 51. if (bottom = NULL) bottom = top = pNew; 52. else _(E)_; 53. 54. /模板類 Stack 的析構函數 Stack()的實現(xiàn) 55. template 56. Stack:Stack() 57. 58. StackItem *p = top, *q; 59. while(p != NULL) 60. q = p-nextItem; 61. delete p; 62. p = q; 63. 64. 問題 1: 程序中有幾處填空,將它們完成。 ( A) bottom (NULL) ( B) top = NULL; ( C) ptop = top; ( D) pNew-nextItem = top; ( E) top = pNew; 問題 2:程序第 4, 5 行有什么作用?如果沒有這兩行語句,程序還正確嗎? 答: 不正確。因為類 StackItem 模板類的定義中用到了模板類 Stack, Stack 還沒有定義,所以,必須先聲明 Stack 是一個模板類,否則 ,編譯程序就不知道標識符 Stack 代表什么樣的含義,無法進行編譯。 問題 3:程序中多處出現(xiàn) const,請分別說明它們各自表示什么含義。 答:第 11、 26 和 47 行的 const 修飾的都是函數的參數,表示在這個函數體中不能改它所修飾的參數的值。第 27 行的 const修飾的是模板類 Stack 的成員函數 is_empty(),它表示在函數 is_empty()的函數體中不能改變任何數據成員的值。 問題 4:程序中模板類 Stack 的析構函數主要做了什么事情?為什么要這么做? 答: 析構函數中主要是釋放存放的各個節(jié)點所 占涌空間。因為 Stack 對象在其生存期間可能加入了很多節(jié)點,從堆中申請了一些內存空間。這些空間應隨著對象的消亡而釋放掉,所以,需要在析構函數中釋放這些空間。 問題 5:下面的程序使用了 stack.h 文件中定義的類模板,請說明下列程序中定義堆棧對象的語句 (1-5)是否正確。 #include “stack.h” void main() Stack q1; / 1 Stack q2; / 2 Stack q3(10); / 3 Stack q410; / 4 Stack *q5 = new Stack; / 5 /. delete q5; 答: 語句號 1 2 3 4 5 對 /錯 錯 對 錯 錯 對 三、 填空題 ( 20 分 ) 下面是一個求數組元素之和的程序。主程序中定義了并初始化了一個數組,然后計算該數組各元素的和,并輸出結果。函數 sum 計算數組元素之和。填充程序中不完整的部分。 _a_. int sum(int ,int); void main() int ia5 = 2,3,6,8,10; b ; sumofarray = sum(ia,5); cout sum of array: sumofarray endl; int sum(int array,int len) int isum = 0; for(int i = 0; c ; d ) e ; return isum; A:#include B: int sumofarray=0; C:ilen D:i+ E:iSum+=arrayi 四、 綜合編程題 ( 20 分) 定義一個日期類 date,該類對象存放一個日期,可以提供的操作有: int getyear ();/取年份 int getmonth ();/取月份 int getday ();/取日子值 void setdate (int year, int month, int day);/設置日期值 下面是測試你所定義的日期類程序: #include #include “date.h” void main() date d1(1999, 1, 14);/用所給日期定一個日期變量 date d2; /定義一個具有缺省值為 1980 年 1 月 1 日的日期 , date d3(d1);/用已有日期 x 構造一個新對象 d2.setdate(1999,3,13); cout date:; cout d1.getyear() . d1.getmonth() . d1.getday() endl; cout date:; cout d2.getyear() . d2.getmonth() . d2.getday() endl; cout date:; cout d3.getyear() . d3.getmonth() . d3.getday() endl; 寫出日期類的完整定義,其 ,三個 get 函數寫成內聯(lián)函數形式 ,setdate 寫成非內聯(lián)函數形式。所有數據成員都定義為私有成員。注意構造函數的三種形式。 寫出程序的運行結果。 修改程序,在日期類中定義日期的輸出函數,這樣,主程序就可以簡化。輸出格式和上面一樣。只需要寫出類date 的修改部分。 簡化后主程序如下: void main() date d1(1999, 1, 14); date d2; date d3(d1); d2.setdate(1999,3,13); d1.print(); d2.print(); d3.print(); 答: class Date private:int year,month,day; public:Data(int yr,int mth,int dy):year(yr),month(mth),day(dy); Date():year(1980),month(1),day(1); Date(date&d1):year(d1.year),month(d1.month),day(d1.day); int GetYear()return year; int GetMonth()return month; int GetDay()return day; void SetDate(int yr,int mth,int dy); ; void Date:SetDate(int yr,int mth,int dy) year=yr; month=mth; day = dy; 程序運行結果 Date:1999.1.14 Date:1999.3.13 Date:1999.1.14 修改部分: class Date public:void Print(); void Date:Print()cout”Date”;coutyear.month.dayendl; 面向對象程序設計 大作業(yè) 班級 : 學號: 姓名: 請您刪除一下內容, O( _ )O 謝謝! 2015 年中央電大期末復習考試小抄大全,電大期末考試必備小抄,電大考試必過小抄 After earning his spurs in the kitchens of The Westin, The Sheraton, Sens on the Bund, and a sprinkling of other top-notch venues, Simpson Lu fi nally got the chance to become his own boss in November 2010. Sort of. The Shanghai-born chef might not actually own California Pizza Kitchen (CPK) but he is in sole charge of both kitchen and frontof- house at this Sinan Mansionsstalwart. Its certainly a responsibility to be the head chef, and then to have to manage the rest of the restaurant as well, the 31-year-old tells Enjoy Shanghai. In hotels, for example, these jobs are strictly demarcated, so its a great opportunity to learn how a business operates across the board. It was a task that management back in sunny California evidently felt he was ready for, and a vote of confi dence from a company that, to date, has opened 250 outlets in 11 countries. And for added pressure, the Shanghai branch was also CPKs China debut. For sure it was a big step, and unlike all their other Asia operations that are franchises, they decided to manage it directly to begin with, says Simpson. Two years ago a private franchisee took over the lease, but the links to CPK headquarters are still strong, with a mainland-based brand ambassador on hand to ensure the business adheres to its ethos of creating innovative, hearth-baked pizzas, a slice of PR blurb that Simpson insists lives up to the hype. They are very innovative, he says. The problem with most fast food places is that they use the same sauce on every pizza and just change the toppings. Every one of our 16 pizza sauces is a unique recipe that has been formulated to complement the toppings perfectly. The largely local customer base evidently agrees and on Saturday and Sunday, at least, the place is teeming. The kids-eat-for-free policy at weekends is undoubtedly a big draw, as well as is the spacious second-fl oor layout overlooked by a canopy of green from Fuxing Park over the road. The company is also focusing on increasing brand recognition and in recent years has taken part in outside events such as the regular California Week. Still, the sta are honest enough to admit that business could be better; as good, in fact, as in CPKs second outlet in the popular Kerry Parkside shopping mall in Pudong. Sinan Mansions has really struggled to get the number of visitors that were envisaged when it first opened, and it hasnt been easy for any of the tenants here, adds Simpson. Were planning a third outlet in the city in 2015, and we will probably choose a shopping mall again because of the better foot traffic. The tearooms once frequented by Coco Chanel and Marcel Proust are upping sticks and coming to Shanghai, Xu Junqian visits the Parisian outpost with sweet treats. One thing the century-old Parisian tearoom Angelina has shown is that legendary fashion designer Coco Chanel not only had style and glamor but also boasted great taste in food, pastries in particular. One of the most popular tearooms in Paris, Angelina is famous for having once been frequented by celebrities such as Chanel and writer Marcel Proust. Now Angelina has packed up its French ambience, efficient service, and beautiful, comforting desserts and flown them to Shanghai. At the flagship dine-in and take-out space in Shanghai, everything mimics the original tearoom designed from the beginning of the 20th century, in Paris, the height of Belle Epoque. The paintings on the wall, for example, are exactly the same as the one that depicts the landscape of southern France, the hometown of the owner; and the small tables are intentional imitations of the ones that Coco Chanel once sat at every afternoon for hot chocolate. The famous hot chocolate, known as LAfricain, is a luxurious mixture of four types of cocoa beans imported from Africa, blended in Paris and then shipped to Shanghai. Its sinfully sweet, rich and thick as if putting a bar of melting chocolate directly on the tongue and the fresh whipped cream on the side makes a light, but equally gratifying contrast. It is also sold in glass bottles as takeaway. The signature Mont-Blanc chestnut cake consists of three parts: the pureed chestnut on top, the vanilla cream like stuffing, and the meringue as base. Get all three layers in one scoop, not only for the different textures but also various flavors of sweetness. The dessert has maintained its popularity for a century, even in a country like France, perhaps the worlds most competitive place for desserts. A much overlooked pairing, is the Paris-New York choux pastry and N226 chocolate flavored tea. The choux pastry is a mouthful of airy pecan-flavored whipped cream, while the tea, a blend of black teas from China and Ceylon, cocoa and rose petals, offers a more subtle fragrance of flowers and chocolate. Ordering these two items, featuring a muted sweetness, makes it easier for you to fit into your little black dress. Breakfast, brunch, lunch and light supper are also served at the tearoom, a hub of many cultures and takes in a mix of different styles of French cuisines, according to the management team. The semi-cooked foie gras terrine, is seductive and deceptive. Its generously served at the size and shape of a toast, while the actual brioche toast is baked into a curved slice dipped with fig chutney. The flavor, however, is honest: strong, smooth and sublime. And you dont actually need the toast for crunchiness. This is the season for high teas, with dainty cups of fine china and little pastries that appeal to both visual and physical appetites. But there is one high tea with a difference, and Pauline D. Loh finds out just exactly why it is special. Earl Grey tea and macarons are all very well for the crucial recuperative break in-between intensive bouts of holiday season shopping. And for those who prefer savory to sweet, there is still the selection of classic Chinese snacks called dim sum to satisfy and satiate. High tea is a meal to eat with eye and mouth, an in-between indulgence that should be light enough not to spoil dinner, but sufficiently robust to take the edge off the hunger that strikes hours after lunch. The afternoon tea special at Shang-Xi at the Four Seasons Hotel Pudong has just the right elements. It is a pampering meal, with touches of luxury that make the high tea session a treat in itself. Whole baby abalones are braised and then topped on a shortcrust pastry shell, a sort of Chinese version of the Western vol-au-vent, but classier. Even classier is the dim sum staple shrimp dumpling or hargow, upgraded with the addition of slivers of midnight dark truffles. This is a master touch, and chef Simon Choi, who presides unchallenged at Shang-Xi, has scored a winner again. Sweet prawns and aromatic truffles whats not to love? His masterful craftsmanship is exhibited in yet another pastry a sweet pastry that is shaped to look like a walnut, but which you can put straight into the mouth. It crumbles immediately, and the slightly sweet, nutty morsel is so easy to eat youll probably reach straight for another. My favorite is the dessert that goes by the name yangzhi ganlu, or ambrosia from the gods. The hotel calls it c
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 工地燈具供貨合同協(xié)議
- 私人房水電安裝合同協(xié)議
- 新時代教師思想政治教育體系建設
- 2024年幽門螺桿菌感染基層診療指南講座課件
- 夜場出租轉讓合同協(xié)議
- 培訓普通話課件
- 第二單元寫作《學會記事》課件 2024-2025學年統(tǒng)編版語文七年級上冊
- 小學教育的學校中的法律關系
- 高校創(chuàng)新管理課程
- 智能汽車自動泊車技術解析
- 甘肅省2025年甘肅高三月考試卷(四4月)(甘肅二診)(數學試題+答案)
- 2025年中小學教師資格考試的重要試題及答案
- 微訓練 一文多考 備考高效之詩歌《蘇幕遮?燎沉香》教師版
- 2025屆山東省濟南市一模生物試題(原卷版+解析版)
- 海南地理會考試卷及答案2024
- 全國河大音像版初中信息技術八年級上冊第三章第三節(jié)《循環(huán)結構程序設計》教學設計
- 企業(yè)健康管理計劃規(guī)劃方案討論
- 隧道高空作業(yè)施工方案
- 危險性較大的分部分項工程專項施工方案嚴重缺陷清單(試行)
- 深信服超融合HCI技術白皮書-20230213
- 2025年陜西省土地工程建設集團有限責任公司招聘筆試參考題庫附帶答案詳解
評論
0/150
提交評論