munther_abdellatif

distacnce class

Jul 13th, 2021 (edited)
202
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. class Distance {
  6.     float x, y;
  7. public:
  8.     // constractor
  9.     Distance(float X, float Y) {
  10.         x = X; y = Y;
  11.     }
  12.     float FindDistance(Distance * point2) {
  13.         return (sqrt(pow((x - point2->x), 2) + pow((y - point2->y), 2)));
  14.     }
  15.     // getter
  16.     float getX() {
  17.         return x;
  18.     }
  19.     float getY() {
  20.         return y;
  21.     }
  22. };
  23.  
  24. int main() {
  25.     Distance p1(8,5);
  26.     Distance p2(12,8);
  27.     cout << "the distance between p1(" << p1.getX() << "," << p1.getY()<<") and p2(";
  28.     cout << p2.getX() << "," << p2.getY()<<") is :"<< p1.FindDistance(&p2);
  29.     cin.get();
  30. }
RAW Paste Data