-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path30parame_construct.cpp
More file actions
42 lines (37 loc) · 862 Bytes
/
Copy path30parame_construct.cpp
File metadata and controls
42 lines (37 loc) · 862 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
#include<iostream>
#include<math.h>
using namespace std;
class point
{
int a, b;
public:
point(int x, int y) //--> this is a parameterized constructor as it takes 2 parameters
{
a = x;
b = y;
}
void display()
{
cout<<"x coordinate : "<<a<<" y coordinate : "<<b<<endl;
}
friend float distance(point, point);
};
float distance(point p1, point p2)
{
int xsec = (p1.a - p2.a)*(p1.a - p2.a);
int ysec = (p1.b - p2.b)*(p1.b - p2.b);
int segment = xsec + ysec;
return sqrt(segment);
}
int main()
{
//implicit constructor call
point p1(2, 4);
//explicit constructor call
point p2 = point(5, 6);
p1.display();
p2.display();
float distancep1p2 = distance(p1, p2);
cout<<"Distance between point 1 and point 2 = "<<distancep1p2<<" units"<<endl;
return 0;
}