-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
551 lines (459 loc) · 14.8 KB
/
main.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
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
//
// main.cpp
// 2012PA1
//
// Created by Tony Wai Sum JI on 2/9/2019.
// Copyright © 2019 Tony Wai Sum JI. All rights reserved.
//
#include <iostream>
#include "buddy.h"
#include "workout.h"
#include "food.h"
#include "relaxation.h"
#include "workoutenvironment.h"
#include "restaurant.h"
#include "relaxplan.h"
using namespace std;
void test_food();
void test_relaxation();
void test_workout();
void test_relaxplan();
void test_buddy();
void test_restaurant();
void test_workoutenvironment();
int main() {
cout<<"Test functions are carried out sequentially, thus later results will be affected by previous ones. \nIf you want to debug a function, read main.cpp and make sure its 'previous' ones work well.\n"<<endl;
cout<<"This program only tests part of the assignment's requirements. If you want to get full marks, you need to change main() and do some testing yourself.\n"<<endl;
int part_to_test = -1;
while (part_to_test) {
cout<<"Select a part you want to test: "<<endl;
cout<<"\t1. Food"<<endl;
cout<<"\t2. Relaxation"<<endl;
cout<<"\t3. Workout"<<endl;
cout<<"\t4. RelaxPlan"<<endl;
cout<<"\t5. Buddy"<<endl;
cout<<"\t6. Restaurant"<<endl;
cout<<"\t7. WorkoutEnvironment"<<endl;
cout<<"\t8. All of the above"<<endl;
cout<<"\t0. Exit"<<endl;
cout<<"\nInput: ";
string input_str = "default string";
cin>>input_str;
cout<<endl;
try {
part_to_test = stoi(input_str);
} catch (...) {
part_to_test = -1;
}
switch (part_to_test) {
case 1:
test_food();
break;
case 2:
test_relaxation();
break;
case 3:
test_workout();
break;
case 4:
test_relaxplan();
break;
case 5:
test_buddy();
break;
case 6:
test_restaurant();
break;
case 7:
test_workoutenvironment();
break;
case 8:
test_food();
test_relaxation();
test_workout();
test_relaxplan();
test_buddy();
test_restaurant();
test_workoutenvironment();
break;
case 0:
break;
default:
cout<<"Invalid input, try again."<<endl<<endl;
break;
}
}
}
void test_food() {
cout<<"------- Food Class -------"<<endl<<endl;
cout<<"Constructor: "<<endl;
Food food0 = Food("Egg White Powder", 0, 20, 5);
food0.print_details(1);
cout<<endl;
cout<<"get_name: "<<endl;
cout<<"\tname: "<<food0.get_name()<<endl;
cout<<endl;
cout<<"get_fat_gain: "<<endl;
cout<<"\tfat_gain: "<<food0.get_fat_gain()<<endl;
cout<<endl;
cout<<"get_protein_gain:"<<endl;
cout<<"\tprotein_gain: "<<food0.get_protein_gain()<<endl;
cout<<endl;
cout<<"get_price:"<<endl;
cout<<"\tprice: "<<food0.get_price()<<endl;
cout<<endl;
cout<<"------- Food Class Completed! -------"<<endl<<endl;
}
void test_relaxation() {
cout<<"------- Relaxation Class -------"<<endl<<endl;
cout<<"Constructor: "<<endl;
Relaxation r = Relaxation("Sleep 24 hours", 1000);
r.print_details(1);
cout<<endl;
cout<<"get_name: "<<endl;
cout<<"\tname: "<<r.get_name()<<endl;
cout<<endl;
cout<<"get_energy_gain: "<<endl;
cout<<"\tenergy_gain: "<<r.get_energy_gain()<<endl;
cout<<endl;
cout<<"get_next: (currently NULL)"<<endl;
cout<<"\tnext: "<<r.get_next()<<endl;
cout<<endl;
cout<<"set_next: "<<endl;
Relaxation* r1 = new Relaxation("Sleep 48 hours", 1500);
r.set_next(r1);
r.print_details(1);
cout<<endl;
delete r1;
cout<<"------- Relaxation Class Completed! -------"<<endl<<endl;
}
void test_workout() {
cout<<"------- Workout Class -------"<<endl<<endl;
cout<<"Constructor: "<<endl;
Workout w = Workout("Wrestling", -20, -5, -50);
w.print_details(1);
cout<<endl;
cout<<"get_name: "<<endl;
cout<<"\tname: "<<w.get_name()<<endl;
cout<<endl;
cout<<"get_fat_change: "<<endl;
cout<<"\tfat_change: "<<w.get_fat_change()<<endl;
cout<<endl;
cout<<"get_muscle_change: "<<endl;
cout<<"\tmuscle_change: "<<w.get_muscle_change()<<endl;
cout<<endl;
cout<<"get_energy_change: "<<endl;
cout<<"\tenergy_change: "<<w.get_energy_change()<<endl;
cout<<endl;
cout<<"------- Workout Class Completed! -------"<<endl<<endl;
}
void test_relaxplan() {
cout<<"------- RelaxPlan Class -------"<<endl<<endl;
cout<<"Constructor: "<<endl<<endl;
RelaxPlan rp = RelaxPlan("Dayoff!");
rp.print_details(1);
cout<<endl;
cout<<"get_head: (currently NULL)"<<endl;
cout<<"\thead: "<<rp.get_head()<<endl;
cout<<endl;
Relaxation r0 = Relaxation("Take a walk", 15);
Relaxation r1 = Relaxation("Steam start!", 20);
Relaxation r2 = Relaxation("Afternoon nap", 30);
Relaxation r3 = Relaxation("Nintendo Switch Start!", 25);
Relaxation r4 = Relaxation("Chat with GF/BF/F/ALONE", 10);
cout<<"add_to_start: (two times)"<<endl<<endl;
rp.addToStart(r1);
rp.addToStart(r0);
rp.print_details(1);
cout<<endl;
cout<<"add_to_end: (three times)"<<endl<<endl;
rp.addToEnd(r2);
rp.addToEnd(r3);
rp.addToEnd(r4);
rp.print_details(1);
cout<<endl;
cout<<"remove: 6; -1; (should not change)"<<endl<<endl;
rp.remove(6);
rp.remove(-1);
rp.print_details(1);
cout<<endl;
cout<<"remove: 4"<<endl<<endl;
rp.remove(4);
rp.print_details(1);
cout<<endl;
cout<<"remove: 1"<<endl<<endl;
rp.remove(1);
rp.print_details(1);
cout<<endl;
cout<<"remove: 0; 0; 0;"<<endl<<endl;
rp.remove(0);
rp.remove(0);
rp.remove(0);
rp.print_details(1);
cout<<endl;
cout<<"Copy Constructor: "<<endl<<endl;
rp.addToEnd(r0);
rp.addToEnd(r1);
rp.addToEnd(r2);
rp.addToEnd(r3);
rp.addToEnd(r4);
cout<<"RelaxPlan to be copied: "<<endl<<endl;
rp.print_details(1);
cout<<endl;
cout<<"RelaxPlan copied: "<<endl<<endl;
cout<<"Make sure the Relaxations' addresses are different from above!"<<endl<<endl;
RelaxPlan rpc = RelaxPlan(rp);
rpc.print_details(1);
cout<<endl;
cout<<"------- RelaxPlan Class Completed! -------"<<endl<<endl;
}
void test_buddy() {
cout<<"------- Buddy Class -------"<<endl<<endl;
cout<<"Constructor: "<<endl;
Buddy* b1 = new Buddy("Mona", 40, 600, 200, 8000);
b1->print_details(1);
cout<<endl;
cout<<"get_name: "<<endl;
cout<<"\tname: "<<b1->get_name()<<endl;
cout<<endl;
cout<<"get_fat: "<<endl;
cout<<"\tfat: "<<b1->get_fat()<<endl;
cout<<endl;
cout<<"get_muscle: "<<endl;
cout<<"\tmuscle: "<<b1->get_muscle()<<endl;
cout<<endl;
cout<<"get_energy: "<<endl;
cout<<"\tenergy: "<<b1->get_energy()<<endl;
cout<<endl;
cout<<"get_money: "<<endl;
cout<<"\tmoney: "<<b1->get_money()<<endl;
cout<<endl;
cout<<"set_fat: 100"<<endl;
b1->set_fat(100);
cout<<"\tnew fat: "<<b1->get_fat()<<endl;
cout<<endl;
cout<<"set_muscle: 700"<<endl;
b1->set_muscle(700);
cout<<"\tnew muscle: "<<b1->get_muscle()<<endl;
cout<<endl;
cout<<"set_energy: 10"<<endl;
b1->set_energy(10);
cout<<"\tnew energy: "<<b1->get_energy()<<endl;
cout<<endl;
cout<<"set_money: 50000"<<endl;
b1->set_money(50000);
cout<<"\tnew money: "<<b1->get_money()<<endl;
cout<<endl;
cout<<"earn_money(500, 10): "<<endl;
b1->earn_money(500, 10);
cout<<"\tnew money: "<<b1->get_money()<<endl;
cout<<endl;
cout<<"Make sure your Relaxation & RelaxPlan class works, otherwise comment out the test functions below."<<endl<<endl;
cout<<"gain_energy: "<<endl<<endl;
RelaxPlan rp = RelaxPlan("Dayoff!");
Relaxation r0 = Relaxation("Take a walk", 15);
Relaxation r1 = Relaxation("Steam start!", 20);
Relaxation r2 = Relaxation("Afternoon nap", 30);
Relaxation r3 = Relaxation("Nintendo Switch Start!", 25);
Relaxation r4 = Relaxation("Chat with GF/BF/F/ALONE", 10);
Relaxation r5 = Relaxation("Sleep", 50);
rp.addToEnd(r0);
rp.addToEnd(r1);
rp.addToEnd(r2);
rp.addToEnd(r3);
rp.addToEnd(r4);
rp.addToEnd(r5);
cout<<"Before Gain Energy: "<<endl<<endl;
rp.print_details(1);
b1->print_details(1);
cout<<endl<<"After Gain Energy: "<<endl<<endl;
b1->gain_energy(rp);
b1->print_details(1);
cout<<endl;
delete b1;
cout<<"------- Buddy Class Completed!-------"<<endl<<endl;
}
void test_restaurant() {
cout<<"------- Restaurant Class -------"<<endl<<endl;
cout<<"Constructor: "<<endl<<endl;
Restaurant r = Restaurant("Silver Rice Bowl");
r.print_details(1);
cout<<endl;
cout<<"get_name: "<<endl;
cout<<"\tname: "<<r.get_name()<<endl;
cout<<endl;
cout<<"add_meal: "<<endl<<endl;
Food f0 = Food("Egg White Powder", 0, 20, 5);
Food f1 = Food("Banana", 0, 5, 3);
Food f2 = Food("Double Cheese Burger With French Fries", 1000, 10, 45);
Food f3 = Food("Air", 0, 0, 0);
Food f4 = Food("Ramen with Deep Fried Chicken", 30, 10, 30);
cout<<"\tadd 2 meals"<<endl<<endl;
r.add_meal(f0);
r.add_meal(f1);
r.print_details(2);
cout<<endl;
cout<<"\tadd 5 meals"<<endl<<endl;
r.add_meal(f2);
r.add_meal(f3);
r.add_meal(f4);
r.print_details(2);
cout<<endl;
cout<<"remove_first_meal: "<<endl<<endl;
cout<<"\t2 times: "<<endl;
r.remove_first_meal();
r.remove_first_meal();
r.print_details(2);
cout<<endl;
cout<<"\t4 times: "<<endl<<endl;
r.remove_first_meal();
r.remove_first_meal();
r.print_details(2);
cout<<endl;
cout<<"add_meal: (Circular add 2 meals)"<<endl<<endl;
r.add_meal(f0);
r.add_meal(f1);
r.print_details(1);
cout<<endl;
cout<<"remove_last_meal: "<<endl<<endl;
cout<<"\t 2 times: "<<endl;
r.remove_last_meal();
r.remove_last_meal();
r.print_details(2);
cout<<endl;
cout<<"\t 4 times: (4th time should return false and do nothing)"<<endl<<endl;
r.remove_last_meal();
r.remove_last_meal();
r.print_details(2);
cout<<endl;
cout<<"Make sure your Buddy class works, otherwise comment out the lines below"<<endl;
cout<<"serve_meal:"<<endl<<endl;
cout<<"Before serving: "<<endl;
Buddy* b1 = new Buddy("Van", 50, 500, 100, 10000);
r.add_meal(f0);
r.add_meal(f1);
r.add_meal(f2);
r.print_details(1);
cout<<endl;
b1->print_details(1);
cout<<endl;
int meal_index = 0;
r.serve_meal(b1, meal_index);
cout<<"After serving meal number "<<meal_index<<": "<<endl;
b1->print_details(1);
cout<<endl;
delete b1;
cout<<"------- Restaurant Class Completed! -------"<<endl<<endl;
}
void test_workoutenvironment() {
cout<<"------- WorkoutEnvironment Class Completed! -------"<<endl<<endl;
cout<<"Constructor: "<<endl<<endl;
WorkoutEnvironment we = WorkoutEnvironment("My House", 20, 5);
we.print_details(1);
cout<<endl;
cout<<"get_name: "<<endl<<endl;
cout<<"\tname: "<<we.get_name()<<endl;
cout<<endl;
cout<<"get_entry_fee: "<<endl<<endl;
cout<<"\tentry_fee: "<<we.get_entry_fee()<<endl;
cout<<endl;
Workout w0 = Workout("Wrestling", -20, -5, -50);
Workout w1 = Workout("Bicep Dumbbell Curl", -5, 15, -10);
Workout w2 = Workout("Machine Shoulder Press", -5, 15, -10);
Workout w3 = Workout("Machine Chest Fly", -5, 15, -10);
Workout w4 = Workout("Jogging", -15, -5, -20);
Workout w5 = Workout("Dead Lift", -5, 20, -15);
cout<<"add_workout: "<<endl;
cout<<"\t\"Wrestling\", 1: (not changed because index invalid)"<<endl<<endl;
we.add_workout(w0, 1);
we.print_details(2);
cout<<endl;
cout<<"\t\"Wrestling\", 0:"<<endl<<endl;
we.add_workout(w0, 0);
we.print_details(2);
cout<<endl;
cout<<"\t\"Bicep Dumbbell Curl\", 0:"<<endl<<endl;
we.add_workout(w1, 0);
we.print_details(2);
cout<<endl;
cout<<"\t\"Machine Shoulder Press\", 2:"<<endl<<endl;
we.add_workout(w2, 2);
we.print_details(2);
cout<<endl;
cout<<"\t\"Jogging\", 1:"<<endl<<endl;
we.add_workout(w4, 1);
we.print_details(2);
cout<<endl;
cout<<"\t\"Dead Lift\", 4:"<<endl<<endl;
we.add_workout(w5, 4);
we.print_details(2);
cout<<endl;
cout<<"\t\"Machine Chest Fly\", 1: (not changed because list is full)"<<endl<<endl;
we.add_workout(w3, 1);
we.print_details(2);
cout<<endl;
cout<<"remove_workout: "<<endl<<endl;
cout<<"\t remove 3:"<<endl<<endl;
we.remove_workout(3);
we.print_details(2);
cout<<endl;
cout<<"\t remove 4: (not changed because index invalid)"<<endl<<endl;
we.remove_workout(4);
we.print_details(2);
cout<<endl;
cout<<"\t remove 0; 0; 1;"<<endl<<endl;
we.remove_workout(0);
we.remove_workout(0);
we.remove_workout(1);
we.print_details(2);
cout<<endl;
Buddy* b0 = new Buddy("Van", 50, 500, 100, 10000);
Buddy* b1 = new Buddy("Mona", 40, 600, 200, 8000);
Buddy* b2 = new Buddy("Billy", 0, 1000, 1000, 10000);
Buddy* b3 = new Buddy("Jagger", 1000, 0, 30, 10000);
Buddy* b4 = new Buddy("Way", 10, 10, 10, 10);
cout<<"register_participant: "<<endl<<endl;
cout<<"\tAdd Jagger: "<<endl<<endl;
we.register_participant(b3);
we.print_details(2);
cout<<endl;
cout<<"\tAdd Way: (not changed because Way doesn't have enough money)"<<endl<<endl;
we.register_participant(b4);
we.print_details(2);
cout<<endl;
cout<<"\tAdd Van; Mona; Billy; "<<endl;
cout<<"\tNote that participants' address is changed, but Jagger's address is not changed."<<endl<<endl;
we.register_participant(b0);
we.register_participant(b1);
we.register_participant(b2);
we.print_details(2);
cout<<endl;
cout<<"\tAdd Jagger: (not changed because Jagger is already added)"<<endl<<endl;
we.register_participant(b3);
we.print_details(2);
cout<<endl;
cout<<"participant_index: "<<endl<<endl;
cout<<"\tJagger: Index "<<we.participant_index(b3)<<endl;
cout<<"\tBilly: Index "<<we.participant_index(b2)<<endl;
cout<<"\tWay: Index "<<we.participant_index(b4)<<endl;
cout<<endl;
cout<<"start_workout: "<<endl<<endl;
cout<<"\t participant 0, workout 0: (not changed because not enough energy)"<<endl<<endl;
we.start_workout(0, 0);
we.print_details(2);
cout<<endl;
cout<<"\t participant 1, workout 0: "<<endl<<endl;
we.start_workout(1, 0);
we.print_details(2);
cout<<endl;
cout<<"\t participant 5, workout 5: (not changed because index invalid)"<<endl<<endl;
we.start_workout(5, 5);
we.print_details(2);
cout<<endl;
delete b0;
delete b1;
delete b2;
delete b3;
delete b4;
cout<<"------- WorkoutEnvironment Class Completed! -------"<<endl<<endl;
}