You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
689 B
C++

#ifndef COMPLEX_CPP
#define COMPLEX_CPP
#include "ComplexNumber.h"
#include <iostream>
Complex::Complex(double real, double imaginary) {
this->real = real;
this->imaginary = imaginary;
}
double Complex::getReal() const {
return real;
}
double Complex::getImaginary() const {
return imaginary;
}
Complex Complex::operator+(const Complex& other) const {
double resultReal = real + other.real;
double resultImaginary = imaginary + other.imaginary;
return Complex(resultReal, resultImaginary);
}
std::ostream& operator<<(std::ostream& os, const Complex& complex) {
os << complex.getReal() << "+" << complex.getImaginary() << "i";
return os;
}
#endif