forked from matkatmusic/PFMCPP_Project3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
588 lines (427 loc) · 12 KB
/
main.cpp
File metadata and controls
588 lines (427 loc) · 12 KB
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
#include <math.h> // include math functions
#include <typeinfo>
/*
Project 3 - Part 5 / 5
video: Chapter 2 - Part 10
Scope and Lifetime tasks
Create a branch named Part5
video covered:
variable scope and lifetime relative to { }
while loops
for loops()
tasks
1) add some new member functions to your types.
2) use while() or for() loops to do something interesting inside these new member functions.
a) for example: have a loop that modifies a member variable of some object created outside the loop.
b) when that member variable reaches a certain threshold, return it mid-loop.
c) maybe use function parameters to control the starting value of that member variable or control the threshold
3) call those new member functions in main()
4) use std::cout statements to print out information about what your loops did.
5) click the [run] button. Clear up any errors or warnings as best you can.
Commit your changes by clicking on the Source Control panel on the left, entering a message, and click [Commit and push].
Make a pull request after you make your first commit and pin the pull request link to our DM thread.
send me a DM to check your pull request
Wait for my code review.
example:
*/
#include <iostream>
namespace Example {
struct Bar
{
int num = 0;
Bar(int n) : num(n) { }
};
struct Foo
{
Bar scopeLifetimeFunc( int threshold, int startingVal ) //3), 4c)
{
Bar bar(startingVal); //4a)
while( bar.num < threshold ) //4a)
{
bar.num += 1; //4a)
if( bar.num >= threshold ) //4b)
return bar;
}
return Bar {-1}; //if your startingValue >= threshold, the while loop never runs
}
};
int main()
{
Foo foo;
auto bar = foo.scopeLifetimeFunc(3, 1); //5)
std::cout << "bar.num: " << bar.num << std::endl; //6)
return 0;
}
}
//call Example::main() in main()
//call Example::main()
//insert Example::main() into main() of user's repo.
/*
1)
*/
struct BoulderProblem
{
int problemGrade;
double wallAngle;
BoulderProblem() : problemGrade( 3 ), wallAngle( 30 ) {}
struct Hold
{
int holdType { 2 };
double holdSize;
double holdHeight;
Hold() : holdSize( 0.8 ), holdHeight( 1 ) {}
void printHoldInfo()
{
std::cout << "Hold Type: " << holdType;
std::cout << "\nHold Size: " << holdSize;
std::cout << "\nHold Height: " << holdHeight;
std::cout << std::endl;
}
};
double calculateDifficulty( double ropeLength );
Hold crimp;
};
double BoulderProblem::calculateDifficulty( double ropeLength )
{
std::cout << "Calculating difficulty for V" << problemGrade << " problem at a " << wallAngle << " degree incline.\n";
return ((problemGrade * crimp.holdType) / crimp.holdSize) - ropeLength;
}
/*
2)
*/
struct TopRopeRoute
{
double wallAngle { 10 };
// TopRopeRoute(){}
struct RouteGrade
{
double gradeNumber;
char gradeLetter;
RouteGrade() :
gradeNumber( 5.10 ),
gradeLetter( 100 ) // ascii letter 'd'
{}
void printGradeInfo()
{
std::cout << "Grade is: " << gradeNumber << gradeLetter << std::endl;
}
};
void buildRoute( int moves, double wallHeight );
RouteGrade hard;
};
void TopRopeRoute::buildRoute( int moves, double wallHeight = 40.36 )
{
BoulderProblem::Hold hold;
std::cout << "The wall is at a " << wallAngle << " degree incline.\n";
for ( int i = moves; i > 0; i-- ) // already have a for loop
{
hold.holdHeight = ( wallHeight / moves ) * i;
std::cout << "Hold height for move " << i << " is: " << hold.holdHeight << std::endl;
}
}
/*
3)
*/
struct Mountain
{
int height { 15 };
int routes { 20 };
// Mountain(){}
void mountainFeatures( TopRopeRoute face, BoulderProblem base, double mountain );
void constructMountain( double baseDiameter );
};
void Mountain::mountainFeatures(TopRopeRoute face, BoulderProblem base, double mountain )
{
std::cout << "Mountain height is " << height << " feet and has " << routes << " routes\n";
for ( int i = this->routes; i > 0; i-- ) // already have a for loop
{
std::cout << "Route #" << i << std::endl;
face.buildRoute( this->height, ( mountain + base.calculateDifficulty( 20.25 ) ) );
}
}
void Mountain::constructMountain( double baseDiameter )
{
TopRopeRoute wall;
BoulderProblem slab;
double mountain = M_PI* pow( baseDiameter / 2, 2 ) * this->height;
std::cout << "The mountain takes up " << mountain << " ft^3 of space.\n";
mountainFeatures( wall, slab, mountain );
}
/*
4)
*/
struct CrackClimb
{
bool isBoulder { false };
double crackWidth;
int rockColor;
CrackClimb() : crackWidth( 8 ), rockColor( 2 ) {}
int restPoint( int holdNumber, bool isRoof );
};
int CrackClimb::restPoint( int holdNumber, bool isRoof = false )
{
int x = 0;
for( int i = 0; i <= 1; i++ ) // already havea for loop
{
if( isRoof == false )
{
x = holdNumber;
}
else
{
x = holdNumber + 1;
}
}
std::cout << "The rest point is at " << x << " feet.\n";
std::cout << "The width of the crack is " << crackWidth << " in.\n";
return x;
}
/*
5)
*/
struct Shoe
{
float shoeSize;
bool isMale;
bool isBoot;
int rubberType;
int agressiveness;
Shoe() : shoeSize( 8.5f ), isMale ( true ), isBoot ( false ), rubberType ( 3 ), agressiveness ( 1 ) {}
void shoeInfo()
{
std::cout << "This size " << shoeSize << ( isBoot ? " boot" : " shoe" ) << " has type " << rubberType << " rubber.\n";
}
bool shoeFit( float painTolerance );
};
bool Shoe::shoeFit( float painTolerance ) // modified to become while loop
{
while ( painTolerance <= shoeSize )
{
std::cout << "The size " << shoeSize << " shoe doesn't fit!\n";
shoeSize = shoeSize - 0.5f;
}
std::cout << "The size " << shoeSize << " shoe fits!\n";
return true;
}
/*
6)
*/
struct RockClimber
{
double experience;
int age;
int height;
double strength;
bool isMale;
RockClimber() : experience( 25.87 ), age( 33 ), height( 167 ), strength( 99.28 ), isMale( false ) {}
void climb( BoulderProblem blue, TopRopeRoute red, CrackClimb green );
bool climberCheck ( int difficulty );
};
void RockClimber::climb( BoulderProblem blue, TopRopeRoute red, CrackClimb green )
{
bool x = experience * blue.problemGrade >= strength;
bool y = experience / red.wallAngle > 5;
bool z = strength / green.crackWidth >= experience;
if( x == true &&
y == true &&
z == true )
{
std::cout << "I'm ready to climb!\n";
}
else
{
std::cout << "I'm not ready to climb.\n";
}
}
bool RockClimber::climberCheck( int difficulty )
{
std::cout << "Your strength is: " << strength << " and you have " << experience << ".\n";
if( difficulty > strength + experience )
{
std::cout << "You do not meet the requirements to attempt this climb.\n";
return false;
}
std::cout << "You can do this climb.\n";
return true;
}
/*
7)
*/
struct Hiker
{
RockClimber leader;
float stamina { 22.45f }; // converted to float because don't need the precision
bool hasBackpack;
Hiker()
{
hasBackpack = true;
}
struct Backpack
{
bool water { true };
bool food { true };
bool rope { true };
double backpackWeight ( double waterWeight, double foodWeight, double ropeWeight );
};
void Hike( float trailLength ); // new function declaration
};
double Hiker::Backpack::backpackWeight ( double waterWeight, double foodWeight, double ropeWeight )
{
std::cout << "I've got my backpack!\n";
std::cout << "I am carrying " << ( water ? "water" : "" ) << ( food ? ", food" : "" ) << ( rope ? ", rope" : "" ) << ".\n";
return waterWeight + foodWeight + ropeWeight;
}
void Hiker::Hike( float trailLength ) // new function definition
{
int i = 0;
while ( stamina > trailLength )
{
stamina = stamina - trailLength;
i++;
}
std::cout << "I can hike this trail " << i << " times.\n";
}
/*
8)
*/
struct Gym
{
BoulderProblem pink;
TopRopeRoute orange;
CrackClimb brown;
int rating;
Gym()
{
rating = 5;
}
void setClimbs( int climbsCount, int difficultySpread );
};
void Gym::setClimbs( int climbsCount, int difficultySpread )
{
std::cout << "This gym's rating is: " << rating << std::endl;
for ( int i = climbsCount; i > 0; i-- ) // already have for loop
{
std::cout << "Gym Route# " << i << std::endl;
orange.buildRoute( 40, orange.wallAngle * difficultySpread );
}
}
/*
9)
*/
struct Exercise
{
int muscleGroup;
int difficulty;
bool useWeight { false };
Exercise() : muscleGroup( 6 ), difficulty( 3 ) {}
void doExercise ( RockClimber trainee );
bool exerciseComplete ( int strength, double stamina );
};
void Exercise::doExercise ( RockClimber trainee )
{
int x = difficulty * 10;
int setsPossible = 0;
for ( double i = trainee.strength; i > x; i = i - x ) // already have for loop
{
setsPossible++;
}
std::cout << "This exercise is for muscle group " << muscleGroup << " and " << ( useWeight ? "uses weights.\n" : "does not use weights.\n" );
std::cout << "I did " << setsPossible << " sets of the exercise.\n";
}
bool Exercise::exerciseComplete ( int strength, double stamina )
{
bool x = strength + stamina > muscleGroup * (difficulty * 10);
if( x )
{
std::cout << "I completed the exercise.\n";
}
std::cout << "I couldn't do it.\n";
return x;
}
/*
10)
*/
struct TrainingPlan
{
Exercise pushUp;
Exercise pullUp;
Exercise shoulderPress;
Exercise deadLift;
Exercise squat;
// TrainingPlan() {};
void createPlan( int intensity, int rounds, double restPeriod );
};
void TrainingPlan::createPlan ( int intensity, int rounds, double restPeriod )
{
RockClimber trainee;
restPeriod = restPeriod - intensity;
for( int i = rounds; i > 0; i-- ) // already have for loop
{
pushUp.doExercise( trainee );
pullUp.doExercise( trainee );
shoulderPress.doExercise( trainee );
deadLift.doExercise( trainee );
squat.doExercise( trainee );
std::cout << "Round Complete.\n\n";
}
}
void divider()
{
std::cout << "\n**=============================**\n\n";
}
int main()
{
Example::main();
//1
divider();
BoulderProblem blue;
BoulderProblem::Hold crimp;
double difficulty = blue.calculateDifficulty( 2.22 );
crimp.printHoldInfo();
std::cout << "Difficulty: " << difficulty << std::endl;
//2
divider();
TopRopeRoute red;
TopRopeRoute::RouteGrade medium;
red.buildRoute(10, 40.36);
medium.printGradeInfo();
//3
divider();
Mountain dingbat;
dingbat.constructMountain( 33.456 );
//4
divider();
CrackClimb green;
green.restPoint( 32, false );
//5
divider();
Shoe scarpa;
scarpa.shoeFit( 8 );
scarpa.shoeInfo();
//6
divider();
RockClimber Drew;
Drew.climberCheck( 200 );
Drew.climb(blue, red, green);
//7
divider();
Hiker::Backpack JanSport;
JanSport.backpackWeight( 10.32, 34.32, 10.12 );
Hiker Dan; // new hiker
Dan.Hike( 4.5f ); // new function
//8
divider();
Gym local;
local.setClimbs( 2, 3 );
//9
divider();
Exercise pullUp;
pullUp.doExercise( Drew );
pullUp.exerciseComplete( 15, 22.56 );
//10
divider();
TrainingPlan DrewsPlan;
DrewsPlan.createPlan( 3, 3, 33.56 );
divider();
std::cout << "good to go!" << std::endl;
}