複數的概念我們高中已經接觸過,包含是實部和虛部,
for example:2i + 3j;實部和虛部值可為整型,亦可浮點型,那在此實現一下簡單的複數類的操作
**如下:
class complex
complex(const complex& c)
~complex()
complex& operator=(const complex& c)
return *this;
}complex operator+(const complex& c)
complex& operator++() // 前置++ , 當外面需要此返回值時,需要加&
complex operator++(int) // 後置++ ,當外面不需要此返回值時,無需加&
complex& operator+= (const complex& c)
inline bool operator==(const complex& c)
inline bool operator>(const complex& c)
inline bool operator>=(const complex& c)
inline bool operator<=(const complex& c)
bool operator<(const complex& c)
inline void display()
c 實現複數類
主要是練習用運算子過載實現複數的一些基本運算,包括 複數加法 過載的運算子 前置 後置 複數減法 過載的運算子 前置 後置 複數乘法 過載的運算子 複數除法 過載的運算子 如下 includeusing namespace std class complex 建構函式 complex const c...
C 實現複數類
complex類的成員變數有實部與虛部 protected double real double image c 中的complex類的基本函式,包括四個預設成員函式,比較運算子過載函式,賦值運算子過載函式,以及前置 與後置 的過載。四個預設成員函式是 1 建構函式 在定義物件時初始化成員變數,函式...
C 實現複數類
用c 語言實現乙個複數類,包括複數加 減 乘 除 加等 減等 乘等及除等8個運算子的過載。include using namespace std class complex 複數類 類外實現成員函式 complex complex const double real,const double ima...