-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab6_2.cpp
58 lines (49 loc) · 1.62 KB
/
lab6_2.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
#include <iostream>
#include <cmath>
using namespace std;
double deg2rad(double degree){
return ((degree/180)*M_PI);
}
double rad2deg(double rad){
return ((rad/M_PI)*180);
}
double findXComponent(double l1,double l2,double a1,double a2){
double x_l1 = (l1*cos(a1));
double x_l2 = (l2*cos(a2));
return x_l1+x_l2;
}
double findYComponent(double l1,double l2,double a1,double a2){
double y_l1 = (l1*sin(a1));
double y_l2 = (l2*sin(a2));
return y_l1+y_l2;
}
double pythagoras(double xcomp,double ycomp){
double xcomp2 = pow(xcomp,2);
double ycomp2 = pow(ycomp,2);
double r = sqrt(xcomp2+ycomp2);
return r;
}
void showResult(double l, double rad){
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "Length of the resultant vector = " << l << endl;
cout << "Direction of the resultant vector (deg) = " << rad << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
}
int main(){
double l1,l2,a1,a2,xcomp,ycomp,result_vec_length,result_vec_direction;
cout << "Enter length of the first vector: ";
cin >> l1;
cout << "Enter direction of the first vector (deg): ";
cin >> a1;
cout << "Enter length of the second vector: ";
cin >> l2;
cout << "Enter direction of the second vector (deg): ";
cin >> a2;
a1 = deg2rad(a1);
a2 = deg2rad(a2);
xcomp = findXComponent(l1,l2,a1,a2);
ycomp = findYComponent(l1,l2,a1,a2);
result_vec_length = pythagoras(xcomp,ycomp);
result_vec_direction = rad2deg(atan2(ycomp,xcomp));
showResult(result_vec_length,result_vec_direction);
}