?? 9-2-2.cpp
字號:
#include <iostream.h>
class Complex {
private:
double real, image; // 復數的實部和虛部
public:
Complex() { real = image = 0.0; }
Complex(double r) {real = r; image = 0.0; }
Complex(double r, double i)
{ real = r; image = i; };
friend Complex operator + (const Complex &c1, const Complex &c2);
friend void print(const Complex &c);
};
inline Complex operator + (const Complex &c1, const Complex &c2)
{ return Complex(c1.real + c2.real, c1.image + c2.image);
}
void print(const Complex &c)
{ if(c.image < 0) cout <<c.real<<" - "<< -c.image<<" i" ;
else cout <<c.real<<" + "<<c.image<<" i" ;
cout << endl;
}
void main()
{ Complex c1(2.5), c2(3.6, -1.2), c3;
c3 = c1 + c2;
cout << "c1+c2 = "; print(c3);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -