This repository has been archived by the owner on Sep 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
POLYGON.html
5948 lines (5612 loc) · 694 KB
/
POLYGON.html
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
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<hr>
<p><strong>POLYGON</strong></p>
<hr>
<figure class="wp-block-image size-full"><img data-attachment-id="21602" data-permalink="https://karlinaobject.wordpress.com/polygon/polygon_inheritance_diagram-2/" data-orig-file="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/polygon_inheritance_diagram.png" data-orig-size="960,720" data-comments-opened="1" data-image-meta="{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":"","orientation":"0"}" data-image-title="polygon_inheritance_diagram" data-image-description="" data-image-caption="" data-medium-file="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/polygon_inheritance_diagram.png?w=300" data-large-file="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/polygon_inheritance_diagram.png?w=960" tabindex="0" role="button" width="960" height="720" src="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/polygon_inheritance_diagram.png" alt="" class="wp-image-21602" srcset="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/polygon_inheritance_diagram.png 960w, https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/polygon_inheritance_diagram.png?w=150&h=113 150w, https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/polygon_inheritance_diagram.png?w=300&h=225 300w, https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/polygon_inheritance_diagram.png?w=768&h=576 768w" sizes="(max-width: 960px) 100vw, 960px" /></figure>
<hr>
<p>image_link: <a style="background:#000000;color:#ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/polygon_inheritance_diagram.png" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/polygon_inheritance_diagram.png</a></p>
<hr>
<figure class="wp-block-image size-full"><img data-attachment-id="21605" data-permalink="https://karlinaobject.wordpress.com/polygon/quadrilateral_image-2/" data-orig-file="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/quadrilateral_image.png" data-orig-size="960,720" data-comments-opened="1" data-image-meta="{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":"","orientation":"0"}" data-image-title="quadrilateral_image" data-image-description="" data-image-caption="" data-medium-file="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/quadrilateral_image.png?w=300" data-large-file="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/quadrilateral_image.png?w=960" tabindex="0" role="button" width="960" height="720" src="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/quadrilateral_image.png" alt="" class="wp-image-21605" srcset="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/quadrilateral_image.png 960w, https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/quadrilateral_image.png?w=150&h=113 150w, https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/quadrilateral_image.png?w=300&h=225 300w, https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/quadrilateral_image.png?w=768&h=576 768w" sizes="(max-width: 960px) 100vw, 960px" /></figure>
<hr>
<p>image_link: <a style="background:#000000;color:#ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/quadrilateral_image.png" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/quadrilateral_image.png</a></p>
<hr>
<figure class="wp-block-image size-full"><img data-attachment-id="21581" data-permalink="https://karlinaobject.wordpress.com/triangle/triangle_image-2/" data-orig-file="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/triangle_image.png" data-orig-size="960,720" data-comments-opened="1" data-image-meta="{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":"","orientation":"0"}" data-image-title="triangle_image" data-image-description="" data-image-caption="" data-medium-file="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/triangle_image.png?w=300" data-large-file="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/triangle_image.png?w=960" tabindex="0" role="button" width="960" height="720" src="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/triangle_image.png" alt="" class="wp-image-21581" srcset="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/triangle_image.png 960w, https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/triangle_image.png?w=150&h=113 150w, https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/triangle_image.png?w=300&h=225 300w, https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/triangle_image.png?w=768&h=576 768w" sizes="(max-width: 960px) 100vw, 960px" /></figure>
<hr>
<p>image_link: <a style="background:#000000;color:#ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/triangle_image.png" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/triangle_image.png</a></p>
<hr>
<figure class="wp-block-image size-full"><img data-attachment-id="21565" data-permalink="https://karlinaobject.wordpress.com/point/points_on_cartesian_grid-2/" data-orig-file="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/points_on_cartesian_grid.png" data-orig-size="960,720" data-comments-opened="1" data-image-meta="{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":"","orientation":"0"}" data-image-title="points_on_cartesian_grid" data-image-description="" data-image-caption="" data-medium-file="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/points_on_cartesian_grid.png?w=300" data-large-file="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/points_on_cartesian_grid.png?w=960" tabindex="0" role="button" loading="lazy" width="960" height="720" src="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/points_on_cartesian_grid.png" alt="" class="wp-image-21565" srcset="https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/points_on_cartesian_grid.png 960w, https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/points_on_cartesian_grid.png?w=150&h=113 150w, https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/points_on_cartesian_grid.png?w=300&h=225 300w, https://karlinaobject.wordpress.com/wp-content/uploads/2023/07/points_on_cartesian_grid.png?w=768&h=576 768w" sizes="(max-width: 960px) 100vw, 960px" /></figure>
<hr />
<p>image_link: <a style="background: #000000;color: #ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/points_on_cartesian_grid.png" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/points_on_cartesian_grid.png</a></p>
<hr />
<p><span style="background: #ffff00">The <a style="background: #ff9000;color: #000000" href="https://en.wikipedia.org/wiki/C%2B%2B" target="_blank" rel="noopener">C++</a> program featured in this tutorial web page demonstrates the concept of Object Oriented Programming (<a style="background: #ff9000;color: #000000" href="https://en.wikipedia.org/wiki/Object-oriented_programming" target="_blank" rel="noopener">OOP</a>); especially the concept of <a style="background: #ff9000;color: #000000" href="https://en.wikipedia.org/wiki/Polymorphism_(computer_science)" target="_blank" rel="noopener">polymorphism</a> (i.e. implementing data types which inherit abstract attributes which can be made more concrete and specific).</span></p>
<p><span style="background: #ffff00">The program implements user defined data types for instantiating <strong>POLYGON</strong> type objects (and POLYGON is an <strong>abstract class</strong>) which are instances of either the POLYGON-derived non-abstract class named <strong>QUADRILATERAL</strong> or else the QUADRILATERAL-derived non-abstract class named <strong>TRAPEZOID</strong> or else the QUADRILATERAL-derived non-abstract class named <strong>RECTANGLE</strong> or else the RECTANGLE-derived non-abstract class named <strong>SQUARE</strong> or else the POLYGON-derived non-abstract class named <strong>TRILATERAL</strong> or else the TRILATERAL-derived non-abstract class named <strong>RIGHT_TRILATERAL</strong>.</span></p>
<p><span style="background: #ffff00">Each non-abstract POLYGON type object object represents either three or else four instances of the <a style="background: #000000;color: #00ff00" href="https://karlinaobject.wordpress.com/point/" target="_blank" rel="noopener">POINT</a> class such that each POINT instance represents a unique whole number coordinate pair and such that the polygon represented by the points whose coordinates are data members of the non-abstract POLYGON instance has a non-zero area and, if the polygon is an instance of TRILATERAL, the sum of the interior angles of that polygon is 180 degrees and, if the polygon is an instance of QUADRILATERAL, the sum of the interior angles of that polygon is 360 degrees.</span></p>
<p><span style="background: #ffff00">A non-abstract POLYGON object can execute various functions including the ability to compute the <a style="background: #ff9000;color: #000000" href="https://en.wikipedia.org/wiki/Area" target="_blank" rel="noopener">area</a> of the two-dimensional region whose boundaries are the line segments which connect the points which the POINT type variables of the non-abstract POLYGON object represent and the ability to compute the <a style="background: #ff9000;color: #000000" href="https://en.wikipedia.org/wiki/Perimeter" target="_blank" rel="noopener">perimeter</a> (i.e. length of the one-dimensional boundary of the two-dimensional area) which the non-abstract POLYGON object represents.</span></p>
<p><em>To view hidden text inside each of the preformatted text boxes below, scroll horizontally.</em></p>
<pre>class : object :: data_type : variable.</pre>
<hr />
<p><strong>SOFTWARE_APPLICATION_COMPONENTS</strong></p>
<hr />
<p>C++_header_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/point.h" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/point.h</a></p>
<p>C++_source_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/point.cpp" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/point.cpp</a></p>
<p>C++_header_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/polygon.h" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/polygon.h</a></p>
<p>C++_source_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/polygon.cpp" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/polygon.cpp</a></p>
<p>C++_header_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/quadrilateral.h" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/quadrilateral.h</a></p>
<p>C++_source_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/quadrilateral.cpp" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/quadrilateral.cpp</a></p>
<p>C++_header_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/trapezoid.h" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/trapezoid.h</a></p>
<p>C++_source_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/trapezoid.cpp" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/trapezoid.cpp</a></p>
<p>C++_header_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/rectangle.h" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/rectangle.h</a></p>
<p>C++_source_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/rectangle.cpp" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/rectangle.cpp</a></p>
<p>C++_header_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/square.h" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/square.h</a></p>
<p>C++_source_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/square.cpp" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/square.cpp</a></p>
<p>C++_header_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/trilateral.h" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/trilateral.h</a></p>
<p>C++_source_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/trilateral.cpp" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/trilateral.cpp</a></p>
<p>C++_header_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/right_trilateral.h" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/right_trilateral.h</a></p>
<p>C++_source_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/right_trilateral.cpp" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/right_trilateral.cpp</a></p>
<p>C++_source_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/polygon_class_inheritance_tester.cpp" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/polygon_class_inheritance_tester.cpp</a></p>
<p>plain-text_file: <a style="background: #000000;color: #ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/polygon_class_inheritance_tester_output.txt" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/polygon_class_inheritance_tester_output.txt</a></p>
<hr />
<p><strong>PROGRAM_COMPILATION_AND_EXECUTION</strong></p>
<hr />
<p>STEP_0: Copy and paste the C++ code from the files named <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/point.h" target="_blank" rel="noopener">point.h</a>, <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/point.cpp" target="_blank" rel="noopener">point.cpp</a>, <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/polygon.h" target="_blank" rel="noopener">polygon.h</a>, <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/polygon.cpp" target="_blank" rel="noopener">polygon.cpp</a>, <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/quadrilateral.h" target="_blank" rel="noopener">quadrilateral.h</a>, <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/quadrilateral.cpp" target="_blank" rel="noopener">quadrilateral.cpp</a>, <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/trapezoid.h" target="_blank" rel="noopener">trapezoid.h</a>, <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/trapezoid.cpp" target="_blank" rel="noopener">trapezoid.cpp</a>, <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/rectangle.h" target="_blank" rel="noopener">rectangle.h</a>, <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/rectangle.cpp" target="_blank" rel="noopener">rectangle.cpp</a>, <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/square.h" target="_blank" rel="noopener">square.h</a>, <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/square.cpp" target="_blank" rel="noopener">square.cpp</a>, <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/trilateral.h" target="_blank" rel="noopener">trilateral.h</a>, <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/trilateral.cpp" target="_blank" rel="noopener">trilateral.cpp</a>, <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/right_trilateral.h" target="_blank" rel="noopener">right_trilateral.h</a>, <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/right_trilateral.cpp" target="_blank" rel="noopener">right_trilateral.cpp</a>, and <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/polygon_class_inheritance_tester.cpp" target="_blank" rel="noopener">polygon_class_inheritance_tester.cpp</a> into their own new text editor documents and save those documents using their corresponding file names:</p>
<pre>point.h</pre>
<pre>point.cpp</pre>
<pre>polygon.h</pre>
<pre>polygon.cpp</pre>
<pre>quadrilateral.h</pre>
<pre>quadrilateral.cpp</pre>
<pre>trapezoid.h</pre>
<pre>trapezoid.cpp</pre>
<pre>rectangle.h</pre>
<pre>rectangle.cpp</pre>
<pre>square.h</pre>
<pre>square.cpp</pre>
<pre>trilateral.h</pre>
<pre>trilateral.cpp</pre>
<pre>right_trilateral.h</pre>
<pre>right_trilateral.cpp</pre>
<pre>polygon_class_inheritance_tester.cpp</pre>
<p>STEP_1: Open a <a style="background: #ff9000;color: #000000" href="https://en.wikipedia.org/wiki/Unix" target="_blank" rel="noopener">Unix</a> command line terminal application and set the current directory to wherever the C++ is located on the local machine (e.g. Desktop).</p>
<pre>cd Desktop</pre>
<p>STEP_2: Compile the C++ file into machine-executable instructions (i.e. object file) and then into an executable piece of software named <strong>app</strong> using the following command:</p>
<pre>g++ polygon_class_inherintance_tester.cpp right_trilateral.cpp trilateral.cpp square.cpp rectangle.cpp trapezoid.cpp quadrilateral.cpp polygon.cpp point.cpp -o app</pre>
<p>STEP_3: If the program compilation command does not work, then use the following commands (in top-down order) to install the C/C++ compiler (which is part of the <a style="background: #ff9000;color: #000000" href="https://en.wikipedia.org/wiki/GNU_Compiler_Collection" target="_blank" rel="noopener">GNU Compiler Collection (GCC)</a>):</p>
<pre>sudo apt install build-essential</pre>
<pre>sudo apt-get install g++</pre>
<p>STEP_4: After running the <strong>g++</strong> command, run the executable file using the following command:</p>
<pre>./app</pre>
<p>STEP_5: Observe program results on the command line terminal and in the <a style="background: #000000;color: #ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/polygon_class_inheritance_tester_output.txt" target="_blank" rel="noopener">output file</a>.</p>
<hr />
<p><strong>POINT_CLASS_HEADER</strong></p>
<hr />
<p>The following header file contains the preprocessing directives and function prototypes of the POINT class.</p>
<p>(Note that the text inside of each of the the preformatted text boxes below appears on this web page (while rendered correctly by the <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/HTML" target="_blank" rel="noopener">web browser</a>) to be identical to the content of that preformatted text box text’s respective <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/C%2B%2B" target="_blank" rel="noopener">C++</a> source code file whose <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/URL" target="_blank" rel="noopener">Uniform Resource Locator</a> is displayed in the green <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Hyperlink" target="_blank" rel="noopener">hyperlink</a> immediately above that preformatted text box. A <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Computer" target="_blank" rel="noopener">computer</a> interprets that C++ source code as a series of programmatic instructions (i.e. <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Software" target="_blank" rel="noopener">software</a>) which govern how the <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Computer_hardware" target="_blank" rel="noopener">hardware</a> of that computer behaves).</p>
<p><em>(Note also that angle brackets which resemble <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/HTML" target="_blank" rel="noopener">HTML</a> tags (i.e. an “is less than” symbol (i.e. ‘<‘) followed by an “is greater than” symbol (i.e. ‘>’) displayed in the aforementioned text boxes have been replaced (at the source code level of this web page) with Unicode symbols <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Less-than_sign" target="_blank" rel="noopener">U+003C</a> (which is rendered by the web browser as ‘<‘) and <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Greater-than_sign" target="_blank" rel="noopener">U+003E</a> (which is rendered by the web browser as ‘>’). That is because the <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/WordPress.com" target="_blank" rel="noopener">WordPress</a> web page editor interprets a plain-text versions of an “is less than” symbol followed by an “is greater than” symbol as being an opening HTML tag (which means that the WordPress web page editor deletes the content between those (plain-text) inequality symbols)).</em></p>
<p>C++_header_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/point.h" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/point.h</a></p>
<hr />
<pre>/**
* file: point.h
* type: C++ (header file)
* author: karbytes
* date: 07_JULY_2023
* license: PUBLIC_DOMAIN
*/
/* preprocessing directives */
#ifndef POINT_H // If point.h has not already been linked to a source file (.cpp),
#define POINT_H // then link this header file to the source file(s) which include this header file.
/* preprocessing directives */
#include <iostream> // library for defining objects which handle command line input and command line output
#include <fstream> // library for defining objects which handle file input and file output
#include <cmath> // library which defines various math functions such as square root (sqrt()) and sine (sin())
#include <string> // library which defines a sequence of text characters (i.e. char type values) as a string type variable
#define MINIMUM_X -999 // constant which represents minimum X value
#define MAXIMUM_X 999 // constant which represents maximum X value
#define MINIMUM_Y -999 // constant which represents minimum Y value
#define MAXIMUM_Y 999 // constant which represents maximum Y value
#define PI 3.14159 // constant which represents the approximate value of a circle's circumference divided by that circle's diameter
/**
* Define a class which is used to instantiate POINT type objects.
*
* (An object is a variable whose data type is user defined rather than native to the C++ programming language).
*
* A POINT object represents a whole number coordinate pair in the form (X,Y).
*
* X represents a specific whole number position along the x-axis (i.e. horizontal dimension) of a two-dimensional Cartesian grid.
* Y represents a specific whole number position along the y-axis (i.e. vertical dimension) of the same two-dimensional Cartesian grid.
*
* X stores one integer value at a time which is no smaller than MINIMUM_X and which is no larger than MAXIMUM_X.
* Y stores one integer value at a time which is no smaller than MINIMUM_Y and which is no larger than MAXIMUM_Y.
*/
class POINT
{
private:
int X, Y; // data attributes
public:
POINT(); // default constructor
POINT(int X, int Y); // normal constructor
POINT(const POINT & point); // copy constructor
int get_X(); // getter method
int get_Y(); // getter method
bool set_X(int X); // setter method
bool set_Y(int Y); // setter method
double get_distance_from(POINT & point); // getter method
double get_slope_of_line_to(POINT & point); // getter method
void print(std::ostream & output = std::cout); // descriptor method
friend std::ostream & operator << (std::ostream & output, POINT & point); // descriptor method
~POINT(); // destructor
};
/* preprocessing directives */
#endif // Terminate the conditional preprocessing directives code block in this header file.
</pre>
<hr />
<p><strong>POINT_CLASS_SOURCE_CODE</strong></p>
<hr />
<p>The following source code defines the functions of the POINT class.</p>
<p>C++_source_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/point.cpp" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/point.cpp</a></p>
<hr />
<pre>/**
* file: point.cpp
* type: C++ (source file)
* date: 07_JULY_2023
* author: karbytes
* license: PUBLIC_DOMAIN
*/
/* preprocessing directives */
#include "point.h" // Include the C++ header file which contains preprocessing directives, variable declarations, and function prototypes for the POINT class.
/**
* The default constructor method of the POINT class
* instantiates POINT type objects
* whose X value is initially set to 0 and
* whose Y value is initially set to 0.
*
* The default constructor method of the POINT class is invoked
* when a POINT type variable is declared as follows:
*
* // variable declaration example one
* POINT point_0;
*
* // variable declaration example two
* POINT point_1 = POINT();
*/
POINT::POINT()
{
std::cout << "\n\nCreating the POINT type object whose memory address is " << this << "...";
X = 0;
Y = 0;
}
/**
* The normal constructor method of the POINT class
* instantiates POINT type objects
* whose X value is set to the leftmost function input value (if that input value is no smaller than MINIMUM_X and no larger than MAXIMUM_X) and
* whose Y value is set to the rightmost function input value (if that input value is no smaller than MINIMUM_Y and no larger than MAXIMUM_Y).
*
* If a function input value is out of its specified range, then set the corresponding int type property of this to 0.
*
* (The keyword this refers to the POINT object which is returned by this function).
*
* The normal constructor method of the POINT class is invoked when a POINT type variable is declared as follows:
*
* // variable definition example one
* POINT point_0 = POINT(-55,84);
*
* // variable definition example two
* POINT point_1 = POINT(3,-4);
*
* // variable definition example three
* POINT point_2 = POINT(-1000, 999); // point_2 = POINT(0,999).
*
* // variable definition example four
* POINT point_3 = POINT(1000,-999); // point_3 = POINT(0,-999).
*
* // variable definition example five
* POINT point_4 = POINT(999,-1000); // point_4 = POINT(999,0).
*
* // variable definition example six
* POINT point_5 = POINT(-999,1000); // point_5 = POINT(-999,0).
*/
POINT::POINT(int X, int Y)
{
std::cout << "\n\nCreating the POINT type object whose memory address is " << this << "...";
this -> X = ((X < MINIMUM_X) || (X > MAXIMUM_X)) ? 0 : X; // Set the X property of the POINT instance being created to 0 if the function input X value is out of range.
this -> Y = ((Y < MINIMUM_Y) || (Y > MAXIMUM_Y)) ? 0 : Y; // Set the Y property of the POINT instance being created to 0 if the function input Y value is out of range.
}
/**
* The copy constructor method of the POINT class
* instantiates POINT type objects
* whose X value is set to the X value of the input POINT object and
* whose Y value is set to the Y value of the input POINT object.
*
* The copy constructor method of the POINT class is invoked when a POINT type variable is declared as follows:
*
* // variable definition example one
* POINT point_0 = POINT(33,55);
* POINT point_1 = POINT(point_0); // point_1 = POINT(33,55).
*
* // variable definition example two
* POINT point_2 = POINT(point_1); // point_2 = POINT(33,55).
*/
POINT::POINT(const POINT & point)
{
std::cout << "\n\nCreating the POINT type object whose memory address is " << this << "...";
X = point.X;
Y = point.Y;
}
/**
* The getter method of the POINT class returns the value of the caller POINT object's X property.
*
* X is an int type variable which stores exactly one integer value at a time which is no smaller than MINIMUM_X and which is no larger than MAXIMUM_X.
*
* X represents a specific whole number position along the x-axis (i.e. horizontal dimension) of a two-dimensional Cartesian grid.
*/
int POINT::get_X()
{
return X;
}
/**
* The getter method of the POINT class returns the value of the caller POINT object's Y property.
*
* Y is an int type variable which stores exactly one integer value at a time which is no smaller than MINIMUM_Y and which is no larger than MAXIMUM_Y.
*
* Y represents a specific whole number position along the y-axis (i.e. vertical dimension) of a two-dimensional Cartesian grid.
*/
int POINT::get_Y()
{
return Y;
}
/**
* The setter method of the POINT class sets the POINT object's X property to the function input value
* if that value is no smaller than MINIMUM_X and which is no larger than MAXIMUM_X.
*
* If the input value is in range, then return true.
* Otherwise, do not change the caller POINT object's X value and return false.
*
* (The keyword this refers to the POINT object which calls this function).
*
* (X represents a specific whole number position along the x-axis (i.e. horizontal dimension) of a two-dimensional Cartesian grid).
*/
bool POINT::set_X(int X)
{
if ((X >= MINIMUM_X) && (X <= MAXIMUM_X))
{
this -> X = X;
return true;
}
return false;
}
/**
* The setter method of the POINT class sets the POINT object's Y property to the function input value
* if that value is no smaller than MINIMUM_Y and which is no larger than MAXIMUM_Y.
*
* If the input value is in range, then return true.
* Otherwise, do not change the caller POINT object's Y value and return false.
*
* (The keyword this refers to the POINT object which calls this function).
*
* (Y represents a specific whole number position along the y-axis (i.e. vertical dimension) of a two-dimensional Cartesian grid).
*/
bool POINT::set_Y(int Y)
{
if ((Y >= MINIMUM_Y) && (Y <= MAXIMUM_Y))
{
this -> Y = Y;
return true;
}
return false;
}
/**
* The getter method of the POINT class returns the length of the shortest path
* between the two-dimensional point represented by the the caller POINT object (i.e. this)
* and the two-dimensional point represented by the input POINT object (i.e. point).
*
* Use the Pythagorean Theorem to compute the length of a right triangle's hypotenuse
* such that the two end points of that hypotenuse are represented by this and point.
*
* (A hypotenuse is the only side of a right triangle which does not form a right angle
* with any other side of that triangle).
*
* (A hypotenuse is the longest side of a triangle (and a triangle is a three-sided polygon
* in which three unique line segments connect three unique points)).
*
* // c is the length of a right triangle's hypotenuse.
* // a is the length of that right triangle's horizontal leg.
* // b is the length of that triangle's vertical leg.
* (c * c) = (a * a) + (b * b).
*
* // sqrt() is a native C++ function defined in the cmath library.
* c = square_root( (a * a) + (b * b)).
*/
double POINT::get_distance_from(POINT & point)
{
int horizontal_difference = 0.0, vertical_difference = 0.0;
horizontal_difference = X - point.X; // a
vertical_difference = Y - point.Y; // b
return sqrt((horizontal_difference * horizontal_difference) + (vertical_difference * vertical_difference)); // c
}
/**
* The getter method of the POINT class returns the slope of the line which intersects
* the two-dimensional point represented by the caller POINT instance (i.e. this)
* and the two-dimensional point represented by the input POINT instance (i.e. point).
*
* // y := f(x),
* // b := f(0),
* // f is a function whose input is an x-axis position and whose output is a y-axis position.
* y := mx + b.
*
* // m is a constant which represents the rate at which y changes in relation to x changing.
* m := (y - b) / x.
*
* // m represents the difference of the two y-values divided by the difference of the two x-values.
* m := (point.Y - this.Y) / (point.X - this.X).
*/
double POINT::get_slope_of_line_to(POINT & point)
{
double vertical_difference = 0.0, horizontal_difference = 0.0, result = 0.0;
vertical_difference = point.Y - Y;
horizontal_difference = point.X - X;
result = vertical_difference / horizontal_difference;
if (result == -0) result = 0; // Signed zeros sometimes occur inside of C++ program runtime instances.
return result;
}
/**
* The print method of the POINT class prints a description of the caller POINT object to the output stream.
*
* Note that the default value of the function input parameter is the standard command line output stream (std::cout).
*
* The default parameter is defined in the POINT class header file (i.e. point.h) and not in the POINT class source file (i.e. point.cpp).
*/
void POINT::print(std::ostream & output)
{
output << "\n\n--------------------------------------------------------------------------------------------------";
output << "\nthis = " << this << ". // The keyword named this is a pointer which stores the memory address of the first memory cell of a POINT sized chunk of contiguous memory cells which are allocated to the caller POINT object.";
output << "\n&X = " << &X << ". // The reference operation returns the memory address of the first memory cell of an int sized chunk of contiguous memory cells which are allocated to the caller POINT data attribute named X.";
output << "\n&Y = " << &Y << ". // The reference operation returns the memory address of the first memory cell of an int sized chunk of contiguous memory cells which are allocated to the caller POINT data attribute named Y.";
output << "\nsizeof(int) = " << sizeof(int) << ". // The sizeof() operation returns the number of bytes of memory which an int type variable occupies. (Each memory cell has a data capacity of 1 byte).";
output << "\nsizeof(POINT) = " << sizeof(POINT) << ". // The sizeof() operation returns the number of bytes of memory which a POINT type object occupies. (Each memory cell has a data capacity of 1 byte).";
output << "\nX = " << X << ". // X stores one int type value at a time which represents the horizontal position of a two-dimensional point plotted on a Cartesian grid.";
output << "\nY = " << Y << ". // Y stores one int type value at a time which represents the vertical position of a two-dimensional point plotted on a Cartesian grid.";
output << "\n--------------------------------------------------------------------------------------------------";
}
/**
* The friend function is an alternative to the print method.
* The friend function overloads the ostream operator (<<).
*
* (Overloading an operator is assigning a different function to a native operator other than the function which that operator is used to represent by default).
*
* Note that the default value of the leftmost function input parameter is the standard command line output stream (std::cout).
* The default parameter is defined in the POINT class header file (i.e. point.h).
*
* The friend function is not a member of the POINT class,
* but the friend function has access to the private and protected members
* of the POINT class and not just to the public members of the POINT class.
*
* The friend keyword only prefaces the function prototype of this function
* (and the prototype of this function is declared in the POINT class header file (i.e. point.h)).
*
* The friend keyword does not preface the definition of this function
* (and the definition of this function is specified in the POINT class source file (i.e. point.cpp)).
*
* // overloaded print function example one
* POINT point_0;
* std::cout << point_0; // identical to point_0.print();
*
* // overloaded print function example two
* std::ofstream file;
* POINT point_1;
* file << point_1; // identical to point_1.print(file);
*/
std::ostream & operator << (std::ostream & output, POINT & point)
{
point.print(output);
return output;
}
/**
* The destructor method of the POINT class de-allocates memory which was used to
* instantiate the POINT object which is calling this function.
*
* The destructor method of the POINT class is automatically called when
* the program scope in which the caller POINT object was instantiated terminates.
*/
POINT::~POINT()
{
std::cout << "\n\nDeleting the POINT type object whose memory address is " << this << "...";
}
</pre>
<hr />
<p><strong>POLYGON_CLASS_HEADER</strong></p>
<hr />
<p>The following header file contains the preprocessing directives and function prototypes of the POLYGON class.</p>
<p>C++_header_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/polygon.h" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/polygon.h</a></p>
<hr />
<pre>/**
* file: polygon.h
* type: C++ (header file)
* date: 07_JULY_2023
* author: karbytes
* license: PUBLIC_DOMAIN
*/
// If polygon.h has not already been linked to a source file (.cpp), then link this header file to the source file(s) which include this header file.
#ifndef POLYGON_H
#define POLYGON_H
// Include the C++ header file which contains preprocessing directives, variable declarations, and function prototypes for the POINT class.
#include "point.h"
/**
* POLYGON is an abstract class whose members are the essential components of objects
* whose classes are TRILATERAL, RIGHT_TRILATERAL, QUADRILATERAL, TRAPEZOID, RECTANGLE, and SQUARE.
*
* (An abstract class has at least one virtual function).
*
* The POLYGON class includes the POINT class via composition and not via inheritance.
*
* Class members which are set to the protected access specifier
* are accessible to the base class and to derived classes.
*
* Class members which are set to the private access specifier
* are only accessible to the base class.
*
* Class members which are set to the public access specifier
* are accessible to any scope within the program where
* the base class and its derived classes are implemented.
*/
class POLYGON
{
protected:
/**
* category is a description of the POLYGON instance.
* category is set to a constant (i.e. immutable) string type value.
*/
const std::string category = "POLYGON";
/**
* color is an arbitrary string type value.
* color is used to demonstrate how abstract constructors work.
*/
std::string color;
public:
/**
* The default POLYGON constructor sets the color value to "orange".
*
* Note that POLYGON type objects cannot be instantiated (i.e. occupy space in memory)
* because the POLYGON class is abstract.
*
* (pointer-to-POLYGON type variables can be instantiated, however, and used to store the memory addresses
* of objects whose classes are derived from the POLYGON).
*
* POLYGON polygon; // This command does not work because POLYGON is an abstract class.
* POLYGON * pointer_to_polygon; // The pointer-to-polygon type variable can store the memory address of an object whose data type is a non-abstract derived class of POLYGON such as QUADRILATERAL.
* pointer_to_polygon = new QUADRILATERAL; // Assign memory to a dynamic QUADRILATERAL instance (i.e. and dynamic implies that the variable was created during program runtime instead of during program compile time).
* pointer_to_polygon -> print(output); // Indirectly call the POLYGON print method and not the QUADRILATERAL print method.
*
* The POLYGON constructor is implemented only by classes which are
* descendents of the POLYGON class.
*/
POLYGON();
/**
* The virtual methods get_area() and get_perimeter()
* must be defined by classes which are derived from the POLYGON class.
*/
virtual double get_area() = 0;
virtual double get_perimeter() = 0;
/**
* The descriptor method prints a description of the caller POLYGON instance to the output stream.
* If no function input is supplied, output is set to the command line terminal.
*/
void print(std::ostream & output = std::cout);
/**
* The friend function is an alternative to the print method.
* The friend function overloads the ostream operator (i.e. <<).
*
* The friend function is not a member of the POLYGON class,
* but that friend function does have access to the private and protected members of the POLYGON class
* as though that friend function was a member of the POLYGON class.
*/
friend std::ostream & operator << (std::ostream & output, POLYGON & polygon);
/**
* The destructor method of the POLYGON class de-allocates memory which was used to
* instantiate the POLYGON object which is calling this function.
*
* The destructor method of the POLYGON class is automatically called when
* the program scope in which the caller POLYGON object was instantiated terminates.
*/
~POLYGON();
};
/* preprocessing directives */
#endif // Terminate the conditional preprocessing directives code block in this header file.
</pre>
<hr />
<p><strong>POLYGON_CLASS_SOURCE_CODE</strong></p>
<hr />
<p>The following source code defines the functions of the POLYGON class.</p>
<p>C++_source_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/polygon.cpp" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/polygon.cpp</a></p>
<hr />
<pre>/**
* file: polygon.cpp
* type: C++ (source file)
* date: 07_JULY_2023
* author: karbytes
* license: PUBLIC_DOMAIN
*/
// Include the C++ header file which contains preprocessing directives, variable declarations, and function prototypes for the POLYGON class.
#include "polygon.h"
/**
* The default POLYGON constructor sets the color value to "orange".
*
* Note that POLYGON type objects cannot be instantiated (i.e. occupy space in memory)
* because the POLYGON class is abstract.
*
* (pointer-to-POLYGON type variables can be instantiated, however, and used to store the memory addresses
* of objects whose classes are derived from the POLYGON).
*
* POLYGON polygon; // This command does not work because POLYGON is an abstract class.
* POLYGON * pointer_to_polygon; // The pointer-to-polygon type variable can store the memory address of an object whose data type is a non-abstract derived class of POLYGON such as QUADRILATERAL.
* pointer_to_polygon = new QUADRILATERAL; // Assign memory to a dynamic QUADRILATERAL instance (i.e. and dynamic implies that the variable was created during program runtime instead of during program compile time).
* pointer_to_polygon -> print(output); // Indirectly call the POLYGON print method and not the QUADRILATERAL print method.
*
* The POLYGON constructor is implemented only by classes which are
* descendents of the POLYGON class.
*/
POLYGON::POLYGON()
{
std::cout << "\n\nCreating the POLYGON type object whose memory address is " << this << "...";
color = "orange";
}
/**
* The virtual methods get_area() and get_perimeter() must be defined by
* classes which are derived from the POLYGON class.
*/
double POLYGON::get_area() { return 0.0; }
double POLYGON::get_perimeter() { return 0.0; }
/**
* The descriptor method prints a description of the caller POLYGON instance to the output stream.
* If no function input is supplied, output is set to the command line terminal.
*/
void POLYGON::print(std::ostream & output)
{
output << "\n\n--------------------------------------------------------------------------------------------------";
output << "\nmemory_address = " << this << ".";
output << "\ncategory = " << category << ".";
output << "\ncolor = " << color << ".";
output << "\n&category = " << &category << ".";
output << "\n&color = " << &color << ".";
output << "\n--------------------------------------------------------------------------------------------------";
}
/**
* The friend function is an alternative to the print method.
* The friend function overloads the ostream operator (i.e. <<).
*
* The friend function is not a member of the POLYGON class,
* but that friend function does have access to the private and protected members of the POLYGON class
* as though that friend function was a member of the POLYGON class.
*/
std::ostream & operator << (std::ostream & output, POLYGON & polygon)
{
polygon.print(output);
return output;
}
/**
* The destructor method of the POLYGON class de-allocates memory which was used to
* instantiate the POLYGON object which is calling this function.
*
* The destructor method of the POLYGON class is automatically called when
* the program scope in which the caller POLYGON object was instantiated terminates.
*/
POLYGON::~POLYGON()
{
std::cout << "\n\nDeleting the POLYGON type object whose memory address is " << this << "...";
}
</pre>
<hr />
<p><strong>QUADRILATERAL_CLASS_HEADER</strong></p>
<hr />
<p>The following header file contains the preprocessing directives and function prototypes of the QUADRILATERAL class.</p>
<p>C++_header_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/quadrilateral.h" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/quadrilateral.h</a></p>
<hr />
<pre>/**
* file: quadrilateral.h
* type: C++ (header file)
* date: 07_JULY_2023
* author: karbytes
* license: PUBLIC_DOMAIN
*/
// If quadrilateral.h has not already been linked to a source file (.cpp), then link this header file to the source file(s) which include this header file.
#ifndef QUADRILATERAL_H
#define QUADRILATERAL_H
// Include the C++ header file which contains preprocessing directives, variable declarations, and function prototypes for the POLYGON class.
#include "polygon.h"
/**
* QUADRILATERAL is a class which inherits the protected and public data
* attributes and methods of POLYGON (and POLYGON is an abstract class).
*
* A QUADRILATERAL object represents an instance in which four unique POINT instances exist
* such that each one of those four POINT instances represents a unique coordinate pair within the tuple of four POINT instances
* (such that each coordinate pair represents exactly one two-dimensional point, POINT(X,Y), on a Cartesian grid).
*
* Each QUADRILATERAL object represents a specific four-sided polygon whose area is a positive real number.
*
* Class members which are set to the protected access specifier
* are accessible to the base class and to derived classes.
*
* Class members which are set to the private access specifier
* are only accessible to the base class.
*
* Class members which are set to the public access specifier
* are accessible to any scope within the program where
* the base class and its derived classes are implemented.
*/
class QUADRILATERAL: public POLYGON
{
protected:
/**
* category is a description of the POLYGON instance.
* category is set to a constant (i.e. immutable) string type value.
*/
const std::string category = "POLYGON/QUADRILATERAL";
/**
* POINT type objects A, B, C, and D represent points on a Cartesian plane.
* Each POINT type object has two int type variables for representing a two-dimensional whole number coordinate pair.
* The X data attribute of a POINT object represents a whole number position on the horizontal axis (i.e. x-axis) of a Cartesian plane.
* The Y data attribute of a POINT object represents a whole number position on the vertical axis (i.e. y-axis) of the same Cartesian plane.
*/
POINT A, B, C, D;
/**
* If each of the four whole number coordinate pairs represented by the POINT type input values named _A, _B, _C, and _D are unique whole number coordinate pairs,
* return true.
* Otherwise, return false.
*/
bool points_represent_unique_coordinate_pairs(POINT _A, POINT _B, POINT _C, POINT _D);
/**
* If sum of the interior angle measurements of the quadrilateral which the caller QUADRILATERAL object represents add up to approximately 360 degrees,
* return true.
* Otherwise, return false.
*/
bool interior_angles_add_up_to_360_degrees();
public:
/**
* The test function helps to illustrate how pointers work.
*/
int quadrilateral_test(); // return 555
/**
* The default constructor of the QUADRILATERAL class calls the constructor of the POLYGON class and
* sets the POINT type data member of the QUADRILATERAL object returned by this function named A to POINT(0,0),
* sets the POINT type data member of the QUADRILATERAL object returned by this function named B to POINT(0,5),
* sets the POINT type data member of the QUADRILATERAL object returned by this function named C to POINT(4,5), and
* sets the POINT type data member of the QUADRILATERAL object returned by this function named D to POINT(4,0).
*/
QUADRILATERAL();
/**
* The normal constructor of QUADRILATERAL attempts to set
* the string type data member of this to the input string type value named color and
* the POINT type data member of this named A to the input POINT type value named A and
* the POINT type data member of this named B to the input POINT type value named B and
* the POINT type data member of this named C to the input POINT type value named C and
* the POINT type data member of this named D to the input POINT type value named D.
*
* (The keyword this refers to the QUADRILATERAL object which is returned by this function).
*
* If A, B, C, and D represent unique points on a Cartesian plane and
* if the interior angles of the quadrilateral which those points would represent add up to 360 degrees and
* if the area of the quadrilateral which those points represents is larger than zero,
* use the input POINT values as the POINT values for the QUADRILATERAL object which is returned by this function.
*/
QUADRILATERAL(std::string color, POINT A, POINT B, POINT C, POINT D);
/**
* The copy constructor method of the QUADRILATERAL class
* instantiates QUADRILATERAL type objects
* whose A value is set to the A value of the input QUADRILATERAL object,
* whose B value is set to the B value of the input QUADRILATERAL object,
* whose C value is set to the C value of the input QUADRILATERAL object, and
* whose D value is set to the D value of the input QUADRILATERAL object.
*/
QUADRILATERAL(QUADRILATERAL & quadrilateral);
/**
* The QUADRILATERAL class implements the virtual get_area() method of the POLYGON class.
*
* The getter method returns the area of the quadrilateral represented by the caller QUADRILATERAL object
* using using Heron's Formula to
* compute the area of each of the two triangles which comprise that quadrilateral.
*
* Let AB be the length of the line segment whose endpoints are A and B.
* Let BC be the length of the line segment whose endpoints are B and C.
* Let CA be the length of the line segment whose endpoints are C and A.
* Let CD be the length of the line segment whose endpoints are C and D.
* Let DA be the length of the line segment whose endpoints are D and A.
*
* Let the first triangle be the area which is enclosed inside line segments represented by AB, BC, and CA.
* Let the second triangle be the area which is enclosed inside line segments represented by AC, CD, and DA.
*
* Then compute the area of each triangle using Heron's Formula as follows:
*
* Let s be the semiperimeter of a triangle (i.e. the perimeter divided by 2).
* Let a, b, and c be the side lengths of a triangle.
*
* Then
*
* area = square_root( s * (s - a) * (s - b) * (s - c) ).
*
* Finally, return the sum of the two triangle areas.
*/
double get_area();
/**
* The QUADRILATERAL class implements the virtual get_perimeter() method of the POLYGON class.
*
* The getter method returns the perimeter of the quadrilateral represented by the caller QUADRILATERAL object
* by adding up the four side lengths of that quadrilateral.
*
* Let AB be the length of the line segment whose endpoints are A and B.
* Let BC be the length of the line segment whose endpoints are B and C.
* Let CD be the length of the line segment whose endpoints are C and D.
* Let DA be the length of the line segment whose endpoints are D and A.
*
* Then return the sum of AB, BC, CD, and DA.
*/
double get_perimeter();
/**
* This method overrides the POLYGON class's print method.
*
* The descriptor method prints a description of the caller QUADRILATERAL instance to the output stream.
*
* If no function input is supplied, output is set to the command line terminal.
*/
void print(std::ostream & output = std::cout);
/**
* The friend function is an alternative to the print method.
* The friend function overloads the ostream operator (i.e. <<).
*
* The friend function is not a member of the QUADRILATERAL class,
* but the friend function does have access to the private and protected members of the QUADRILATERAL class as though
* the friend function was a member of the QUADRILATERAL class.
*/
friend std::ostream & operator << (std::ostream & output, QUADRILATERAL & quadrilateral);
/**
* The destructor method of the QUADRILATERAL class de-allocates memory which was used to
* instantiate the QUADRILATERAL object which is calling this function.
*
* The destructor method of the QUADRILATERAL class is automatically called when
* the program scope in which the caller QUADRILATERAL object was instantiated terminates.
*/
~QUADRILATERAL();
};
/* preprocessing directives */
#endif // Terminate the conditional preprocessing directives code block in this header file.
</pre>
<hr />
<p><strong>QUADRILATERAL_CLASS_SOURCE_CODE</strong></p>
<hr />
<p>The following source code defines the functions of the QUADRILATERAL class.</p>
<p>C++_source_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/quadrilateral.cpp" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/quadrilateral.cpp</a></p>
<hr />
<pre>/**
* file: quadrilateral.cpp
* type: C++ (source file)
* date: 07_JULY_2023
* author: karbytes
* license: PUBLIC_DOMAIN
*/
// Include the C++ header file which contains preprocessing directives, variable declarations, and function prototypes for the QUADRILATERAL class.
#include "quadrilateral.h"
/**
* If each of the four whole number coordinate pairs represented by the POINT type input values named _A, _B, _C, and _D are unique whole number coordinate pairs,
* return true.
* Otherwise, return false.
*/
bool QUADRILATERAL::points_represent_unique_coordinate_pairs(POINT _A, POINT _B, POINT _C, POINT _D)
{
if ((_A.get_X() == _B.get_X()) && (_A.get_Y() == _B.get_Y())) return false;
if ((_A.get_X() == _C.get_X()) && (_A.get_Y() == _C.get_Y())) return false;
if ((_A.get_X() == _D.get_X()) && (_A.get_Y() == _D.get_Y())) return false;
if ((_B.get_X() == _C.get_X()) && (_B.get_Y() == _C.get_Y())) return false;
if ((_B.get_X() == _D.get_X()) && (_B.get_Y() == _D.get_Y())) return false;
if ((_C.get_X() == _D.get_X()) && (_C.get_Y() == _D.get_Y())) return false;
return true;
}
/**
* If sum of the interior angle measurements of the quadrilateral which the caller QUADRILATERAL object represents add up to approximately 360 degrees,
* return true.
* Otherwise, return false.
*/
bool QUADRILATERAL::interior_angles_add_up_to_360_degrees()
{
double a0 = 0.0, b0 = 0.0, c0 = 0.0;
double a1 = 0.0, b1 = 0.0, c1 = 0.0;
double angle_opposite_of_a0 = 0.0, angle_opposite_of_b0 = 0.0, angle_opposite_of_c0 = 0.0;
double angle_opposite_of_a1 = 0.0, angle_opposite_of_b1 = 0.0, angle_opposite_of_c1 = 0.0;
double interior_angle_of_A = 0.0, interior_angle_of_B = 0.0, interior_angle_of_C = 0.0, interior_angle_of_D = 0.0;
double sum_of_interior_angles = 0.0;
// first triangle
a0 = A.get_distance_from(B);
b0 = B.get_distance_from(D);
c0 = D.get_distance_from(A);
angle_opposite_of_a0 = acos(((b0 * b0) + (c0 * c0) - (a0 * a0)) / (2 * b0 * c0)) * (180 / PI);
angle_opposite_of_b0 = acos(((a0 * a0) + (c0 * c0) - (b0 * b0)) / (2 * a0 * c0)) * (180 / PI);
angle_opposite_of_c0 = acos(((a0 * a0) + (b0 * b0) - (c0 * c0)) / (2 * a0 * b0)) * (180 / PI);
// second triangle
a1 = D.get_distance_from(B);
b1 = B.get_distance_from(C);
c1 = C.get_distance_from(D);
angle_opposite_of_a1 = acos(((b1 * b1) + (c1 * c1) - (a1 * a1)) / (2 * b1 * c1)) * (180 / PI);
angle_opposite_of_b1 = acos(((a1 * a1) + (c1 * c1) - (b1 * b1)) / (2 * a1 * c1)) * (180 / PI);
angle_opposite_of_c1 = acos(((a1 * a1) + (b1 * b1) - (c1 * c1)) / (2 * a1 * b1)) * (180 / PI);
interior_angle_of_A = angle_opposite_of_b0;
interior_angle_of_B = angle_opposite_of_c0 + angle_opposite_of_c1;
interior_angle_of_C = angle_opposite_of_a1;
interior_angle_of_D = angle_opposite_of_b1 + angle_opposite_of_a0;
sum_of_interior_angles = interior_angle_of_A + interior_angle_of_B + interior_angle_of_C + interior_angle_of_D;
// Allow for there to be a +/- 2 margin of error for the value stored in sum_of_interior_angles with the ideal value being 360.
if ((sum_of_interior_angles >= 358) && (sum_of_interior_angles <= 362)) return true;
return false;
}
/**
* The test function helps to illustrate how pointers work.
*/
int QUADRILATERAL::quadrilateral_test()
{
return 555;
}
/**
* The default constructor of the QUADRILATERAL class calls the constructor of the POLYGON class and
* sets the POINT type data member of the QUADRILATERAL object returned by this function named A to POINT(0,0),
* sets the POINT type data member of the QUADRILATERAL object returned by this function named B to POINT(0,5),
* sets the POINT type data member of the QUADRILATERAL object returned by this function named C to POINT(4,5), and
* sets the POINT type data member of the QUADRILATERAL object returned by this function named D to POINT(4,0).
*/
QUADRILATERAL::QUADRILATERAL()
{
std::cout << "\n\nCreating the QUADRILATERAL type object whose memory address is " << this << "...";
A = POINT(0,0);
B = POINT(0,5);
C = POINT(4,5);
D = POINT(4,0);
}
/**
* The normal constructor of QUADRILATERAL attempts to set
* the string type data member of this to the input string type value named color and
* the POINT type data member of this named A to the input POINT type value named A and
* the POINT type data member of this named B to the input POINT type value named B and
* the POINT type data member of this named C to the input POINT type value named C and
* the POINT type data member of this named D to the input POINT type value named D.
*
* (The keyword this refers to the QUADRILATERAL object which is returned by this function).
*
* If A, B, C, and D represent unique points on a Cartesian plane and
* if the interior angles of the quadrilateral which those points would represent add up to 360 degrees and
* if the area of the quadrilateral which those points represents is larger than zero,
* use the input POINT values as the POINT values for the QUADRILATERAL object which is returned by this function.
*/
QUADRILATERAL::QUADRILATERAL(std::string color, POINT A, POINT B, POINT C, POINT D)
{
std::cout << "\n\nCreating the QUADRILATERAL type object whose memory address is " << this << "...";
QUADRILATERAL test_quadrilateral;
test_quadrilateral.A.set_X(A.get_X());
test_quadrilateral.A.set_Y(A.get_Y());
test_quadrilateral.B.set_X(B.get_X());
test_quadrilateral.B.set_Y(B.get_Y());
test_quadrilateral.C.set_X(C.get_X());
test_quadrilateral.C.set_Y(C.get_Y());
test_quadrilateral.D.set_X(D.get_X());
test_quadrilateral.D.set_Y(D.get_Y());
if (points_represent_unique_coordinate_pairs(A, B, C, D) && test_quadrilateral.interior_angles_add_up_to_360_degrees() && (test_quadrilateral.get_area() > 0))
{
this -> A = A;
this -> B = B;
this -> C = C;
this -> D = D;
}
else
{
this -> A = POINT(0,0);
this -> B = POINT(0,5);
this -> C = POINT(4,5);
this -> D = POINT(4,0);
}
this -> color = color;
}
/**
* The copy constructor method of the QUADRILATERAL class
* instantiates QUADRILATERAL type objects
* whose A value is set to the A value of the input QUADRILATERAL object,
* whose B value is set to the B value of the input QUADRILATERAL object,
* whose C value is set to the C value of the input QUADRILATERAL object, and
* whose D value is set to the D value of the input QUADRILATERAL object.
*/
QUADRILATERAL::QUADRILATERAL(QUADRILATERAL & quadrilateral)
{
std::cout << "\n\nCreating the QUADRILATERAL type object whose memory address is " << this << "...";
A = quadrilateral.A;
B = quadrilateral.B;
C = quadrilateral.C;
D = quadrilateral.D;
color = quadrilateral.color;
}
/**
* The QUADRILATERAL class implements the virtual get_area() method of the POLYGON class.