-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab3.cpp
59 lines (53 loc) · 993 Bytes
/
lab3.cpp
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
59
/**
* @file lab3.cpp
* @author Bibhushan Saakha
* @brief print out the distance between two points
* @version 0.1
* @date 2022-02-19
*
* @copyright Copyright (c) 2022
*/
#include <iostream>
#include <cmath>
using namespace std;
class point
{
public:
float x,y;
void print()
{
cout<<"("<<x<<","<<y<<")";
}
};
class vect
{
public:
point start,end;
float distance();
void print();
};
float vect::distance()
{
return (sqrt(pow(end.x - start.x, 2) + pow(end.y - start.y, 2) * 1.0));
}
void vect:: print()
{
start.print();
cout<<" => ";
end.print();
}
int main()
{
vect v;
cout<<"Enter starting x co-ordinte:\t";
cin>>v.start.x;
cout<<"Enter starting y co-ordinte:\t";
cin>>v.start.y;
cout<<"Enter end x co-ordinte: \t";
cin>>v.end.x;
cout<<"Enter end y co-ordinte: \t";
cin>>v.end.y;
v.print();
cout<<"\n magnitude of the vector is\t"<<v.distance()<<endl;
return 0;
}