#include <iostream>
#include <math.h>
using namespace std;
class Point{
float x, y;
public:
Point():x(0), y(0){}
Point(float a, float b): x(a), y(b){}
friend float distance(const Point&, const Point&);
};
float distance(const Point& a, const Point& b){
return sqrt((a.x - b.x)*(a.x - b.x)+(a.y - b.y)*(a.y - b.y));
}
class DArray{
int size;
Point *ptr;
public:
DArray(int size){
this->size = size;
ptr = new Point[size];
}
~DArray(){
delete ptr;
ptr = NULL;
}
Point &operator[](int i){
return ptr[i];
}
};
int main(){
DArray arr(3);
arr[0] = Point(0, 0);
arr[1] = Point(3, 4);
arr[2] = Point(-12, 5);
cout<<distance(arr[0], arr[1])<<endl;
cout<<distance(arr[1], arr[2])<<endl;
cout<<distance(arr[2], arr[0])<<endl;
return 0;
}
Comments
Leave a comment