-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw5.cpp
79 lines (67 loc) · 2.1 KB
/
hw5.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <string>
#include <cmath>
using std::cin;
using std::cout;
using std::endl;
using std::string;
//Convert your Triangle structure, and all your Triangle functions into a Triangle Class with methods. (each function will be a methods)
//Make use of Accessors, your Getters and Setters
class Triangle {
private:
float sA, sB, sC, angA, angB, angC, PI = 3.14159265, toDegrees = 180.;
public:
Triangle(float sideA, float sideB) {
sA = sideA;
sB = sideB;
};
Triangle(float sideA, float sideB, float angleA, float angleB) {
sA = sideA;
sB = sideB;
angA = angleA;
angB = angleB;
};
Triangle(float sideA, float sideB, float sideC, float angleA, float angleB, float angleC) {
sA = sideA;
sB = sideB;
sC = sideC;
angA = angleA;
angB = angleB;
angC = angleC;
};
float convertToDegrees() {
return (toDegrees / PI);
}
float getSideA() {
return sA;
};
float getSideB() {
return sB;
};
float getAngleA() {
return angA;
};
float getAngleB() {
return angB;
};
float calculateHypotenuse() {
float hypotenuse = sqrt(pow(sA, 2) + pow(sB, 2));
return hypotenuse;
};
float calculateAngle(float side) {
float hypo = calculateHypotenuse();
float angX = asin(side / hypo) * convertToDegrees();
return angX;
};
};
int main() {
Triangle tri1 = Triangle(3., 4.);
cout << "Triangle 1 has a hypotenuse of : " << tri1.calculateHypotenuse() << " units." << endl;
cout << "Theta 1 of Triangle 1 is " << tri1.calculateAngle(tri1.getSideA()) << " degrees." << endl;
cout << "Theta 2 of Triangle 1 is " << tri1.calculateAngle(tri1.getSideB()) << " degrees." << endl;
cout << endl;
Triangle tri2 = Triangle(5., 12.);
cout << "Triangle 1 has a hypotenuse of : " << tri2.calculateHypotenuse() << " units." << endl;
cout << "Theta 1 of Triangle 2 is " << tri2.calculateAngle(tri2.getSideA()) << " degrees." << endl;
cout << "Theta 2 of Triangle 2 is " << tri2.calculateAngle(tri2.getSideB()) << " degrees." << endl;
}