Advertisement
Guest User

:D

a guest
May 26th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1. complex.h
  2.  
  3. #ifndef COMPLEX_H
  4. #define COMPLEX_H
  5.  
  6.  
  7. #endif // COMPLEX_H
  8.  
  9. class complex{
  10. private:
  11.     float x,y;
  12. public:
  13.     complex(int, int);
  14.     ~complex();
  15.     float modul();
  16.     void citire();
  17.     void afisare();
  18.     complex operator +(complex);
  19.     complex operator -(complex);
  20.     complex operator *(complex);
  21.     complex operator /(complex);
  22.     complex operator !();
  23.     complex operator ++();
  24.     complex operator ++(int );
  25.     complex operator --();
  26.     complex operator --(int );
  27. };
  28.  
  29.  
  30.  
  31.  
  32. complex.cpp
  33.  
  34.  
  35. #include "complex.h"
  36. #include "iostream"
  37. #include "math.h"
  38.  
  39. using namespace std;
  40.  
  41. complex::complex(float a, float b)
  42. {
  43.     x = a;
  44.     y = b;
  45. }
  46.  
  47. complex::~complex()
  48. {
  49.     cout<<"Am eliminat un obiect";
  50. }
  51.  
  52. float complex::modul()
  53. {
  54.     return sqrt(x *x + y * y);
  55. }
  56.  
  57. void complex::citire()
  58. {
  59.     cout<<"Dati partea reala"; cin>>x;
  60.     cout<<"Dati partea imaginara"; cin>>y;
  61. }
  62.  
  63. void complex::afisare()
  64. {
  65.     if(x !=0 )
  66.         if(y != 0)
  67.             cout<<x <<'+'<<y<<"i";
  68.         else
  69.             cout<<x;
  70.     else
  71.         if(y != 0)
  72.             cout<<"i"<<y;
  73.         else
  74.             cout<<0;
  75. }
  76.  
  77. complex complex::operator++(complex z)
  78. {
  79.     complex r;
  80.     r.x = x + z.x;
  81.     r.y = y + z.y;
  82.     return r;
  83. }
  84.  
  85. complex complex::operator--(complex z)
  86. {
  87.     complex r;
  88.     r.x = x - z.x;
  89.     r.y = y - z.y;
  90.     return r;
  91. }
  92.  
  93. complex complex::operator*(complex z)
  94. {
  95.     complex r;
  96.     r.x = x * z.x - y * z.y;
  97.     r.y = y * z.x + x * z.y;
  98.     return r;
  99. }
  100.  
  101. complex complex::operator/(complex z)
  102. {
  103.     complex r;
  104.     if(z)
  105.     {
  106.         r.x = x * z.x + y * z.y;
  107.         r.y = y * z.x + x * z.y;
  108.    
  109.         int numi = z.x * z.x + z.y * z.y;
  110.         r.x = r.x / numi;
  111.         r.y = r.y / numi;
  112.     }
  113.     return r;
  114. }
  115.  
  116. complex complex::operator++()
  117. {
  118.     complex r;
  119.     r.x = x + z.x;
  120.     r.y = y + z.y;
  121.     return r;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement