第九周 任務三

2021-06-05 19:13:05 字數 2109 閱讀 6483

/* 

實驗內容:定義分數類中《和》運算子過載

* 程式的版權和版本宣告部分

* 檔名稱: 定義分數類中《和》運算子過載

* 作 者: 薛廣晨

* 完成日期: 2012 年 4 月 14 日

* 版 本號: x1.0

*///【任務3】接第8周任務3,定義分數類中《和》運算子過載,實現分數的輸入輸出,改造原程式中對運算結果顯示方式,使程式讀起來更自然。

#includeusing namespace std;

class cfraction

; //建構函式,初始化用

void output1();

friend ostream& operator << (ostream &,cfraction &);

friend istream& operator >> (istream &,cfraction &);

cfraction operator+(cfraction &c1);

cfraction operator-(cfraction &c1);

cfraction operator*(cfraction &c1);

cfraction operator/(cfraction &c1);

cfraction operator-();//取反

//比較運算子(二目)的過載

bool operator > (cfraction &c1);

bool operator < (cfraction &c1);

bool operator >= (cfraction &c1);

bool operator <= (cfraction &c1);

bool operator == (cfraction &c1);

bool operator != (cfraction &c1);

};ostream& operator << (ostream &ouput, cfraction &c)

}ouput << c.nume << "/" << c.deno << endl;

} else

}ouput << -c.nume << "/" << c.deno << endl;

} return ouput;

} istream& operator >> (istream &input, cfraction &c)

}while(1);

return input;

}cfraction cfraction :: operator+(cfraction &c1)

cfraction cfraction :: operator-(cfraction &c1)

cfraction cfraction :: operator*(cfraction &c1)

cfraction cfraction :: operator/(cfraction &c1)

cfraction cfraction :: operator-()//取反

void cfraction :: output1()

//比較運算子(二目)的過載

上機感言:感覺挺爽的,可以直接輸入與輸出

第九周 任務一

實驗內容 定義complex類中的 和 運算子的過載,實現輸入和輸出。程式的版權和版本宣告部分 檔名稱 定義complex類中的 和 運算子的過載,實現輸入和輸出 作 者 薛廣晨 完成日期 2012 年 4 月 14日 版 本號 x1.0 對任務及求解方法的描述部分 輸入描述 程式頭部的注釋結束 此...

第九周任務1

includeusing namespace std class complex complex double r,double i complex operator complex c2 complex operator complex c2 complex operator complex c2...

第九周任務2

include using namespace std class ctime void settime int h,int m,int s 比較運算子 二目 的過載 bool operator ctime t bool operator ctime t bool operator ctime t ...