📄 l8_6.cpp
字号:
#include "iostream.h"
class CComplex
{
private:
double real;
double imag;
public:
CComplex(double r=0, double i=0);
void Print();
friend CComplex operator +(CComplex c1,CComplex c2);
friend CComplex operator -(CComplex c1,CComplex c2);
};
CComplex::CComplex (double r, double i)
{
real = r;
imag = i;
}
void CComplex::Print()
{
cout << "(" << real << "," << imag << ")" << endl;
}
CComplex operator +(CComplex c1, CComplex c2)
{
CComplex temp;
temp.real = c1.real + c2.real;
temp.imag = c1.imag + c2.imag;
return temp;
}
CComplex operator -(CComplex c1, CComplex c2)
{
CComplex temp;
temp.real = c1.real - c2.real;
temp.imag = c1.imag - c2.imag;
return temp;
}
void main(void)
{
CComplex a(1, 2), b(3.0, 4.0), c, d, e;
c = a+b;
d = b-10;
e = 20+a;
cout << "c = ";
c.Print();
cout << "d = ";
d.Print();
cout << "e = ";
e.Print();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -