面向?qū)ο蟪绦蛟O(shè)計實驗九新_第1頁
面向?qū)ο蟪绦蛟O(shè)計實驗九新_第2頁
面向?qū)ο蟪绦蛟O(shè)計實驗九新_第3頁
面向?qū)ο蟪绦蛟O(shè)計實驗九新_第4頁
全文預(yù)覽已結(jié)束

下載本文檔

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

文檔簡介

溫州大學(xué)物理與電子信息工程學(xué)院 面向?qū)ο蟪绦蛟O(shè)計實驗報告實驗名稱:實驗九:運算符重載班 級:計算機(jī)科學(xué)姓 名:錢旭北學(xué) 號:07202043217實驗地點:5B305日 期:一、實驗?zāi)康模?、理解運算符重載的本質(zhì)和意義。2、掌握成員函數(shù)方式的運算符重載。3、掌握友元方式的運算符重載二、實驗環(huán)境:windows 2000, visual c+6.0或c-free三、實驗內(nèi)容和要求:(一)擴(kuò)展實驗五中Complex類的內(nèi)容,增加1、單目運算符負(fù)號:的重載;2、雙目運算符、*、/、=、!=的友元重載;3、雙目運算符、*、/的成員重載;4、插入運算符 的重載(二)實現(xiàn)并測試下面的類class student char *name; /姓名 int age; /年齡 float *score;/成績 int scorenum; public: student(char *name, int age , int scorenum=3 ) ; student( const student& s); student operator =( const student& s); student( ); void setscore(); /輸入學(xué)生的信息 void print(); /把學(xué)生的信息打印出來;四、預(yù)習(xí)內(nèi)容:1、什么樣的運算符應(yīng)重載為成員?2、運算符對應(yīng)的函數(shù)名是什么?五、實驗步驟(各源程序文件):#include#includeusing namespace std;class student char *name; /姓名 int age; /年齡 float *score;/成績 int scorenum; public: student() student(char *name, int age ,int scorenum=3 ) ; student( const student& s); student operator =( const student& s); student( ); void setscore( ); /輸入學(xué)生的信息 void print( ); /把學(xué)生的信息打印出來;student:student(char *name,int age ,int scorenum=3 ) this-name=new charstrlen(name)+1; strcpy(this-name,name); this-age=age; this-scorenum=scorenum; score=new floatscorenum;student:student(const student &s) int i,k; age=s.age;scorenum=s.scorenum; k=strlen()+1; name=new chark; for(i=0;ik;i+) namei=i; score=new floatscorenum; for(i=0;iscorenum;i+) scorei=s.scorei;student student:operator =( const student& s) int i,k; age=s.age;scorenum=s.scorenum; delete name; delete score; k=strlen()+1; name=new chark; for(i=0;ik;i+) namei=i; score=new floatscorenum; for(i=0;iscorenum;i+) scorei=s.scorei; return *this;student:student()delete name;delete score;void student:setscore( ) int i,a; for(i=0;ia; scorei=a; void student:print() coutname age scorenumt; for(int i=0;iscorenum;i+) coutscorei ;void main() student s1(xiaobai,20 ,3),s2; s1.setscore(); s2=s1; student s3(s1); s1.print(); s2.print(); s3.print(); 六、實驗結(jié)果與

溫馨提示

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

最新文檔

評論

0/150

提交評論