Advertisement
mithirii

przeciazanieoperatorow - objekowka

Nov 20th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <typeinfo>
  4. #include <sstream>
  5.  
  6. using namespace std;
  7.  
  8. class L_zesp{
  9. private:
  10. int re, im;
  11. public:
  12. L_zesp(double a=0, double b=0){
  13. re=a;
  14. im=b;
  15. }
  16. L_zesp operator +(L_zesp &B){
  17. L_zesp w;
  18. w.re = re + B.re;
  19. w.im = im + B.im;
  20. return w;
  21. }
  22. L_zesp operator -(L_zesp &B){
  23. L_zesp w;
  24. w.re = re - B.re;
  25. w.im = im - B.im;
  26. return w;
  27. }
  28. L_zesp operator *(L_zesp &B){
  29. L_zesp w;
  30. w.re = (re*B.re-(im*B.im));
  31. w.im = (re*B.im+(im*B.re));
  32. return w;
  33. }
  34. L_zesp operator /(L_zesp &B){
  35. L_zesp w;
  36. if((B.im*B.im+(B.re*B.re))<=0){
  37. w.re=0;
  38. w.im=0;
  39. return w;
  40. }
  41. w.re = (re*B.re+(im*B.im))/(B.im*B.im+(B.re*B.re));
  42. w.im = (im*B.re-(re*B.im))/(B.im*B.im+(B.re*B.re));
  43. return w;
  44.  
  45. }
  46. void druk(){
  47. cout<<"z=["<<re<<"+i*"<<im<<"]"<<endl;
  48. }
  49. };
  50.  
  51. int main(){
  52.  
  53. L_zesp A1(2,6),A2(7,-3),A3;
  54. A3=A1+A2;
  55. A3.druk();
  56. A3=A1-A2;
  57. A3.druk();
  58. A3=A1*A2;
  59. A3.druk();
  60. A3=A1/A2;
  61. A3.druk();
  62.  
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement