Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<math.h>
- using namespace std;
- class nrcomplex
- {
- private:
- int re;
- int im;
- public:
- nrcomplex();
- nrcomplex(int v);
- nrcomplex(int RE,int IM );
- int get_re();
- int get_im();
- void set_re(int r);
- void set_im(int i);
- nrcomplex operator+(nrcomplex nr);
- nrcomplex operator-(nrcomplex nr);
- nrcomplex operator*(nrcomplex nr);
- void afisare();
- void modul();
- };
- nrcomplex::nrcomplex()
- {
- re=im=0;
- }
- nrcomplex::nrcomplex(int v)
- {
- re=im=v;
- }
- nrcomplex::nrcomplex(int RE, int IM)
- {
- re=RE;
- im=IM;
- }
- int nrcomplex::get_re()
- {
- return re;
- }
- int nrcomplex::get_im()
- {
- return im;
- }
- void nrcomplex::set_re(int r)
- {
- re=r;
- }
- void nrcomplex::set_im(int i)
- {
- im=i;
- }
- nrcomplex nrcomplex:: operator+(nrcomplex nr)
- {
- nrcomplex tmp;
- tmp.re=re+nr.re;
- tmp.im=im+nr.im;
- return tmp;
- }
- nrcomplex nrcomplex:: operator-(nrcomplex nr)
- {
- nrcomplex tmp;
- tmp.re=re-nr.re;
- tmp.im=im-nr.im;
- return tmp;
- }
- void nrcomplex::afisare()
- {
- cout<<re<<"+"<<im<<"i"<<endl;
- }
- void nrcomplex:: modul()
- {
- cout<<sqrt(re*re+im*im)<<endl;
- }
- nrcomplex nrcomplex::operator*(nrcomplex nr)
- { nrcomplex tmp;
- tmp.re=re*tmp.re-(im*tmp.im);
- tmp.im=re*tmp.im+im*tmp.re;
- return tmp;
- }
- int main()
- { int n;
- cin>>n;
- nrcomplex*v=new nrcomplex[n];
- for(int i=0;i<n;i++)
- { int a,b;
- cin>>a>>b;
- v[i].set_re(a);
- v[i].set_im(b);
- }
- /*v[2]= v[0]+v[1];
- v[2].afisare();
- v[2].modul();*/
- nrcomplex pr;
- v[2]=v[0]*v[1];
- v[2].afisare();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement