Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "MyComplex.h"
- #include <ostream>
- Complex::Complex() {}
- Complex::Complex(double a, double b) : real(a), imag(b) {}
- Complex::~Complex(){}
- Complex& Complex::add(Complex& other) {
- double rez_real = real + other.real;
- double rez_imag = imag + other.imag;
- return Complex(rez_real, rez_imag);
- }
- Complex& Complex::sub(Complex& other) {
- double rez_real = real - other.real;
- double rez_imag = imag - other.imag;
- return Complex(rez_real, rez_imag);
- }
- Complex& Complex::mul(Complex& other) {
- double rez_real = real * other.real - imag * other.imag;
- double rez_imag = real * other.real + imag * other.imag;
- return Complex(rez_real, rez_imag);
- }
- Complex& Complex::mul(double other) {
- double rez_real = real * other - imag * other;
- double rez_imag = real * other + imag * other;
- return Complex(rez_real, rez_imag);
- }
- Complex& Complex::conj() {
- return Complex(real, -imag);
- }
- double Complex::getReal() const{
- return real;
- }
- double Complex::getImag() const{
- return imag;
- }
- Complex& Complex::operator+(Complex& other)
- {
- return this->add(other);
- }
- Complex & Complex::operator-(Complex& other)
- {
- return this->sub(other);
- }
- Complex & Complex::operator*(Complex& other)
- {
- return this->mul(other);
- }
- Complex& Complex::operator*(double other) {
- return this->mul(other);
- }
- Complex& Complex::operator~()
- {
- return this->conj();
- }
- void Complex::setImag(double a) {
- imag = a;
- }
- void Complex::setReal(double a) {
- real = a;
- }
- std::ostream& operator<<(std::ostream& os,const Complex& c)
- {
- os << c.getReal() << "+" << c.getImag() << "i";
- return os;
- }
- std::istream& operator>>(std::istream& is, Complex& c)
- {
- double rea;
- double ima;
- is >> rea;
- is >> ima;
- c.setReal(rea);
- c.setImag(ima);
- return is;
- }
- Complex & operator*(double c,const Complex& comp)
- {
- return Complex(c*comp.getReal(), c*comp.getImag());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement