2008年級上機考試試卷bc下答案_第1頁
2008年級上機考試試卷bc下答案_第2頁
2008年級上機考試試卷bc下答案_第3頁
2008年級上機考試試卷bc下答案_第4頁
2008年級上機考試試卷bc下答案_第5頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)

文檔簡介

1、參考信息學(xué)院 08 年級計算機科學(xué)基礎(chǔ) II 上機試卷 B時間 70 分鐘卷面成績 100 分)(學(xué)號 機位號說明:首先在 Z 盤建立一個以自己的學(xué)號命名的文件夾,用于存放上交的*.CPP 文件,結(jié)束前根據(jù)機房要求,將這個文件夾傳送到網(wǎng)絡(luò)服務(wù)器上,注意:提交時只保留文件夾中的 CPP 文件。一、改錯題 (50 分)【要求】調(diào)試程序,修改其中的語法錯誤及少量邏輯錯誤。只能修改、不能增加或刪除整條語句,但可增加少量說明語句和編譯預(yù)處理指令?!咀⒁狻吭闯绦蛞浴皩W(xué)號 f1.cpp”命名,存入自己學(xué)【題目】以下程序?qū)崿F(xiàn)動態(tài)生成數(shù)據(jù)成員,析構(gòu)函數(shù)用來夾。動態(tài)分配的內(nèi)存,構(gòu)造函數(shù)和賦值操作操作符實現(xiàn)深?!竞?/p>

2、錯誤的源程序】#include #include using namespatd; class studentchar *pName; public:student( );student( char *pname, student( student &s );student( );len ); /錯 1,該句改為:student( char *pname );student & operator = ( student &s );/錯 2,該句改為: ;student:student( )cout Constructor; pName = NULL;cout 默認(rèn) endl;/錯 3,該句改為

3、:cout Constructor;student:student( char *pname )cout Constructor;pName = new charstrlen(pname)+1; if ( pName ) strcpy( pName, pname ); cout pName endl;student:student( student s )/錯 4,該句改為:student:student( student &s )coutCopy Constructor; if( s.pName )len = strlen(s.pName);pName = new char(len+1);/

4、錯 5,該句改為:pName = new charlen+1;if ( pName ) strcpy( pName, s.pName ); cout pName endl;else pName = NULL;student:student()cout Destructor;if ( pName ) cout pName endl;delete PName;/錯 6,該句改為: delete PName;student & Student:operator = ( student &s )/錯 7,上一行改為:student & student:operator = ( student &s )

5、cout Copy Assign operator; delete pName;if(s.pName)len = strlen(s.pName); pName = new charlen;/錯 8,該句改為:len = strlen(s.pName);/錯 9,該句改為:pName = new charlen+1;if( pName ) strcpy( pName, s.pName ); cout pName endl;else pNa return *this;LL;main(void)student s1(范英明), s2( student s3(s1););student *s4 = n

6、ew student(s2);delete s3; return 0;/錯 10,該句改為:改為 delete s4;二、編程題(50 分)【注意】源程序以“學(xué)號 f2.cpp”命名,存入自己學(xué)【題目】夾。給產(chǎn)品銷售價定價,請編寫產(chǎn)品類 Product。確定產(chǎn)品的銷售價的公式為:產(chǎn)品銷售價 = 原材料價格*1.5 + 加工費*2.0要求:類 Product 的數(shù)據(jù)成員包括ProductName(表示產(chǎn)品名稱,為字符串型)、MatName(表示原材料名,為字符串型)、MatPrice0(表示原材料進價,為整型)、ServicePrice(表示加工費,為整型)、SalePrice(表示商品銷售價,

7、為整型)。類 Product 的構(gòu)造函數(shù)實現(xiàn)從文本文件 Product.txt 中類 Product 的成員函數(shù) CalSalePrice()計算產(chǎn)品的產(chǎn)品名稱、原材料名、原材料進價和加工費。類 Product 的析構(gòu)函數(shù)將完整的產(chǎn)品信息寫入文本文件 Output.txt。寫入的信息包括產(chǎn)品名稱、原材料名稱、原材料價格、加工費、產(chǎn)品銷售價?!咀⒁狻?將源程序以文件名“學(xué)號 f2.cpp”存入 Z 盤自己的文件夾中。class Productstring ProductName; string MatName;/產(chǎn)品名稱/ 原材料名稱原材料進價/加工費/最終定價MatPrice0; Servic

8、ePrice; SalePrice;/public:Product();Product();void CalSalePrice();Product:Product()/類Product的構(gòu)造函數(shù)實現(xiàn)從文本文件Product.txt中/以下需要代碼:Product:Product()產(chǎn)品名稱、原材料名稱、原材料進價、加工費。/類Product的析構(gòu)函數(shù)將完整的產(chǎn)品信息寫入文本文件Output.txt/以下需要代碼:void Product:CalSalePrice()/類Product的成員函數(shù)CalSalePrice()計算產(chǎn)品的/以下需要代碼:/用于測試的 main 函數(shù)如下:main()P

9、roduct pro; pro.CalSalePrice(); return 0;/*調(diào)試程序時可先建立數(shù)據(jù)文件 Product.txt, 內(nèi)容為:椅子木頭。2050這樣程序運行后產(chǎn)生數(shù)據(jù)文件Output.txt,內(nèi)容將為:產(chǎn)品名稱:椅子原材料名稱:木頭原材料進價:20加工費:50最終定價:130*/夾中只需包含 f1.cpp、f2.cpp 及 Output.txt 三個文件即可,其余文件上傳前盡可刪除?!咎嵝选可蟼鞯膶W(xué)【參考】#include #include #includeusing namespa class Producttd;string ProductName; string M

10、atName;/產(chǎn)品名稱/ 原材料名稱原材料進價/加工費/最終定價MatPrice0; ServicePrice; SalePrice;/public:Product();Product();void CalSalePrice();Product:Product()/類Product的構(gòu)造函數(shù)實現(xiàn)從文本文件Product.txt中/以下紅顏色的為添加的代碼 ifstream infile(Product.txt);if(!infile)cout打開失敗!ProductName;infileMatName; infileMatPrice0; infileServicePrice; infile.

11、close();Product:Product()產(chǎn)品名稱、原材料名稱、原材料進價、加工費。/類Product的析構(gòu)函數(shù)將完整的產(chǎn)品信息寫入文本文件Output.txt/以下紅顏色的為添加的代碼 ofstream outf(Output.txt);if(!outf)cout打開失??!endl;return; outf產(chǎn)品名稱:ProductNameendl; outf原材料名稱:MatNameendl; outf原材料進價:MatPrice0endl; outf加工費:ServicePriceendl; outf最終定價:SalePriceendl; outf.close();void Prod

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論