Bob103

класс

May 30th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5. class Vector
  6. {
  7. private: int x, y;
  8.  
  9. public: Vector() : x(0), y(0)
  10. {
  11.  
  12. }
  13. Vector(int x, int y) :x(x), y(y)
  14. {
  15. }
  16.  
  17. void ShowData()
  18. {
  19. cout << "(" << x << "," << y << ")";
  20. cout << endl;
  21. }
  22. double GetDlina()
  23. {
  24. return sqrt(x*x + y*y);
  25. }
  26. bool operator== (const Vector &v1)
  27. {
  28. return (x == v1.x && y == v1.y);
  29. }
  30. Vector add(Vector d)
  31. {
  32. Vector result;
  33. result.x = x + d.x;
  34. result.y = y + d.y;
  35. return result;
  36. }
  37.  
  38. Vector sub(Vector d)
  39. {
  40. Vector result;
  41. result.x = x - d.x;
  42. result.y = y - d.y;
  43. return result;
  44. }
  45.  
  46. double scal(Vector right)
  47. {
  48. return x*right.x + y*right.y;
  49. }
  50.  
  51. };
  52. int main()
  53. {
  54. int x, y, x2, y2;
  55.  
  56. cout << "Enter x && y=";
  57. cin >> x >> y;
  58. Vector v(x, y);
  59.  
  60. cout << "Enter x2 && y2=";
  61. cin >> x2 >> y2;
  62. Vector v1(x2, y2);
  63.  
  64. v.ShowData();
  65. v1.ShowData();
  66. cout << v.GetDlina() << endl;
  67. cout << v1.GetDlina() << endl;
  68. cout << v.scal(v1) << endl;
  69. system("pause");
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment