Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. class Wektor
  7. {
  8. public:
  9. double x, y;
  10.  
  11. Wektor()
  12. {
  13. this->x = 0;
  14. this->y = 0;
  15. }
  16. Wektor(double x, double y)
  17. {
  18. this->x = x;
  19. this->y = y;
  20. }
  21.  
  22. void wprowadz_x()
  23. {
  24. cout << "Podaj x: ";
  25. cin >> x;
  26. }
  27. void wprowadz_y()
  28. {
  29. cout << "Podaj y: ";
  30. cin >> y;
  31. }
  32. void wypisz()
  33. {
  34. cout << x << " " << y << endl;
  35. }
  36.  
  37. Wektor operator +(const Wektor &n)
  38. {
  39. return Wektor( this->x + n.x, this->y + n.y);
  40. }
  41. Wektor operator -(const Wektor &n)
  42. {
  43. return Wektor(this->x - n.x, this->y - n.y);
  44. }
  45. friend Wektor operator *(const Wektor &, const Wektor &);
  46.  
  47. };
  48.  
  49. Wektor operator *(const Wektor &n, const Wektor &m)
  50. {
  51. return Wektor(this->x * m.x, this->y * m.y);
  52. }
  53.  
  54. int main()
  55. {
  56. Wektor w1(7,4);
  57. Wektor w2(2,2);
  58. Wektor w3 = w1 * w2;
  59. w3.wypisz();
  60.  
  61.  
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement