Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. // zespolone.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. class LiczbyZespolone
  10. {
  11. private:
  12. int _re, _im;
  13.  
  14. public:
  15. LiczbyZespolone(int re, int im)
  16. {
  17. this->_re = re;
  18. this->_im = im;
  19. }
  20. LiczbyZespolone(const LiczbyZespolone& lzesp)
  21. {
  22. this->_re = lzesp._re;
  23. this->_im = lzesp._im;
  24. }
  25. int getRe()
  26. {
  27. return this->_re;
  28. }
  29. int getIm()
  30. {
  31. return this->_im;
  32. }
  33. void setRe(int re)
  34. {
  35. this->_re = re;
  36. }
  37. void setIm(int im)
  38. {
  39. this->_im = im;
  40. }
  41. LiczbyZespolone& operator=(const LiczbyZespolone& lzesp)
  42. {
  43. this->_re = lzesp._re;
  44. this->_im = lzesp._im;
  45. return *this;
  46. }
  47. LiczbyZespolone& operator+(const LiczbyZespolone& lzesp)
  48. {
  49. this->_re += lzesp._re;
  50. this->_im += lzesp._im;
  51. return *this;
  52. }
  53. LiczbyZespolone& operator-(const LiczbyZespolone& lzesp)
  54. {
  55. this->_re -= lzesp._re;
  56. this->_im -= lzesp._im;
  57. return *this;
  58. }
  59. /*
  60. ostream& operator<<(ostream& strm)
  61. {
  62. return strm << "(" << this->_re << " + " << this->_im << "i)";
  63. }
  64. */
  65. };
  66.  
  67. ostream& operator<<(ostream& strm, LiczbyZespolone& lzesp)
  68. {
  69. return strm << "(" << lzesp.getRe() << " + " << lzesp.getIm() << "i)";
  70. }
  71.  
  72. int main()
  73. {
  74. LiczbyZespolone lzesp1(3, 5);
  75. LiczbyZespolone lzesp2(2, 8);
  76. LiczbyZespolone lzesp3(21, 37);
  77. LiczbyZespolone lzesp4(9, 11);
  78.  
  79. cout << endl << lzesp1 << endl << lzesp2 << endl << lzesp3 << endl << lzesp4 << endl << endl;
  80.  
  81. cout << lzesp1 + lzesp2 << endl;
  82.  
  83. cout << lzesp3 - lzesp4 << endl;
  84.  
  85. getchar();
  86. return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement