![東南大學(xué)08級C++試卷B(電類第一場)機(jī)試試卷-和答案解析_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-4/10/8a910d54-d360-47bf-bfc9-b67c714a35e5/8a910d54-d360-47bf-bfc9-b67c714a35e51.gif)
![東南大學(xué)08級C++試卷B(電類第一場)機(jī)試試卷-和答案解析_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-4/10/8a910d54-d360-47bf-bfc9-b67c714a35e5/8a910d54-d360-47bf-bfc9-b67c714a35e52.gif)
![東南大學(xué)08級C++試卷B(電類第一場)機(jī)試試卷-和答案解析_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-4/10/8a910d54-d360-47bf-bfc9-b67c714a35e5/8a910d54-d360-47bf-bfc9-b67c714a35e53.gif)
![東南大學(xué)08級C++試卷B(電類第一場)機(jī)試試卷-和答案解析_第4頁](http://file3.renrendoc.com/fileroot_temp3/2022-4/10/8a910d54-d360-47bf-bfc9-b67c714a35e5/8a910d54-d360-47bf-bfc9-b67c714a35e54.gif)
![東南大學(xué)08級C++試卷B(電類第一場)機(jī)試試卷-和答案解析_第5頁](http://file3.renrendoc.com/fileroot_temp3/2022-4/10/8a910d54-d360-47bf-bfc9-b67c714a35e5/8a910d54-d360-47bf-bfc9-b67c714a35e55.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上東南大學(xué)08級C+(下)上機(jī)試卷B(考試時間80分鐘,卷面成績100分)學(xué)號 姓名 機(jī)位號 說明:首先在Z盤建立一個以自己的學(xué)號命名的文件夾,用于存放上交的*.CPP文件,考試結(jié)束前根據(jù)機(jī)房要求,將這個文件夾傳送到網(wǎng)絡(luò)服務(wù)器上,注意:提交時只保留文件夾中的CPP文件。一、改錯題 (50分)【要求】調(diào)試程序,修改其中的語法錯誤及少量邏輯錯誤。只能修改、不能增加或刪除整條語句,但可增加少量說明語句和編譯預(yù)處理指令?!咀⒁狻吭闯绦蛞浴皩W(xué)號f1.cpp”命名,存入自己學(xué)號文件夾?!绢}目】以下程序?qū)崿F(xiàn)了冒泡排序算法。 【含錯誤的源程序】/*冒泡排序*/錯誤1using name
2、space std /錯誤2void BubbleSort(int slist,int n) /錯誤3bool noswap;int i,j;int temp;for (i=0;i<n;i+) /錯誤4noswap=true; /未交換標(biāo)志為真for(j=n-1;j>i;j-) /從下往上冒泡if(slistj<slistj-1)temp=slistj;slistj=slistj-1;slistj-1=temp;noswap=false;if(!noswap) break; /本趟無交換,則終止算法。/錯誤5int main()int h=10; /錯誤6int i;int
3、listh=5,8,7,9,6,12,11,15,3,10;cout>>"未排序數(shù)組:"<<endl; /錯誤7for(i=0;i<h;i+) cout<<listi<<'t' /錯誤8BubbleSort(list,h);cout<<"已排序數(shù)組:"<<endl();/錯誤9for(i=0;i<h;i+) cout<<listi<<'t' /錯誤10return 0;二、編程題(50分) 【注意】源程序以“學(xué)號f2
4、.cpp”命名,存入自己學(xué)號文件夾。【題目】創(chuàng)建類inventory,該類的定義如下,在創(chuàng)建inventory對象時,會調(diào)用默認(rèn)的構(gòu)造函數(shù)inventory()從“mydatafile.txt”文件中讀取數(shù)據(jù)來初始化類的成員;在撤消inventory對象時,會調(diào)用默認(rèn)的析構(gòu)函數(shù)inventory()將類的成員保存至工程目錄下“mydatafile.txt”文件中。 請完成該類的構(gòu)造函數(shù)、析構(gòu)函數(shù)以及SetParam()函數(shù)的定義。并用main主函數(shù)來驗(yàn)證該類的上述功能?!咀⒁狻?將源程序以文件名“學(xué)號f2.cpp”存入Z盤自己的文件夾中。class inventorystring Descri
5、ption;string No;int Quantity;double Cost;double Retail;fstream datafile;Public:inventory(); /從文件中讀取數(shù)據(jù)進(jìn)行初始化inventory();/數(shù)據(jù)保存到文件中void SetParam(string ,string,int,double,double);/為類的成員數(shù)據(jù)賦值;inventory:inventory()/此處添加代碼inventory:inventory()/此處添加代碼void inventory:SetParam(string description ,string number,
6、int quantity, double cost,double retail)/完成成員函數(shù)SetParam()定義,實(shí)現(xiàn)為類的成員數(shù)據(jù)賦值 用于測試的main函數(shù)如下:int main()inventory goods;goods.SetParam("家電","10",100,2000,3500);return 0;【提醒】上傳的學(xué)號文件夾中只需包含f1.cpp、f2.cpp及mydatafile.txt三個文件即可,其余文件上傳前盡可刪除。答案解析:一 改錯題#include<iostream>using namespace std ;
7、void BubbleSort(int slist,int n) bool noswap;int i,j;int temp;for (i=0;i<n;i+) noswap=true; /未交換標(biāo)志為真for(j=n-1;j>i;j-) /從下往上冒泡if(slistj<slistj-1)temp=slistj;slistj=slistj-1;slistj-1=temp;noswap=false;if(noswap) break; /本趟無交換,則終止算法。/錯誤5int main()const int h=10; int i;int listh=5,8,7,9,6,12,11
8、,15,3,10;cout<<"未排序數(shù)組:"<<endl; for(i=0;i<h;i+) cout<<listi<<'t' BubbleSort(list,h);cout<<"已排序數(shù)組:"<<endl;for(i=0;i<h;i+) cout<<listi<<'t' return 0;二 編程題#include<iostream>#include<fstream>#include<
9、iomanip>using namespace std;class inventorystring Description;string No;int Quantity;double Cost;double Retail;fstream datafile;public:inventory(); /從文件中讀取數(shù)據(jù)進(jìn)行初始化inventory();/數(shù)據(jù)保存到文件中void SetParam(string ,string,int,double,double);/為類的成員數(shù)據(jù)賦值;inventory:inventory()fstream datafile("d:mydatafil
10、e.txt",ios:in);if(!datafile=0)string description;string no;int quantity;double cost;double retail;while(!datafile.eof()datafile>>description;datafile>>no;datafile>>quantity;datafile>>cost;datafile>>retail;Description=description;No=no;Quantity=quantity;Cost=cost;Re
11、tail=retail;inventory:inventory()fstream datafile("d:mydatafile.txt",ios:out);datafile<<Description<<setw(3);datafile<<No<<setw(3);datafile<<Quantity<<setw(3);datafile<<Cost<<setw(3);datafile<<Retail<<endl;datafile.close();void inventory:SetParam(string description ,string number,int quantity, double cost,double retail)Description=description;/完成成員函數(shù)SetParam()
溫馨提示
- 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 初一年級學(xué)生學(xué)習(xí)計(jì)劃
- 培訓(xùn)部工作計(jì)劃
- 2025年度建筑工程防水保溫工程承包合同
- 加盟后合同范本
- 產(chǎn)品技術(shù)協(xié)議合同范本
- led燈維修合同范本
- 加盟合同范本英文版
- 農(nóng)村建筑標(biāo)準(zhǔn)合同范本
- 專業(yè)承包樁基工程合同范本
- 工作調(diào)出申請書
- 復(fù)產(chǎn)復(fù)工試題含答案
- 湖南省長沙市2023-2024學(xué)年八年級下學(xué)期入學(xué)考試英語試卷(附答案)
- 部編版語文三年級下冊第六單元大單元整體作業(yè)設(shè)計(jì)
- 售后服務(wù)經(jīng)理的競聘演講
- 臨床醫(yī)技科室年度運(yùn)營發(fā)展報告
- 慢加急性肝衰竭護(hù)理查房課件
- 文件丟失應(yīng)急預(yù)案
- 從建設(shè)和諧社會角度思考治超限載(十)
- 幼兒園小班開學(xué)家長會課件
- 云南華葉投資公司2023年高校畢業(yè)生招聘1人筆試參考題庫(共500題)答案詳解版
- ABB電子時間繼電器CTMVS系列操作與安裝指南
評論
0/150
提交評論