Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- class Distance {
- float x, y;
- public:
- // constractor
- Distance(float X, float Y) {
- x = X; y = Y;
- }
- float FindDistance(Distance * point2) {
- return (sqrt(pow((x - point2->x), 2) + pow((y - point2->y), 2)));
- }
- // getter
- float getX() {
- return x;
- }
- float getY() {
- return y;
- }
- };
- int main() {
- Distance p1(8,5);
- Distance p2(12,8);
- cout << "the distance between p1(" << p1.getX() << "," << p1.getY()<<") and p2(";
- cout << p2.getX() << "," << p2.getY()<<") is :"<< p1.FindDistance(&p2);
- cin.get();
- }
Add Comment
Please, Sign In to add comment