1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include<iostream>
#include<math.h>
using namespace std;
class point
{
public:
point(int x_i,int y_i){x=x_i;y=y_i;};
~point(){};
void setc(int x_l,int y_l){x=x_l,y=y_l;};
int getc_x()const{return x;};
int getc_y()const{return y;};
private:
int x;
int y;
};
float distance(point,point);
int main()
{
int x,y;
float d;
point a(0,0),b(0,0);
cout<<"Insert x coordinate of point 1:\n";
cin>>x;
cin.ignore();
cout<<"\nInsert y coordinate of point 1:\n";
cin>>y;
a.setc(x,y);
cout<<"\nInsert x coordinate of point 2:\n";
cin>>x;
cout<<"\nInsert y coordinate of point 2:\n";
cin>>y;
b.setc(x,y);
d=distance(a,b);
cout<<"\nThe Distance between them is "<<d;
return 0;
}
float distance(point a,point b)
{
float d;
int x1,x2,y1,y2,q,w,e,r;
x1=a.getc_x();
x2=b.getc_x();
y1=a.getc_y();
y2=b.getc_y();
q=(x1-x2)*(x1-x2);
w=(y1-y2)*(y1-y2);
e=q+w;
d=sqrt(e);
return d;
}
|