Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- using namespace std;
- class complex {
- float im;
- float re;
- public:
- complex() // по умолчанию
- {
- cout << "CREATED DEFAULT" << endl;
- im = -1;
- re = -1;
- }
- complex(const complex& o)
- {
- re = o.re;
- im = o.im;
- cout << "CREATED COPY" << endl;
- }
- complex(float re, float im)
- : im(im), re(re)
- {
- cout << "CREATED HIPSTER" << endl;
- this->im = im;
- this->re = re;
- }
- ~complex()
- {
- cout << "DELETED" << endl;
- }
- float getIm()
- {
- return im;
- }
- float getRe()
- {
- return re;
- }
- void setIm(float im)
- {
- this->im = im;
- }
- void setRe(float re)
- {
- this->re = re;
- }
- complex operator+(float other)
- {
- complex c;
- c.re = other + re;
- c.im = im;
- return c;
- }
- complex operator-(float other)
- {
- complex c;
- c.re = re - other;
- c.im = im;
- return c;
- }
- complex operator*(float other);
- complex operator/(float other);
- complex operator+(complex& other)
- {
- complex c;
- c.re = re + other.re;
- c.im = im + other.im;
- return c;
- }
- complex operator-(complex& other)
- {
- complex c;
- c.re = re - other.re;
- c.im = im - other.im;
- return c;
- }
- complex operator*(complex& other)
- {
- complex c;
- c.re = re*other.re - im*other.im;
- c.im = re*other.im + im*other.re;
- return c;
- }
- complex operator/(complex& other)
- {
- complex c;
- c.re = (re*other.re + im*other.im) / (other.re*other.re + other.im*other.im);
- c.im = (other.re*im - re*other.im) / (other.re*other.re + other.im*other.im);
- return c;
- }
- void print();
- friend complex operator+(float other, complex& first);
- friend complex operator-(float other, complex& first);
- };
- complex operator-(float other, complex& first)
- {
- complex c;
- c.re = first.re - other;
- c.im = first.im;
- return c;
- }
- complex operator*(float other, complex& first)
- {
- complex c;
- c.setRe(first.getRe()*other);
- return c;
- }
- complex operator/(float other, complex& first)
- {
- complex c;
- c.setRe(first.getRe()/other);
- return c;
- }
- complex operator+(float other, complex& first)
- {
- complex c;
- c.re = other + first.re;
- c.im = first.im;
- return c;
- }
- int main()
- {
- complex p1(1, 2);
- complex p2(2, 3);
- complex c = p2/p1; //p1.operator+(p2);
- cout << c.getIm() << "*i + " << c.getRe() << endl;
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement