Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. class Complex {
  8. private:
  9. int Rl;
  10. int Im;
  11. public:
  12. Complex(int x, int y) {
  13. Rl = x;
  14. Im = y;
  15. }
  16.  
  17. void wypisz() {
  18. cout << Rl << "+j*" << Im << endl;
  19. }
  20.  
  21. int CzRzeczywista() {
  22. return Rl;
  23. }
  24.  
  25. int CzImaginowana() {
  26. return Im;
  27. }
  28.  
  29. friend Complex& operator +(Complex, Complex);
  30. friend ostream& operator <<(ostream&, Complex);
  31. };
  32.  
  33. Complex& operator +(Complex x, Complex y) {
  34. int tmp1 = x.CzRzeczywista() + y.CzRzeczywista();
  35. int tmp2 = x.CzImaginowana() + y.CzImaginowana();
  36. Complex *obiekt = new Complex(tmp1, tmp2);
  37. return (*obiekt);
  38. }
  39.  
  40. ostream& operator <<(ostream &str, Complex x) {
  41. str << x.CzRzeczywista() << "+j*" << x.CzImaginowana();
  42. return str;
  43. }
  44.  
  45. int main() {
  46. Complex c1(20, 30), c2(40, 10);
  47. cout << "c1="; c1.wypisz();
  48. cout << "c2="; c2.wypisz();
  49. cout << "c1+c2=" << c1 + c2 << endl;
  50. Complex *c3 = new Complex(1, 7);
  51. cout << "c3 wskazuje na obiekt="; c3->wypisz();
  52. cout << "c3 wskazuje na obiekt=" << *c3 << endl;
  53. Complex c4 = c1 + c2;
  54. cout << "c4=" << c4;
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement