Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class NrComplex
- { double re, im;
- public:
- NrComplex()
- {
- re = im = 0;
- }
- NrComplex(double r, double i)
- {
- re = r;
- im = i;
- }
- void Afisare()
- {
- cout << re << " + " << im << "i" << endl;
- }
- friend NrComplex operator+(NrComplex,NrComplex);
- friend NrComplex operator*(NrComplex,NrComplex);
- friend NrComplex operator*(NrComplex,double);
- friend NrComplex operator*(double,NrComplex);
- friend NrComplex operator~(NrComplex);
- };
- NrComplex operator+(NrComplex nr1, NrComplex nr2)
- { NrComplex tmp;
- tmp.re = nr1.re + nr2.re;
- tmp.im = nr1.im + nr2.im;
- return tmp;
- }
- NrComplex operator*(NrComplex nr1, NrComplex nr2)
- {
- NrComplex tmp;
- tmp.re = nr1.re * nr2.re - nr1.im * nr2.im;
- tmp.im = nr1.re * nr2.im + nr1.im * nr2.re;
- return tmp;
- }
- NrComplex operator*(NrComplex nr1, double n)
- {
- NrComplex tmp;
- tmp.re = nr1.re * n;
- tmp.im = nr1.im;
- return tmp;
- }
- NrComplex operator*(double n, NrComplex nr1)
- {
- NrComplex tmp;
- tmp.re = n * nr1.re;
- tmp.im = nr1.im;
- return tmp;
- }
- NrComplex operator~(NrComplex nr1)
- {
- NrComplex tmp;
- tmp.re = nr1.re;
- tmp.im = - nr1.im;
- return tmp ;
- }
- int main()
- {
- NrComplex ob(2.5, 3.4);
- NrComplex ob2;
- ob2 = ob * 3;
- ob2.Afisare();
- ob2 = 3 * ob;
- ob2.Afisare();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement