Advertisement
vutu10

Untitled

Jan 19th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class NrComplex
  5. {
  6.     double re, im;
  7.     int *v;
  8.     int l;
  9. public:
  10.     NrComplex()
  11.     {
  12.         re = im = 0;
  13.     }
  14.     NrComplex(double r, double i)
  15.     {
  16.         re = r;
  17.         im = i;
  18.     }
  19.     void Afisare()
  20.     {
  21.         cout << re << " + " << im << "i" << endl;
  22.     }
  23.     void operator =(const NrComplex& a)
  24.     {
  25.         re = a.re;
  26.         im = a.im;
  27.     }
  28.     double todouble();
  29.     NrComplex operator+(NrComplex nr2);
  30.     NrComplex operator*(NrComplex nr2);
  31.     NrComplex(double);
  32.     NrComplex& operator*(double v);
  33. };
  34.  
  35. NrComplex::NrComplex(double x)
  36. {
  37.     re = x;
  38.     im = 0;
  39. }
  40.  
  41.  
  42. double NrComplex::todouble()
  43. {
  44.     return (double)this->re / (double)this->im;
  45.    
  46. }
  47.  
  48.     NrComplex NrComplex::operator+(NrComplex nr2)
  49. {
  50.     NrComplex tmp;
  51.  
  52.     tmp.re = re + nr2.re;
  53.     tmp.im = im + nr2.im;
  54.     return tmp;
  55.  
  56. }
  57. NrComplex NrComplex::operator*(NrComplex nr2)
  58. {
  59.     NrComplex tmp;
  60.  
  61.     tmp.re = re * nr2.re - im * nr2.im;
  62.     tmp.im = re * nr2.im - im * nr2.re;
  63.     return tmp;
  64.  
  65. }
  66. NrComplex& NrComplex::operator*(double v)
  67. {
  68.     re *= v;
  69.     im *= v;
  70.     return *this;
  71. }
  72.  
  73.  
  74.  
  75. int main() {
  76.     NrComplex n, m, p, z, v;
  77.     NrComplex nr1(2.5, 9.4);
  78.     NrComplex nr2(4.2, 6.1);
  79.     NrComplex nr3;
  80.     NrComplex OB(2.5);
  81.     nr3 = nr1 + nr2;
  82.     n = nr3;
  83.     n.Afisare();
  84.     nr3 = nr1 * nr2;
  85.     m = nr3;
  86.     m.Afisare();
  87.     nr3 = nr1 * 2.5;
  88.     p = nr3;
  89.     p.Afisare();
  90.     z =2.5 *nr1;
  91.     z.Afisare();
  92.     return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement