第十周 複數類

2021-06-21 22:04:11 字數 2132 閱讀 4455

#include using namespace std;

class complex

complex(double r,double i)

complex operator-();

//實現輸入、輸出的運算子過載

friend ostream& operator << (ostream& output, const complex& c);

friend istream& operator >> (istream& input, complex& c);

//實現加減乘除的運算子過載

friend complex operator+(complex &c1, complex &c2);

friend complex operator+(double d1, complex &c2);

friend complex operator+(complex &c1, double d2);

friend complex operator-(complex &c1, complex &c2);

friend complex operator-(double d1, complex &c2);

friend complex operator-(complex &c1, double d2);

friend complex operator*(complex &c1, complex &c2);

friend complex operator*(double d1, complex &c2);

friend complex operator*(complex &c1, double d2);

friend complex operator/(complex &c1, complex &c2);

friend complex operator/(double d1, complex &c2);

friend complex operator/(complex &c1, double d2);

private:

double real;

double imag;

};//實現輸出的運算子過載

ostream& operator << (ostream& output, const complex& c)

while(!((sign=='+'||sign=='-')&&i=='i'));

c.real=a;

c.imag=(sign=='+')?b:-b;

return input;

}complex complex::operator-()

//複數相加:(a+bi)+(c+di)=(a+c)+(b+d)i.

complex operator+(complex &c1, complex &c2)

complex operator+(double d1, complex &c2)

complex operator+(complex &c1, double d2)

//複數相減:(a+bi)-(c+di)=(a-c)+(b-d)i.

complex operator-(complex &c1, complex &c2)

complex operator-(double d1, complex &c2)

complex operator-(complex &c1, double d2)

//複數相乘:(a+bi)(c+di)=(ac-bd)+(bc+ad)i.

complex operator*(complex &c1, complex &c2)

complex operator*(double d1, complex &c2)

complex operator*(complex &c1, double d2)

//複數相除:(a+bi)/(c+di)=(ac+bd)/(c^2+d^2) +(bc-ad)/(c^2+d^2)i

complex operator/(complex &c1, complex &c2)

complex operator/(double d1, complex &c2)

complex operator/(complex &c1, double d2)

int main()

第十周 oj 類模板

問題及 宣告乙個類模板,利用它分別實現兩個整數 浮點數和字元的比較,求出大數和小數。說明 在類模板外定義各成員函式。輸入兩個整數 兩個浮點數和兩個字元 從大到小輸出兩個整數 兩個浮點數和兩個字元 3 7 45.78 93.6 a a7 3 93.60 45.78 a a include includ...

第十周周小結

2.本次工作任務 本週老師沒有明確的給每個團隊留這週的作業,因為每個團隊的專案進入到了開發階段,老師只是要求每個團隊每天必須有要有明確的任務,提交量和團隊內部每日例會總結上傳到碼雲倉庫,助教每天每天進入倉庫檢視,他們專案倉庫的提交結果並進行點評和打分。我負責的團隊 web5組,web8組,web9組...

第十周總結

這周一開始說的是要考試,但是最後又說等通知,所以就有時間複習了,要是真的這周考試那就涼涼了。之前學的有的忘了,有的是根本都不會,反正都得從頭開始看。這周講課的時候我看了看講課表,嗯,下下個星期就到我了。下個星期又要考試,所以說還是考試重要,講課先放到一邊,等考試過了再說,畢竟考的那兩門都挺難的。不過...