版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、.南昌航空大學(xué)實(shí)驗(yàn)報(bào)告2011年11月16日課程名稱: 面向?qū)ο蟪绦蛟O(shè)計(jì)B 實(shí)驗(yàn)名稱:構(gòu)造函數(shù)班級:102022 姓名:林書晨指導(dǎo)老師評定: 簽名:實(shí)驗(yàn)二 析構(gòu)函數(shù)1. 實(shí)驗(yàn)?zāi)康?通過實(shí)驗(yàn)理解析構(gòu)函數(shù)的概念與其特殊應(yīng)用2. 實(shí)驗(yàn)內(nèi)容 應(yīng)用VC+6.0的編輯環(huán)境構(gòu)造一個(gè)類student,該類主要實(shí)現(xiàn)學(xué)生的基本操作。該學(xué)生類包括學(xué)生姓名 學(xué)生學(xué)號 學(xué)生成績(課程數(shù)目不定,起存儲(chǔ)空間應(yīng)動(dòng)態(tài)申請),實(shí)現(xiàn)對該學(xué)生信息的初始化,求該學(xué)生的總成績,平均成績,最高分與最低分以及最后輸出,具體說明如下: class Studentpublic:Student(char *n,char *s,int num,do
2、uble *s);Student();double GetSum();double GetAver();double GetMax();double GetMin();void Show();private:char *name;/student namechar *stuno;/student noint score_num;/score number Double *score; /student score;3. 概要設(shè)計(jì)a. 析構(gòu)函數(shù) class Studentpublic:Student(char *n,char *s,int num,double *s);Student();dou
3、ble GetSum();double GetAver();double GetMax();double GetMin();void Show();private:char *name;/student namechar *stuno;/student noint score_num;/score number Double *score; /student score;b.實(shí)現(xiàn)功能1. double GetSum() 求總成績 double s=0; for(int i=0; iscore_num; i+) s = s+*(score+i); return s; 2.double GetAv
4、er() 求平均成績 return GetSum()/score_num ; 3.double GetMax() 求最高分?jǐn)?shù) double max=*score; for(int i=0; i=max) max=*(score+i); return max; 4.double GetMin() 求最低分?jǐn)?shù) double m=*score; for(int i=0; iscore_num; i+) if(*(score+i)=m) m=*(score+i); return m; 4. 詳細(xì)設(shè)計(jì) #include #includeclass Studentprivate: char *name;
5、/student name char *stuno; /student no int score_num; /課程數(shù)量 double *score; /存儲(chǔ)學(xué)生課程成績的數(shù)組,其長度由score_num決定public: Student(char *n,char *m,int num,double *s) name=new charstrlen(n)+1; stuno=new charstrlen(m)+1; strcpy(name,n); strcpy(stuno,m); score_num=num; score=s; Student() delete name; delete stuno;
6、 cout析構(gòu)endl; double GetSum() 求總成績 double s=0; for(int i=0; iscore_num; i+) s = s+*(score+i); return s; double GetAver() 求平均成績 return GetSum()/score_num ; double GetMax() 求最高分?jǐn)?shù) double max=*score; for(int i=0; i=max) max=*(score+i); return max; double GetMin() 求最低分?jǐn)?shù) double m=*score; for(int i=0; iscor
7、e_num; i+) if(*(score+i)=m) m=*(score+i); return m; void Show() coutnameendl stunoendl GetAver()endl GetMax()endl GetMin()endl; return ; ; void main() double a3=50.0,80.0,60.0; Student student001(stu001,001,3,a); student001.Show(); return ;5. 程序調(diào)試a.(1) 未初始化函數(shù)(2) 調(diào)試加入初始化函數(shù)(3) 程序可運(yùn)行(4) 輸入數(shù)據(jù)(5) 結(jié)果正確b.運(yùn)
8、行結(jié)果6.實(shí)驗(yàn)總結(jié)在實(shí)驗(yàn)中其實(shí)程序的寫入并不難,只是我們應(yīng)該注意一些具體的細(xì)節(jié),比如函數(shù)的初始化,函數(shù)的具體方法等等。7.附錄 #include#includeclass Studentprivate: char *name; char *stuno; int score_num; double *score; public: Student(char *n,char *m,int num,double *s) name=new charstrlen(n)+1; stuno=new charstrlen(m)+1; strcpy(name,n); strcpy(stuno,m); score_
9、num=num; score=s; Student() delete name; delete stuno; cout析構(gòu)endl; double GetSum() double s=0; for(int i=0; iscore_num; i+) s = s+*(score+i); return s; double GetAver() return GetSum()/score_num ; double GetMax() double max=*score; for(int i=0; i=max) max=*(score+i); return max; double GetMin() double m=*score; for(int i=0; iscore_num; i+) if(*(score+i)=m) m=*(score+i); return m; void Show() coutnameendl stunoendl GetAve
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024-2030年牛仔服裝市場投資前景分析及供需格局研究預(yù)測報(bào)告
- 2024-2030年燃?xì)獗硇袠I(yè)市場現(xiàn)狀供需分析及投資評估規(guī)劃分析研究報(bào)告
- 2024-2030年熔噴設(shè)備行業(yè)市場現(xiàn)狀供需分析及重點(diǎn)企業(yè)投資評估規(guī)劃分析研究報(bào)告
- 2024-2030年熱塑性管行業(yè)市場現(xiàn)狀供需分析及投資評估規(guī)劃分析研究報(bào)告
- 2024-2030年液晶調(diào)光玻璃行業(yè)市場發(fā)展分析與發(fā)展趨勢及投資前景預(yù)測報(bào)告
- 出租公司運(yùn)營管理方案
- 出差飛機(jī)故障處理方案
- 凍雨形成的原因研究報(bào)告
- 冰雪時(shí)光營銷策略研究報(bào)告
- 伊春市五營區(qū)2025屆數(shù)學(xué)三年級第一學(xué)期期末聯(lián)考模擬試題含解析
- 第1章勾股定理單元測試2024-2025學(xué)年北師大版數(shù)學(xué)八年級上冊
- 版權(quán)許可權(quán)許可變更協(xié)議
- 2024-2030年中國演藝行業(yè)市場發(fā)展現(xiàn)狀分析及發(fā)展趨勢與投資前景研究報(bào)告
- ISO∕IEC22989-2022信息技術(shù) - 人工智能 - 人工智能概念和術(shù)語(中文版-雷澤佳譯2024)
- 多旋翼無人機(jī)駕駛員執(zhí)照(CAAC)備考試題庫大全-上部分
- 綠色動(dòng)力高鐵時(shí)代
- 2024-2030年中國小青龍顆粒市場經(jīng)營風(fēng)險(xiǎn)與投資前景建議研究研究報(bào)告
- 漢語基礎(chǔ)#-形考任務(wù)三-國開(HUB)-參考資料
- YB∕T 5363-2016 裝飾用焊接不銹鋼管
- 奇瑞汽車校園招聘測評題庫
- 污水管道更換工程施工方案
評論
0/150
提交評論