forked from codebloded/BackToBasics.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistBtwtwoPoints.cpp
More file actions
45 lines (38 loc) · 855 Bytes
/
distBtwtwoPoints.cpp
File metadata and controls
45 lines (38 loc) · 855 Bytes
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
#include<iostream>
#include<math.h>
using namespace std;
class Point
{
private:
int x;
int y;
public:
Point(int a , int b);
friend int distance(Point pt1 , Point pt2);
void display(void){
cout<<"The points are ("<<x<<","<<y<<")"<<endl;
}
};
Point :: Point(int a, int b){
x=a;
y=b;
}
//Declaring the function for calculating the distance between two points
int distance(Point pt1 , Point pt2)
{
float form = ((pt2.x - pt1.x)*(pt2.x - pt1.x)) + ((pt2.y - pt1.y)*(pt2.y - pt1.y));
float dist=sqrt(form);
cout<<"The distance between the points is : "<<dist<<endl;
return 0;
}
int main()
{ Point p(0,0);
p.display();
Point p1(9,5);
p1.display();
Point pO(2,6);
pO.display();
distance(p,p1);
distance(p1,pO);
return 0;
}