📄 complex2.cpp
字号:
// complex2.cpp Implementation file for class Complex using
// overloaded arithmetic and insertion, extraction operators
#include "complex.h"
// `+' operator Returns the sum of the owner and the parameter
Complex Complex::operator + (Complex x)
{ Complex temp;
temp.real = real + x.real;
temp.imag = imag + x.imag;
return (temp);
}
// `-' operator Returns the diff. between the owner and parameter
Complex Complex::operator - (Complex x)
{ Complex temp;
temp.real = real - x.real;
temp.imag = imag - x.imag;
return (temp);
}
// `*' operator Returns the product of the owner and the parameter
Complex Complex::operator * ( Complex x)
{ Complex temp;
temp.real = (real*x.real) - (imag*x.imag);
temp.imag = (imag * x.real) + (real * x.imag);
return (temp);
}
// InputC() Input a complex pair into owner
void Complex::InputC (istream& in)
{ char i, paren, comma;
in >> paren >> real >> comma >> imag >> i >> paren;
}
// OutputC() Output the owner as a complex pair
void Complex::OutputC (ostream& out)
{ out << `(` << real << `,' << imag << "i)" << endl;
}
// wrapper function for the extraction `>>' operator
istream& operator >> (istream& in, Complex& x)
{ x.InputC (in);
return (in);
}
// wrapper function for the insertion `<<' operator
ostream& operator << (ostream& out, Complex x)
{ x.Output (out);
return (out);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -