-
Notifications
You must be signed in to change notification settings - Fork 0
/
Alpha
300 lines (260 loc) · 7.73 KB
/
Alpha
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
// Reference for TCNJ Students
#include <iostream>
#include <string>
#include <cmath>
#include <math.h>
using namespace std;
int main() {
// Declare all and set double variables to null state
string unitType;
int caseCheck, caseNum, forceNum;
double angle1 = 0.0, angle2 = 0.0, angle3 = 0.0, angle4 = 0.0, angle5 = 0.0;
double force1 = 0.0, force2 = 0.0, force3 = 0.0, force4 = 0.0, force5 = 0.0;
double f1x = 0.0, f2x = 0.0, f3x = 0.0, f4x = 0.0, f5x = 0.0, f1y = 0.0, f2y = 0.0, f3y = 0.0, f4y = 0.0, f5y = 0.0;
double sumFx = 0.0, sumFy = 0.0, resultant = 0.0, degrees = 0.0;
char axisAngle1, axisAngle2, axisAngle3, axisAngle4, axisAngle5;
char xPositiveF1, xPositiveF2, xPositiveF3, xPositiveF4, xPositiveF5, yPositiveF1, yPositiveF2, yPositiveF3, yPositiveF4, yPositiveF5;
// Introduction
cout << "\n\nThis program will determine the resultant of concurrent system of forces\n" << endl;
// Get number of cases
cout << "How many cases/problems?: ";
cin >> caseNum;
// Loop set of times for caseNum
for (caseCheck = 1 ; caseCheck <= caseNum ; caseCheck++) {
// Get unit type
cout << "\nWhat is the unit type for case " << caseCheck << "?: ";
cin >> unitType;
// Get number of forces
cout << "How many forces are there for case " << caseCheck << "? (Max 5): ";
cin >> forceNum;
cout << endl;
// Get forces
switch(forceNum){
case(5):
cout << "What is F5?: ";
cin >> force5;
case(4):
cout << "What is F4?: ";
cin >> force4;
case(3):
cout << "What is F3?: ";
cin >> force3;
case(2):
cout << "What is F2?: ";
cin >> force2;
case(1):
cout << "What is F1?: ";
cin >> force1;
break;
}
cout << endl;
// Get angles
switch(forceNum) {
case(5):
cout << "What angle is F5?: ";
cin >> angle5;
cout << "Where is angle respect to?: ";
cin >> axisAngle5;
case(4):
cout << "What angle is F4?: ";
cin >> angle4;
cout << "Where is angle respect to?: ";
cin >> axisAngle4;
case(3):
cout << "What angle is F3?: ";
cin >> angle3;
cout << "Where is angle respect to?: ";
cin >> axisAngle3;
case(2):
cout << "What angle is F2?: ";
cin >> angle2;
cout << "Where is angle respect to?: ";
cin >> axisAngle2;
case(1):
cout << "What angle is F1?: ";
cin >> angle1;
cout << "Where is angle respect to?: ";
cin >> axisAngle1;
break;
}
cout << endl;
// Ask if forces is positive/negative respect to x/y axis
switch(forceNum){
case(5):
cout << "Is F5 positive to the x-axis? (Y/N): ";
cin >> xPositiveF5;
cout << "Is F5 positive to the y-axis? (Y/N): ";
cin >> yPositiveF5;
case(4):
cout << "Is F4 positive to the x-axis? (Y/N): ";
cin >> xPositiveF4;
cout << "Is F4 positive to the y-axis? (Y/N): ";
cin >> yPositiveF4;
case(3):
cout << "Is F3 positive to the x-axis? (Y/N): ";
cin >> xPositiveF3;
cout << "Is F3 positive to the y-axis? (Y/N): ";
cin >> yPositiveF3;
case(2):
cout << "Is F2 positive to the x-axis? (Y/N): ";
cin >> xPositiveF2;
cout << "Is F2 positive to the y-axis? (Y/N): ";
cin >> yPositiveF2;
case(1):
cout << "Is F1 positive to the x-axis? (Y/N): ";
cin >> xPositiveF1;
cout << "Is F1 positive to the y-axis? (Y/N): ";
cin >> yPositiveF1;
break;
}
cout << endl;
// Convert degrees to radians (C++ interprets inputs as degrees)
switch(forceNum) {
case(5):
angle5 = angle5 * M_PI / 180;
case(4):
angle4 = angle4 * M_PI / 180;
case(3):
angle3 = angle3 * M_PI / 180;
case(2):
angle2 = angle2 * M_PI / 180;
case(1):
angle1 = angle1 * M_PI / 180;
break;
}
// Calculate
switch(forceNum) {
case(5):
if (axisAngle5 == 'x' || axisAngle5 == 'X') {
f5x = force5 * cos(angle5);
f5y = force5 * sin(angle5);
}
else {
f5x = force5 * sin(angle5);
f5y = force5 * cos(angle5);
}
case(4):
if (axisAngle4 == 'x' || axisAngle4 == 'X') {
f4x = force4 * cos(angle4);
f4y = force4 * sin(angle4);
}
else {
f4x = force4 * sin(angle4);
f4y = force4 * cos(angle4);
}
case(3):
if (axisAngle3 == 'x' || axisAngle3 == 'X') {
f3x = force3 * cos(angle3);
f3y = force3 * sin(angle3);
}
else {
f3x = force3 * sin(angle3);
f3y = force3 * cos(angle3);
}
case(2):
if (axisAngle2 == 'x' || axisAngle2 == 'X') {
f2x = force2 * cos(angle2);
f2y = force2 * sin(angle2);
}
else {
f2x = force2 * sin(angle2);
f2y = force2 * cos(angle2);
}
case(1):
if (axisAngle1 == 'x' || axisAngle1 == 'X') {
f1x = force1 * cos(angle1);
f1y = force1 * sin(angle1);
}
else {
f1x = force1 * sin(angle1);
f1y = force1 * cos(angle1);
}
break;
}
// Convert to negative if applicable
if (xPositiveF5 == 'n' || xPositiveF5 == 'N') {
f5x = f5x * -1.0;
}
if (xPositiveF4 == 'n' || xPositiveF4 == 'N') {
f4x = f4x * -1.0;
}
if (xPositiveF3 == 'n' || xPositiveF3 == 'N') {
f3x = f3x * -1.0;
}
if (xPositiveF2 == 'n' || xPositiveF2 == 'N') {
f2x = f2x * -1.0;
}
if (xPositiveF1 == 'n' || xPositiveF1 == 'N') {
f1x = f1x * -1.0;
}
if (yPositiveF5 == 'n' || yPositiveF5 == 'N') {
f5y = f5y * -1.0;
}
if (yPositiveF4 == 'n' || yPositiveF4 == 'N') {
f4y = f4y * -1.0;
}
if (yPositiveF3 == 'n' || yPositiveF3 == 'N') {
f3y = f3y * -1.0;
}
if (yPositiveF2 == 'n' || yPositiveF2 == 'N') {
f2y = f2y * -1.0;
}
if (yPositiveF1 == 'n' || yPositiveF1 == 'N') {
f1y = f1y * -1.0;
}
// Calculate sum of Fx and Fy
sumFx = f5x + f4x + f3x + f2x + f1x;
sumFy = f5y + f4y + f3y + f2y + f1y;
// Calculate resultant
resultant = sqrt(pow(sumFx,2) + pow(sumFy,2));
// Convert sumFx and sumFy to positive if both are negative
if (sumFx < 0 && sumFy < 0) {
sumFx = sumFx * -1.0;
sumFy = sumFy * -1.0;
}
// Calculate degrees
degrees = atan2(sumFy, sumFx);
degrees = degrees * 180 / M_PI;
// Output results
cout << "\nThe resultant force is " << resultant << "." << endl;
cout << "The angle is " << degrees << " degrees." << endl;
// Calculate and output quadrant location
if (degrees > 0 && degrees < 90) {
cout << "It resides in the first quadrant." << endl;
}
else if (degrees > 90.0 && degrees < 180.0) {
cout << "It resides in the second quadrant." << endl;
}
else if (degrees > 180.0 && degrees < 270.0) {
cout << "It resides in the third quadrant." << endl;
}
else if (degrees > 270.0 && degrees < 360.0) {
cout << "It resides in the fourth quadrant." << endl;
}
else if (degrees == 90.0) {
cout << "It resides between the first and second quadrant." << endl;
}
else if (degrees == 180.0) {
cout << "It resides between the second and third quadrant." << endl;
}
else if (degrees == 270.0) {
cout << "It resides between the third and fourth quadrant." << endl;
}
else if (degrees == 360.0) {
cout << "It resides between the fourth and first quadrant." << endl;
}
else {
cout << "The quadrant location can not be determined." << endl;
}
cout << endl << endl;
// Reset double values to null state
angle1 = 0.0, angle2 = 0.0, angle3 = 0.0, angle4 = 0.0, angle5 = 0.0;
force1 = 0.0, force2 = 0.0, force3 = 0.0, force4 = 0.0, force5 = 0.0;
f1x = 0.0, f2x = 0.0, f3x = 0.0, f4x = 0.0, f5x = 0.0, f1y = 0.0, f2y = 0.0, f3y = 0.0, f4y = 0.0, f5y = 0.0;
sumFx = 0.0, sumFy = 0.0, resultant = 0.0, degrees = 0.0;
axisAngle1 = '\0', axisAngle2 = '\0', axisAngle3 = '\0', axisAngle4 = '\0', axisAngle5 = '\0';
xPositiveF1 = '\0', xPositiveF2 = '\0', xPositiveF3 = '\0', xPositiveF4 = '\0', xPositiveF5 = '\0';
yPositiveF1 = '\0', yPositiveF2 = '\0', yPositiveF3 = '\0', yPositiveF4 = '\0', yPositiveF5 = '\0';
}
return 0;
}