Unit9 problem1 複數大排練

2021-06-21 20:31:00 字數 2319 閱讀 1796

/*univercity:煙台大學

*@class計134~4

*@author:薛富磊

*@time:2014-4-28

*@function:複數

*@args:

*@return:

*/#include#includeusing namespace std;

class complex

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)

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()

/*心得體會:

基本都是看的老師的

不過都看的懂 mmbb*/

Unit5 problem3 形體藝術

univercity 煙台大學 class計134 4 author 薛富磊 time 2014 3 18 function 長方柱類 args return include includeusing namespace std class bulk double volume 體積 double ...

Unit13 problem1 2 圓大小比較

univercity 煙台大學 class計134 4 author 薛富磊 time 2014 5 27 function 在專案1的基礎上,在圓類上過載關係運算子 6種 使之能夠按圓的面積比較兩個圓的大小。自編main函式完成測試。args return include includeusing...

Unit9 作業練習

第九單元練習 1.在desktop主機中建立使用者westos,並設定其密碼為westoslinux 2.配置desktop中的sshd服務要求如下 設定sshd服務只允許westos使用者可以被訪問使用 命令 vim etc ssh sshd config 修改配置檔案 allowusers we...