Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- complex.h
- #ifndef COMPLEX_H
- #define COMPLEX_H
- #endif // COMPLEX_H
- class complex{
- private:
- float x,y;
- public:
- complex(int, int);
- ~complex();
- float modul();
- void citire();
- void afisare();
- complex operator +(complex);
- complex operator -(complex);
- complex operator *(complex);
- complex operator /(complex);
- complex operator !();
- complex operator ++();
- complex operator ++(int );
- complex operator --();
- complex operator --(int );
- };
- complex.cpp
- #include "complex.h"
- #include "iostream"
- #include "math.h"
- using namespace std;
- complex::complex(float a, float b)
- {
- x = a;
- y = b;
- }
- complex::~complex()
- {
- cout<<"Am eliminat un obiect";
- }
- float complex::modul()
- {
- return sqrt(x *x + y * y);
- }
- void complex::citire()
- {
- cout<<"Dati partea reala"; cin>>x;
- cout<<"Dati partea imaginara"; cin>>y;
- }
- void complex::afisare()
- {
- if(x !=0 )
- if(y != 0)
- cout<<x <<'+'<<y<<"i";
- else
- cout<<x;
- else
- if(y != 0)
- cout<<"i"<<y;
- else
- cout<<0;
- }
- complex complex::operator++(complex z)
- {
- complex r;
- r.x = x + z.x;
- r.y = y + z.y;
- return r;
- }
- complex complex::operator--(complex z)
- {
- complex r;
- r.x = x - z.x;
- r.y = y - z.y;
- return r;
- }
- complex complex::operator*(complex z)
- {
- complex r;
- r.x = x * z.x - y * z.y;
- r.y = y * z.x + x * z.y;
- return r;
- }
- complex complex::operator/(complex z)
- {
- complex r;
- if(z)
- {
- r.x = x * z.x + y * z.y;
- r.y = y * z.x + x * z.y;
- int numi = z.x * z.x + z.y * z.y;
- r.x = r.x / numi;
- r.y = r.y / numi;
- }
- return r;
- }
- complex complex::operator++()
- {
- complex r;
- r.x = x + z.x;
- r.y = y + z.y;
- return r;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement