Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <iostream>
- using namespace std;
- class Complex {
- public:
- double real, imag;
- Complex(double r, double i) {
- real = r;
- imag = i;
- }
- Complex(double r) {
- real = r;
- imag = 0;
- }
- Complex operator + (const Complex& c) {
- return Complex (real + c.real, imag + c.imag);
- }
- Complex operator - (Complex& c) {
- return Complex (real - c.real, imag - c.imag);
- }
- Complex operator * (Complex& c) {
- return Complex (real * c.real - imag * c.imag, imag * c.real + real * c.imag);
- }
- Complex operator / (Complex& c) {
- return Complex ((real * c.real + imag * c.imag) / (c.real * c.real + c.imag * c.imag),
- (imag * c.real - real * c.imag) / (c.real * c.real + c.imag * c.imag));
- }
- Complex operator + () {
- return Complex (real, imag);
- }
- Complex operator - () {
- return Complex (-real, -imag);
- }
- double Re() {
- return real;
- }
- double Im() {
- return imag;
- }
- bool operator == (Complex& c) {
- return (real == c.real && imag == c.imag);
- }
- bool operator != (Complex& c) {
- return (real != c.real || imag != c.imag);
- }
- };
- double abs(Complex& c) {
- return sqrt (c.real * c.real + c.imag * c.imag);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement