#include<iostream>
#include<bits/stdc++.h>
using namespace std;
class Point{
public:
float x,y;
Point(float a, float b)
{
x=a;
y=b;
}
friend float distance(Point* a, Point* b);
void display()
{
cout<<"x : "<<x<<endl;
cout<<"y : "<<y<<endl;
}
};
float distance(Point* a, Point* b)
{
return sqrt(((b->x - a->x)(b->x - a->x)) + (((b->y - a->y)(b->y - a->y))));
}
class DArray{
public:
int *size;
Point* point;
DArray()
{
}
Darray(int n)
{
size = new int(n);
}
~DArray()
{
}
};
int main()
{
cout<<"Enter number of points : ";
int n;
cin>>n;
DArray arr[n];
for(int i=0; i<n; i++)
{
float a,b;
cout<<"Enter value of x : ";
cin>>a;
cout<<"Enter value of y : ";
cin>>b;
cout<<endl;
Point *p = new Point(a,b);
arr[i].point = p;
}
cout<<endl<<endl;
for(int i=0; i<n; i++)
{
for(int j=i+1; j<n; j++)
{
float dist = distance(arr[i].point,arr[j].point);
cout<<"Distance b/w ("<<arr[i].point->x<<","<<arr[i].point->y<<") and ("<<arr[j].point->x<<","<<arr[j].point->y<<") is : "<<dist<<endl;
}
}
}
Comments
Leave a comment