-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw2.cpp
41 lines (32 loc) · 1.25 KB
/
hw2.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
#include <iostream>
#include <string>
#include <cmath>
using std::cin;
using std::cout;
using std::endl;
using std::string;
// NOTE: Hardcode in side A = 3 and side B = 4
//Write a program that from two lengths of a right triangle calculates the hypotenuse and the two adjacent angles.
//The hypotenuse function, and each angle function should all be separate functions. Hint: Don't forget to return the answers from the functions.
double calculateHypotenuse(double a, double b);
double calculateAngle(double x, double hypotenuse);
int main() {
double side_a = 3;
double side_b = 4;
cout << "With a side a of " << side_a << " and a side b of " << side_b << endl;
double hypo = calculateHypotenuse(side_a, side_b);
cout << "The hypotenuse is = " << hypo << endl;
double angle_A = calculateAngle(side_a, hypo);
double angle_B = calculateAngle(side_b, hypo);
cout << "The angle 1 is = " << angle_A << " degrees" << endl;
cout << "The angle 2 is = " << angle_B << " degrees" << endl;
}
double calculateHypotenuse(double a, double b) {
double hypotenuse = sqrt(pow(a, 2) + pow(b, 2));
return hypotenuse;
}
double calculateAngle(double x, double hypotenuse) {
double PI = 3.14159265;
double angX = asin(x / hypotenuse) * (180 / PI);
return angX;
}