




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、東南大學09級C+(下)上機試卷B-答案一、改錯題(50分)本題共10個錯誤,每個錯誤5分#include #include using namespace std;class studentchar *pName;public:student();student(char *pname);student(student &s);student();student & operator=(student &s);void print();student:student()/去掉voidcoutConstructor;pName=NULL;cout缺省endl;student:student (
2、 char *pname )coutConstructor;pName = new charstrlen(pname);if ( pName ) strcpy ( pName, pname);/pName與pname互換位置coutpNameendl;student:student(student &s) /改為student &scoutCopy Constructor;if(s.pName)int len = strlen( s.pName );pName = new charlen+1; /len改為len+1if ( pName ) strcpy (pName, s.pName);co
3、utpNameendl;else pName=NULL;student:student()coutDestructor;if ( pName ) coutpNameendl;delete pName; /改為delete pName;student & student:operator = ( student &s ) coutCopy Assign operator;delete pName; if ( s.pName ) pName = new charstrlen(s.pName)+1;if ( pName ) strcpy ( pName, s.pName );coutpNameend
4、l;else pName=NULL;return *this; /改為return *this;void student:print( ) /改為void student:print( )if (pName = NULL ) cout NULL endl; else cout pName print();/改為s3-print();delete s3; return; /去掉0二、編程題(50分)每段代碼10分,共50分。紅字為要求設計的部分。#include #include #include using namespace std;class goods;ostream& operator
5、(istream &is, goods &a);class goodsstringName;/名稱intAmount;/數量floatPrice;/單價public:goods (); goods ();/析構函數,將數據保存到文件中bool IsEmpty() return Name=; ;friend ostream& operator(istream &is, goods &a);goods: goods () ifstream file(goodinfo.data);if ( file ) /文件打開成功file *this;file.close();elseName = ;Amoun
6、t = 0;Price = 0;goods: goods ()ofstream file(goodinfo.data);file *this;file.close();ostream& operator (ostream &os, goods &a)os a.Name endl;os a.Amount endl;os a.Price (istream &is, goods &a)if ( is = cin )cout 請輸入你的以下信息: endl;cout a.Name;cout a.Amount;cout a.Price;elseis a.Name;is a.Amount;is a.Pri
7、ce;return is;void main()goods g;if ( g.IsEmpty() ) cin g;cout endl;cout 顯示商品信息: endl;cout g;if(!datafile) coutproductNamematNamematPrice0servicePrice; ProductName=productName; MatName=matName; MatPrice0=matPrice0; ServicePrice=servicePrice;編程題評分標準: 1. 頭文件引用是否正確 2分 2. 主函數:22分 (1)創建文件流對象與要求的文件相對應數否正確 (2分) (2)是否關閉文件 (2分) (3)變量初始化 (2分) (4)產生a數組是否正確 (8分) (5)將a數組是否按要求寫入文件 (4分) (6)將符合條件的
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 玩具行業新興市場開發考核試卷
- 《肺癌治療研究進展》課件
- 2025年湖南省常德市初中學校教學教研共同體中考二模道德與法治試卷(含答案)
- 題型01 讀圖理解-2025年中考生物二輪復習精講課件
- 彩色無木漿紙市場深度剖析:預計2031年全球市場銷售額將達到1.57億美元
- 行進間發射技術發展方向
- 滲透游泳救生員資格考試中的試題及答案特點
- 體育經紀人職業技能評估試題及答案
- 高效籃球裁判員等級考試試題及答案
- 裁判員如何提升與球員的相處能力試題及答案
- 04S520埋地塑料排水管道施工標準圖集OSOS
- 220KV輸電線路組塔施工方案
- 高中班級讀書活動方案
- 國際經濟學教案doc
- 六年級數學下冊《圖形的運動》
- 2022-2023學年北京海淀人大附數學八年級第二學期期末復習檢測試題含解析
- 高中歷史雙向細目表
- 2022-2023學年北京石景山數學七下期中檢測試題含解析
- 蘇教版四年級下冊數學期中復習
- 常用消毒劑分類及消毒方法演示文稿
- LY/T 3245-2020中國森林認證自然保護地森林康養
評論
0/150
提交評論