Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "Complex.h"
- Complex::Complex(): _re(0.0), _im(0.0)
- {
- }
- Complex::Complex(double re, double im): _re(re), _im(im)
- {
- }
- double Complex::getIm() const
- {
- return _im;
- }
- double Complex::getRe() const
- {
- return _re;
- }
- void Complex::setIm(double im)
- {
- _im = im;
- }
- void Complex::setRe(double re)
- {
- _re = re;
- }
- Complex & Complex::operator+=(const Complex & other)
- {
- setRe(getRe() + other.getRe());
- setIm(getIm() + other.getIm());
- return *this;
- }
- Complex Complex::operator+(const Complex & other) const
- {
- Complex result(this->getRe() + other.getRe(), this->getIm() + other.getIm());
- return result;
- }
- double Complex::operator[](int number) const
- {
- switch (number)
- {
- case 0: return getRe();
- case 1: return getIm();
- default: return 0.0;
- }
- }
- bool Complex::operator!=(const Complex & other) const
- {
- if (this->getRe() == other.getRe() && this->getIm() == other.getIm())
- return false;
- return true;
- }
- bool Complex::operator==(const Complex & other) const
- {
- return !(other!=(*this));
- }
- Complex & Complex::operator++()
- {
- this->setRe(this->getRe() + 1.0);
- this->setIm(this->getIm() + 1.0);
- return *this;
- }
- Complex Complex::operator++(int)
- {
- Complex temp(this->getIm(),this-> getRe());
- ++(*this);
- return temp;
- }
- void Complex::operator()(double re, double im)
- {
- this->setRe(re);
- this->setIm(im);
- }
- Complex & Complex::operator=(const Complex & other)
- {
- this->setRe(other.getRe());
- this->setIm(other.getIm());
- return *this;
- }
- Complex & operator+(Complex & complex, const double & d)
- {
- complex.setIm(complex.getIm() + d);
- complex.setRe(complex.getRe() + d);
- return complex;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement