#includeusing namespace std;
class complex
complex(double r,double i)
complex operator+(complex &c2);
complex operator-(complex &c2);
complex operator*(complex &c2);
complex operator/(complex &c2);
void display();
private:
double real;
double imag;
};
//下面定義成員函式
//複數相加: (a+bi)+(c+di)=(a+c)+(b+d)i.
complex complex::operator+(complex &c2)
//複數相減:(a+bi)-(c+di)=(a-c)+(b-d)i.
complex complex::operator-(complex &c2)
//複數相乘:(a+bi)(c+di)=(ac-bd)+(bc+ad)i.
complex complex::operator*(complex &c2)
//複數相除:(a+bi)/(c+di)=(ac+bd)/(c^2+d^2) +(bc-ad)/(c^2+d^2)i
complex complex::operator/(complex &c2)
void complex::display( )
complex(double r,double i)
friend complex operator+(complex &c1,complex &c2);
friend complex operator-(complex &c1,complex &c2);
friend complex operator*(complex &c1,complex &c2);
friend complex operator/(complex &c1,complex &c2);
friend void display(complex &c2);
private:
double real;
double imag;
};
//下面定義友元函式
//複數相加: (a+bi)+(c+di)=(a+c)+(b+d)i.
complex operator+(complex &c1,complex &c2)
//複數相減:(a+bi)-(c+di)=(a-c)+(b-d)i.
complex operator-(complex &c1,complex &c2)
//複數相乘:(a+bi)(c+di)=(ac-bd)+(bc+ad)i.
complex operator*(complex &c1,complex &c2)
//複數相除:(a+bi)/(c+di)=(ac+bd)/(c^2+d^2) +(bc-ad)/(c^2+d^2)i
complex operator/(complex &c1,complex &c2)
void display(complex &c2)
complex(double r,double i)
friend complex operator+(complex &c1,complex &c2);
friend complex operator-(complex &c1,complex &c2);
friend complex operator-(complex &c2);
friend complex operator*(complex &c1,complex &c2);
friend complex operator/(complex &c1,complex &c2);
friend complex operator+(complex &c1,const double &d);
friend complex operator+(const double &d, complex &c);
friend void display(complex &c2);
private:
double real;
double imag;
};
//下面定義友元函式
//複數相加: (a+bi)+(c+di)=(a+c)+(b+d)i.
complex operator+(complex &c1,complex &c2)
complex operator+(complex &c1,const double &d)
complex operator+(const double &d, complex &c1)
//複數相減:(a+bi)-(c+di)=(a-c)+(b-d)i.
complex operator-(complex &c1,complex &c2)
complex operator-(complex &c2)
//複數相乘:(a+bi)(c+di)=(ac-bd)+(bc+ad)i.
complex operator*(complex &c1,complex &c2)
//複數相除:(a+bi)/(c+di)=(ac+bd)/(c^2+d^2) +(bc-ad)/(c^2+d^2)i
complex operator/(complex &c1,complex &c2)
void display(complex &c2)
{
cout<
感想:許多問題,認真看書後變的很簡單了,另外,還要弄明白任務的要求
第八周實驗報告1
程式頭部注釋開始 程式的版權和版本宣告部分 檔名稱 實現複數類中的運算子過載 作 者 於宸 完成日期 2012 年04 月08 日 版 本 號 1.0 對任務及求解方法的描述部分 輸入描述 問題描述 定義乙個複數類過載運算子 使之能用於複數的加減乘除。程式輸出 程式頭部的注釋結束 html view...
第八周實驗報告(1 2)
程式頭部注釋開始 程式的版權和版本宣告部分 檔名稱 友元函式 運算子過載 作 者 李瑞 完成日期 2012 年4 月 8日 版 本 號 v1.0 對任務及求解方法的描述部分 輸入描述 問題描述 程式輸出 程式頭部的注釋結束 用類的友元函式,完成複數類的運算子的過載 includeusing name...
第八周實驗報告1 1
實驗目的 定義乙個複數類,過載運算子 使之能用於複數的加減乘除。實驗 include include using namespace std class complex complex double r,double i complex operator complex c2 complex ope...