南昌航空大學(xué)實(shí)驗(yàn)報(bào)告3析構(gòu)函數(shù)_第1頁
南昌航空大學(xué)實(shí)驗(yàn)報(bào)告3析構(gòu)函數(shù)_第2頁
南昌航空大學(xué)實(shí)驗(yàn)報(bào)告3析構(gòu)函數(shù)_第3頁
南昌航空大學(xué)實(shí)驗(yàn)報(bào)告3析構(gòu)函數(shù)_第4頁
南昌航空大學(xué)實(shí)驗(yàn)報(bào)告3析構(gòu)函數(shù)_第5頁
已閱讀5頁,還剩8頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論