Advertisement
paiuscarmina

nrcomplex

Jan 20th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. #include<iostream>
  2. #include<math.h>
  3. using namespace std;
  4.  
  5. class nrcomplex
  6. {
  7. private:
  8.     int re;
  9.     int im;
  10. public:
  11.     nrcomplex();
  12.     nrcomplex(int v);
  13.     nrcomplex(int RE,int IM );
  14.     int get_re();
  15.     int get_im();
  16.     void set_re(int r);
  17.     void set_im(int i);
  18.     nrcomplex operator+(nrcomplex nr);
  19.     nrcomplex operator-(nrcomplex nr);
  20.     nrcomplex operator*(nrcomplex nr);
  21.     void afisare();
  22.     void modul();
  23.  
  24. };
  25. nrcomplex::nrcomplex()
  26. {
  27.     re=im=0;
  28. }
  29. nrcomplex::nrcomplex(int v)
  30. {
  31.     re=im=v;
  32. }
  33. nrcomplex::nrcomplex(int RE, int IM)
  34. {
  35.     re=RE;
  36.     im=IM;
  37. }
  38. int nrcomplex::get_re()
  39. {
  40.     return re;
  41. }
  42. int nrcomplex::get_im()
  43. {
  44.     return im;
  45. }
  46. void nrcomplex::set_re(int r)
  47. {
  48.     re=r;
  49. }
  50. void nrcomplex::set_im(int i)
  51. {
  52.     im=i;
  53. }
  54. nrcomplex nrcomplex:: operator+(nrcomplex nr)
  55. {
  56.     nrcomplex tmp;
  57.     tmp.re=re+nr.re;
  58.     tmp.im=im+nr.im;
  59.     return tmp;
  60. }
  61. nrcomplex nrcomplex:: operator-(nrcomplex nr)
  62. {
  63.     nrcomplex tmp;
  64.     tmp.re=re-nr.re;
  65.     tmp.im=im-nr.im;
  66.     return tmp;
  67. }
  68. void nrcomplex::afisare()
  69. {
  70.     cout<<re<<"+"<<im<<"i"<<endl;
  71. }
  72. void nrcomplex:: modul()
  73. {
  74.     cout<<sqrt(re*re+im*im)<<endl;
  75. }
  76. nrcomplex nrcomplex::operator*(nrcomplex nr)
  77. {   nrcomplex tmp;
  78.     tmp.re=re*tmp.re-(im*tmp.im);
  79.     tmp.im=re*tmp.im+im*tmp.re;
  80.     return tmp;
  81.  
  82.  
  83. }
  84.  
  85.  
  86. int main()
  87.  
  88. {   int n;
  89.     cin>>n;
  90.     nrcomplex*v=new nrcomplex[n];
  91.     for(int i=0;i<n;i++)
  92.     {   int a,b;
  93.     cin>>a>>b;
  94.         v[i].set_re(a);
  95.         v[i].set_im(b);
  96.  
  97.     }
  98.    /*v[2]= v[0]+v[1];
  99.    v[2].afisare();
  100.    v[2].modul();*/
  101.    nrcomplex pr;
  102.    v[2]=v[0]*v[1];
  103.    v[2].afisare();
  104.  
  105.  
  106.     return 0;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement