Facebook
From morov, 11 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 288
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Complex
  5. {
  6. private:
  7. int real, imag, jav;
  8. public:
  9. Complex(int r=0, int i=0)
  10. {
  11. real = r;
  12. imag = i;
  13.  
  14. }
  15.  
  16. Complex operator+(Complex obj)
  17. {
  18. Complex res;
  19. res.real = real + obj.real;
  20. res.imag = imag + obj.imag;
  21. return res;
  22. }
  23.  
  24. Complex operator-(Complex obj)
  25. {
  26. Complex res;
  27. res.real = real - obj.real;
  28. res.imag = imag - obj.imag;
  29. return res;
  30. }
  31.  
  32. Complex operator*(Complex obj)
  33. {
  34. Complex res;
  35. res.real = (real * obj.real) + (-1 * imag * obj.imag) ;
  36. res.imag = (real * obj.imag) + (imag * obj.real );
  37. return res;
  38. }
  39.  
  40.  
  41. void printAdd()
  42. {
  43. cout << real << " + i" << imag << endl;
  44. }
  45.  
  46. void printSub()
  47. {
  48. cout << real << " - i" << imag << endl;
  49. }
  50.  
  51. void printzarb()
  52. {
  53. cout << real << " +i " << imag << endl;
  54. }
  55. };
  56.  
  57. int main()
  58. {
  59. Complex c1 = Complex(10, 5);
  60. Complex c2 = Complex(2, 4);
  61.  
  62. Complex add = c1 + c2;
  63. Complex sub = c1 - c2;
  64. Complex zarb = c1 * c2;
  65. //add.printAdd();
  66. //sub.printSub();
  67. zarb.printzarb();
  68. return 0;}