This repository has been archived by the owner on Dec 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
P13_PROBABILITY_23_OCTOBER_2022_COPY.html
1705 lines (1591 loc) · 89.2 KB
/
P13_PROBABILITY_23_OCTOBER_2022_COPY.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>PROBABILITY_23_OCTOBER_2022_COPY</strong></p>
<hr>
<p>* * *</p>
<p>START OF WEB PAGE COPY</p>
<p>* * *</p>
<hr>
<p><strong>PROBABILITY</strong></p>
<hr>
<p><span style="background:#ffff00;">The C++ program featured in this tutorial web page generates a dynamically-allocated one-dimensional array of int-type values named A and a dynamically-allocated two-dimensional array of int type values named B. A represents a contiguous block of memory consisting of exactly S int-sized contiguous chunks of memory (and S is a natural number). B represents a contiguous block of memory consisting of exactly T int-sized contiguous chunks of memory (and T is natural number). Each of the S int-sized chunks of memory comprising array A is assigned some random nonnegative integer value which is less than T. The elements of array B are each a one-dimensional array for storing exactly two int-type values.</span></p>
<p>The first int-type value of the ith subarray i of B (i.e. B[i][0]) represents a possible value occurring as an element of array A (such that int-sized memory chunk represented by B[i][0] stores the value i (and i is a nonnegative integer less than T)).</p>
<p>The second int-type value of the ith subarray of B (i.e. B[i][1]) represents the frequency at which i occurs as an element of array A (such that the int-sized memory chunk represented by B[i][1] stores the frequency at which i occurs as an element of array A (and B[i][1] is a nonnegative integer less than or equal to S)).</p>
<p>A histogram visually depicting the frequency array is printed to the command line and as write-only file output (along with statistics about such as the average value in A, the largest value in A, and the smallest value in A).</p>
<p><strong><em>To view hidden text inside of the preformatted text boxes below, scroll horizontally.</em></strong></p>
<p><span style="background:#00ff00;">Theoretically speaking, each of the T possible unique integer values which <a style="background:#ff9000;color:#000000;" href="https://en.wikipedia.org/wiki/Randomness" target="_blank" rel="noopener">randomly</a> occur in A have the same probability of occurring (and that <strong>probability</strong> is the rational number (1/T)).</span></p>
<hr>
<p><strong>Software Application Files</strong></p>
<hr>
<p>C++ source file: <a style="background:#000000;color:#00ff00;" href="https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/probability.cpp" target="_blank" rel="noopener">https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/probability.cpp</a></p>
<p>plain-text file: <a style="background:#000000;color:#ff9000;" href="https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/probability_output.txt" target="_blank" rel="noopener">https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/probability_output.txt</a></p>
<p>plain-text file: <a style="background:#000000;color:#ff9000;" href="https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/probability_output_(large_S_small_T).txt" target="_blank" rel="noopener">https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/probability_output_(large_S_small_T).txt</a></p>
<p>plain-text file: <a style="background:#000000;color:#ff9000;" href="https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/probability_output_(small_S_large_T).txt" target="_blank" rel="noopener">https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/probability_output_(small_S_large_T).txt</a></p>
<hr>
<p><strong>Program Compilation & Execution</strong></p>
<hr>
<p>STEP_0: Copy and paste the C++ <a style="background:#000000;color:#00ff00;" href="https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/probability.cpp" target="_blank" rel="noopener">source code</a> into a new text editor document and save that document as the following file name:</p>
<pre>probability.cpp</pre>
<p>STEP_1: Open a Unix 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++ probability.cpp -o app</pre>
<p>STEP_3: If the program compilation command does not work, then use the following command to install the C++ compiler:</p>
<pre>sudo apt install build-essential</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: Once the application is running, the following prompt will appear:</p>
<pre>Enter a natural number value, S, which is no larger than 1000 (and which will be used as the number of elements to include in an array of random integers):</pre>
<p>STEP_6: Enter a value for S using the using the keyboard.</p>
<p>STEP_7: After a valid input value for S is entered, the following prompt will appear:</p>
<pre>Enter a natural number value, T, which is no larger than 1000 (and which will be used as the maximum number of unique states which each array element may represent):</pre>
<p>STEP_8: Enter a value for T using the using the keyboard.</p>
<p>STEP_9: Observe program results on the command line terminal and in the <a style="background:#000000;color:#ff9000;" href="https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/probability_output.txt" target="_blank" rel="noopener">output file</a>.</p>
<hr>
<p><strong>Program Source Code</strong></p>
<hr>
<p>C++ source file: <a style="background:#000000;color:#00ff00;" href="https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/probability.cpp" target="_blank" rel="noopener">https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/probability.cpp</a></p>
<p><strong><em>When copy-pasting the source code from the preformatted text box below into a text editor document, remove the spaces between the angle brackets and the library names in the preprocessing directives code block.</em></strong></p>
<hr>
<pre>/**
* file: probability.cpp
* type: C++ (source file)
* date: 10_OCTOBER_2022
* author: Karlina Ray Beringer
* license: PUBLIC_DOMAIN
*/
/**
* Preprocessing Directives
*/
#include < iostream > // standard input and output operations (command line terminal and keyboard)
#include < fstream > // file input and output operations (text file generation)
#include < stdio.h > // library which contains NULL macro
#include < stdlib.h > // library for srand() and rand() functions
#include < time.h > // library for time() function
#define MAXIMUM_S 1000 // upper limit constant for values of S
#define MAXIMUM_T 1000 // upper limit constant for values of T
/**
* Function Prototypes
*/
void bubble_sort(int * A, int S);
int ** get_frequency_array(int * A, int S, int T);
double get_average_array_value(int * A, int S);
int get_smallest_array_value(int * A, int S);
int get_largest_array_value(int * A, int S);
void print_histogram(int * A, int S, int T, std::ostream & output);
/**
* Use the Bubble Sort sorting algorithm to arrange the elements of array A in ascending order.
*
* Note that, even though this function returns no value, the array which the pointer variable points to is updated.
*
* Assume that there are at least S consecutive int-sized chunks of memory allocated to array A
* (and that S is a natural number no larger than MAXIMUM_S).
*/
void bubble_sort(int * A, int S)
{
int i = 0, placeholder = 0;
bool array_is_sorted = false, adjacent_elements_were_swapped = false;
while (!array_is_sorted)
{
adjacent_elements_were_swapped = false;
for (i = 1; i < S; i += 1)
{
if (A[i] < A[i - 1])
{
placeholder = A[i];
A[i] = A[i - 1];
A[i - 1] = placeholder;
adjacent_elements_were_swapped = true;
}
}
if (!adjacent_elements_were_swapped) array_is_sorted = true;
}
}
/**
* Return a pointer to a two-dimensional array which represents the number of times each unique
* int-type value of array A occurs inside of array A.
*
* (The maximum number of times a unique integer value may occur as a data element of array A is S).
*
* (The minimum number of times a unique integer value may occur as a data element of array A is 0).
*
* (The maximum number of times a unique integer value may occur as a data element of array B is T).
*
* (The minimum number of times a unique integer value may occur as a data element of array B is 0).
*
* The returned array is a dynamically allocated variable (i.e. a variable which is
* instantiated during program runtime instead of during program compile time
* (which means that the amount of memory to allocate to array A (and, hence, to array B) is unknown
* until the program user inputs the total number of elements to include in array A during program runtime)).
*
* Assume that there are at least S consecutive int-sized chunks of memory allocated to array A
* (and that S is a natural number no larger than MAXIMUM_S).
*
* Assume that T is a natural number no larger than MAXIMUM_T.
*
* Each element of the output array is an int-type array consisting of 2 elements:
*
* The lefthand element of the ith element of the output array, B[i][0],
* stores a unique nonnegative integer no larger than (T - 1).
*
* The righthand element of the ith element of the output array,
* B[i][1], stores the nonnegative number of times
* each unique nonnegative integer no larger than T occurs in A.
*
* The returned array, B, will have a total of T elements.
*
* The returned array will logically resemble a two-dimensional grid
* whose left-column values are each nonnegative integers no larger than T
* which are arranged in ascending order starting at the first element of B (i.e. B[0])
* and ending at the last element of B (i.e. B[T - 1])
* and whose right-column values are each nonnegative integers no larger than S.
*/
int ** get_frequency_array(int * A, int S, int T)
{
int i = 0, k = 0;
int ** B = new int * [T];
for (i = 0; i < T; i += 1) B[i] = new int[2];
for (i = 0; i < T; i += 1) B[i][0] = i;
for (i = 0; i < T; i += 1)
{
for (k = 0; k < S; k += 1) if (A[k] == B[i][0]) B[i][1] += 1;
}
return B;
}
/**
* Return the sum of each of the S int-type values which are stored in the array named A divided by S.
*
* Assume that there are at least S consecutive int-sized chunks of memory allocated to array A
* (and that S is a natural number no larger than MAXIMUM_S).
*/
double get_average_array_value(int * A, int S)
{
int i = 0, sum_of_values = 0;
for (i = 0; i < S; i += 1) sum_of_values += A[i];
return sum_of_values / S;
}
/**
* Return the smallest integer value occurring inside of the array named A.
*
* Assume that there are at least S consecutive int-sized chunks of memory allocated to array A
* (and that S is a natural number no larger than MAXIMUM_S).
*/
int get_smallest_array_value(int * A, int S)
{
int i = 0, smallest_value = 0;
int * A_copy = new int[S];
for (i = 0; i < S; i += 1) A_copy[i] = A[i];
bubble_sort(A_copy, S);
smallest_value = A_copy[0];
delete [] A_copy;
return smallest_value;
}
/**
* Return the largest integer value occurring inside of the array named A.
*
* Assume that there are at least S consecutive int-sized chunks of memory allocated to array A
* (and that S is a natural number no larger than MAXIMUM_S).
*/
int get_largest_array_value(int * A, int S)
{
int i = 0, largest_value = 0;
int * A_copy = new int[S];
for (i = 0; i < S; i += 1) A_copy[i] = A[i];
bubble_sort(A_copy, S);
largest_value = A_copy[S - 1];
delete [] A_copy;
return largest_value;
}
/**
* Print a histogram which displays the number of times each unique integer value occurs inside of the array named A.
*
* Assume that there are at least S consecutive int-sized chunks of memory allocated to array A
* (and that S is a natural number no larger than MAXIMUM_S).
*
* Assume that T is a natural number no larger than MAXIMUM_T
* (and that each of the values of A is no smaller than 0 and no larger than (T - 1)).
*
* The maximum number of histogram rows to print is T (i.e. the number unique states which each element of A may represent).
* If T histogram rows are printed by the time this function terminates, then each element of A stores a unique int-type value.
*
* The minimum number of histogram rows to print is 1.
* If 1 histogram row is printed by the time this function terminates, then each element of A stores the same int-type value.
*/
void print_histogram(int * A, int S, int T, std::ostream & output)
{
int i = 0, k = 0;
int * A_copy = new int [S];
int ** B = new int * [T];
for (i = 0; i < S; i += 1) A_copy[i] = A[i];
bubble_sort(A_copy, S);
B = get_frequency_array(A, S, T);
output << "\n\nHistogram of Unique Array Value Frequencies:";
for (i = 0; i < T; i += 1)
{
output << "\n" << B[i][0] << ": ";
for (k = 0; k < B[i][1]; k += 1) output << "X";
output << " (" << B[i][1] << ")";
}
delete [] A_copy;
for (int i = 0; i < T; i += 1) delete [] B[i];
delete [] B;
}
/**
* Program Entry Point
*/
int main()
{
// Declare a write-only file stream object.
std::ofstream fout;
// Declare a pointer to an int-sized block of memory.
int * A;
// Declare a pointer to a pointer to an int-sized block of memory.
int ** B;
// Declare and initialize 4 int type variables.
int i = 0, S = 1, T = 1, N = 0;
// Set the number of digits of floating point numbers which are printed to the command line to 50.
// Set the number of digits of floating point numbers which are printed to the output file stream to 50.
std::cout.precision(50);
fout.precision(50);
/**
* If the plain-text file named probability_output.txt exists in the same file directory as probability.cpp,
* then set probability_output.txt to be overwritten with program data.
*
* Otherwise, create a plain-text file named probability_output.txt in the same file directory as probability.cpp
* and set probability_output.txt to be overwritten with program data.
*/
fout.open("probability_output.txt");
// Print an opening message to the command line terminal.
std::cout << "\n\n--------------------------------";
std::cout << "\nStart Of Program";
std::cout << "\n--------------------------------";
// Print an opening message to the file output stream.
fout << "--------------------------------";
fout << "\nStart Of Program";
fout << "\n--------------------------------";
// Print the declare the int pointer named A to the command line terminal.
// Print the declare the int pointer named A to the file output stream.
std::cout << "\n\n// Declare a pointer to an int-sized block of memory.";
std::cout << "\nint * A;";
fout << "\n\n// Declare a pointer to an int-sized block of memory.";
fout << "\nint * A;";
// Print the declare the double int pointer named B to the command line terminal.
// Print the declare the doubke int ointer named B to the file output stream.
std::cout << "\n\n// Declare a pointer to a pointer to an int-sized block of memory.";
std::cout << "\nint ** B;";
fout << "\n\n// Declare a pointer to a pointer to an int-sized block of memory.";
fout << "\nint ** B;";
// Print a message to the command line terminal which asks the user to enter a natural number value for S.
// Print a message to the command line terminal which asks the user to enter a natural number value for S.
std::cout << "\n\nEnter a natural number value, S, which is no larger than " << MAXIMUM_S << " (and which will be used as the number of elements to include in an array of random integers): ";
fout << "\n\nEnter a natural number value, S, which is no larger than " << MAXIMUM_S << " (and which will be used as the number of elements to include in an array of random integers): ";
// Scan the command line for keyboard input and store that value inside the int type variable named S.
std::cin >> S;
// If S is smaller than 1 or if S is larger than MAXIMUM_S, then set S to 1.
S = ((S < 1) || (S > MAXIMUM_S)) ? 1 : S;
// Print a message describing the value of the variable named S to the command line terminal.
// Print a message describing the value of the variable named S to to the output file stream.
std::cout << "\n\nS := " << S << ".";
fout << "\n\nS := " << S << ".";
// Print a message to the command line terminal which asks the user to enter a natural number value for T.
// Print a message to the command line terminal which asks the user to enter a natural number value for S.
std::cout << "\n\nEnter a natural number value, T, which is no larger than " << MAXIMUM_T << " (and which will be used as the maximum number of unique states which each array element may represent): ";
fout << "\n\nEnter a natural number value, T, which is no larger than " << MAXIMUM_T << " (and which will be used as the maximum number of unique states which each array element may represent): ";
// Scan the command line for keyboard input and store that value inside the int type variable named T.
std::cin >> T;
// If T is smaller than 1 or if S is larger than MAXIMUM_T, then set T to 1.
T = ((T < 1) || (T > MAXIMUM_T)) ? 1 : T;
// Print a message describing the value of the variable named T to the command line terminal.
// Print a message describing the value of the variable named T to to the output file stream.
std::cout << "\n\nT := " << T << ".";
fout << "\n\nT := " << T << ".";
// Allocate S consecutive int-sized blocks of memory to the instantiation of array A.
// A is a pointer which stores the address of the first memory cell of that chunk of S consecutive int-sized blocks of memory.
A = new int[S];
// Print the command to instatiate dynamic array A to the command line terminal.
// Print the command to instatiate dynamic array A to the file output stream.
std::cout << "\n\n// Allocate S consecutive int-sized blocks of memory to the instantiation of array A.";
std::cout << "\n// A is a pointer which stores the address of the first memory cell of that chunk of S consecutive int-sized blocks of memory.";
std::cout << "\nA = new int[S];";
fout << "\n\n// Allocate S consecutive int-sized blocks of memory to the instantiation of array A.";
fout << "\n// A is a pointer which stores the address of the first memory cell of that chunk of S consecutive int-sized blocks of memory.";
fout << "\nA = new int[S];";
// Print "Display the Initial Contents of Array A:" to the command line terminal.
// Print "Display the Initial Contents of Array A:" to the file output stream.
std::cout << "\n\nDisplay the Initial Contents of Array A:\n";
fout << "\n\nDisplay the Initial Contents of Array A:\n";
// For each element A[i] of array A (whose length is S),
// increment i by one
// starting at i = 0
// and ending at i = (S - 1)...
for (i = 0; i < S; i += 1)
{
// Print a description of the ith element of array A to the command line terminal.
// Print a description of the ith element of array A to the file output stream.
// (The default value of each array element should be 0).
std::cout << "\nA[" << i << "] := " << A[i] << ". (memory address of A[" << i << "] is " << &A[i] << ").";
fout << "\nA[" << i << "] := " << A[i] << ". (memory address of A[" << i << "] is " << &A[i] << ").";
}
// Seed the pseudo random number generator with the integer number of seconds which have elapsed since the Unix Epoch (i.e. midnight of 01_JANUARY_1970).
srand(time(NULL));
// Print the command to seed the pseudo random number generator to the command line.
// Print the command to seed the pseudo random number generator to the file output stream.
std::cout << "\n\n// Seed the pseudo random number generator with the integer number of seconds which have elapsed since the Unix Epoch (i.e. midnight of 01_JANUARY_1970).";
std::cout << "\nsrand(time(NULL));";
fout << "\n\n// Seed the pseudo random number generator with the integer number of seconds which have elapsed since the Unix Epoch (i.e. midnight of 01_JANUARY_1970).";
fout << "\nsrand(time(NULL));";
// Print "Set Each Element of Array A to a Random Nonnegative Integer No Larger Than T:" to the command line terminal.
// Print "Set Each Element of Array A to a Random Nonnegative Integer No Larger Than T:" to the file output stream.
std::cout << "\n\nSet Each Element of Array A to a Random Nonnegative Integer No Larger Than T:\n";
fout << "\n\nSet Each Element of Array A to a Random Nonnegative Integer No Larger Than T:\n";
// For each element A[i] of array A (whose length is S),
// increment i by one
// starting at i = 0
// and ending at i = (S - 1)...
for (i = 0; i < S; i += 1)
{
// Randomly select one of T possible states from a set of T unique states (i.e. the first T nonnegative integers).
// Store that value inside of variable the int type variable named N.
// The modulo operator (%) is used to compute the remainder of dividing the lefthand operand (rand()) by the righthand operand (T). That remainder is an integer value.
N = rand() % T;
// Set the value of the ith element of A to N.
A[i] = N;
// Print a description of the ith element of array A to the command line terminal.
// Print a description of the ith element of array A to the file output stream.
std::cout << "\nA[" << i << "] := rand() % T := " << A[i] << ". (memory address of A[" << i << "] is " << &A[i] << ").";
fout << "\nA[" << i << "] := rand() % T := " << A[i] << ". (memory address of A[" << i << "] is " << &A[i] << ").";
}
// Sort the integer values stored in array A in ascending order.
bubble_sort(A, S);
// Print the command to sort the integer values stored in array A in ascending order to the command line.
// Print the command to sort the integer values stored in array A in ascending order to the file output stream.
std::cout << "\n\n// Sort the integer values stored in array A in ascending order.";
std::cout << "\nbubble_sort(A, S);";
fout << "\n\n// Sort the integer values stored in array A in ascending order.";
fout << "\nbubble_sort(A, S);";
// Print "Display the Contents of Array A in Ascending Order:" to the command line terminal.
// Print "Display the Contents of Array A in Ascending Order:" to the file output stream.
std::cout << "\n\nDisplay the Contents of Array A in Ascending Order:\n";
fout << "\n\nDisplay the Contents of Array A in Ascending Order:\n";
// For each element A[i] of array A (whose length is S),
// increment i by one
// starting at i = 0
// and ending at i = (S - 1)...
for (i = 0; i < S; i += 1)
{
// Print a description of the ith element of array A to the command line terminal.
// Print a description of the ith element of array A to the file output stream.
std::cout << "\nA[" << i << "] := " << A[i] << ". (memory address of A[" << i << "] is " << &A[i] << ").";
fout << "\nA[" << i << "] := " << A[i] << ". (memory address of A[" << i << "] is " << &A[i] << ").";
}
// Assign double pointer B to address of the first memory cell constituting a two-dimensional array.
// B represents a grid consisting of T rows and 2 columns.
B = get_frequency_array(A, S, T);
// Print the command to instantiate a two-dimensional array and store its address in B to the command line.
// Print the command to instantiate a two-dimensional array and store its address in B to the file output stream.
std::cout << "\n\n// Assign double pointer B to address of the first memory cell constituting a two-dimensional array.";
std::cout << "\n// B represents a grid consisting of T rows and 2 columns.";
std::cout << "\nB = get_frequency_array(A, S, T);";
fout << "\n\n// Assign double pointer B to address of the first memory cell constituting a two-dimensional array.";
fout << "\n// B represents a grid consisting of T rows and 2 columns.";
fout << "\nB = get_frequency_array(A, S, T);";
// Print "Display the Contents of Two-Dimensional Array B:" to the command line terminal.
// Print "Display the Contents of Two-Dimensional Array B:" to the file output stream.
std::cout << "\n\nDisplay the Contents of Two-Dimensional Array B:\n";
fout << "\n\nDisplay the Contents of Two-Dimensional Array B:\n";
// For each element B[i] of array B (whose length is T),
// increment i by one
// starting at i = 0
// and ending at i = (T - 1)...
for (i = 0; i < T; i += 1)
{
// Print a description of the ith element of array B to the command line terminal.
// Print a description of the ith element of array B to the file output stream.
std::cout << "\n------------------------------------------------";
std::cout << "\nFrequency of value " << B[i][0] << " in array A is " << B[i][1] << ".";
std::cout << "\n------------------------------------------------";
std::cout << "\nB[" << i << "][0] := " << B[i][0] << ". (memory address of B[" << i << "][0] is " << &B[i][0] << ").";
std::cout << "\nB[" << i << "][1] := " << B[i][1] << ". (memory address of B[" << i << "][1] is " << &B[i][1] << ").";
fout << "\n------------------------------------------------";
fout << "\nFrequency of value " << B[i][0] << " in array A is " << B[i][1] << ".";
fout << "\n------------------------------------------------";
fout << "\nB[" << i << "][0] := " << B[i][0] << ". (memory address of B[" << i << "][0] is " << &B[i][0] << ").";
fout << "\nB[" << i << "][1] := " << B[i][1] << ". (memory address of B[" << i << "][1] is " << &B[i][1] << ").";
}
// Verify that the sum of the frequencies of unique values in A is the same as the total number of elements in A.
N = 0;
for (i = 0; i < T; i += 1) N += B[i][1];
// Print the sum of the counts of each unique value which is stored in array B to the command line.
// Print the sum of the counts of each unique value which is stored in array B to the file output stream.
std::cout << "\n\n// Verify that the sum of the frequencies of unique values in A is the same as the total number of elements in A.";
std::cout << "\nN = 0;";
std::cout << "\nfor (i = 0; i < T; i += 1) N += B[i][1];";
std::cout << "\nN := " << N << ". // which should be identical to S.";
fout << "\n\n// Verify that the sum of the frequencies of unique values in A is the same as the total number of elements in A.";
fout << "\nN = 0;";
fout << "\nfor (i = 0; i < T; i += 1) N += B[i][1];";
fout << "\nN := " << N << ". // which should be identical to S.";
// Print the average value of A to the command line terminal.
// Print the average value of A to the file output steam.
std::cout << "\n\nget_average_array_value(A, S) := " << get_average_array_value(A, S) << ".";
fout << "\n\nget_average_array_value(A, S) := " << get_average_array_value(A, S) << ".";
// Print the smallest value of A to the command line terminal.
// Print the smallest value of A to the file output steam.
std::cout << "\n\nget_smallest_array_value(A, S) := " << get_smallest_array_value(A, S) << ".";
fout << "\n\nget_smallest_array_value(A, S) := " << get_smallest_array_value(A, S) << ".";
// Print the largest value of A to the command line terminal.
// Print the largest value of A to the file output steam.
std::cout << "\n\nget_largest_array_value(A, S) := " << get_largest_array_value(A, S) << ".";
fout << "\n\nget_largest_array_value(A, S) := " << get_largest_array_value(A, S) << ".";
// Print a description about how much data each of the dynamocally allocated arrays represents to the command line terminal.
std::cout << "\n\n* * *";
std::cout << "\nsizeof(int) := " << sizeof(int) << " byte(s).";
std::cout << "\nThe number of bytes of contiguous memory allocated to array A is: (sizeof(int) * S) = (" << sizeof(int) << " * " << S << ") = " << sizeof(int) * S << ".";
std::cout << "\nThe number of bytes of contiguous memory allocated to array B is: (sizeof(int) * T) = (" << sizeof(int) << " * " << T << ") = " << sizeof(int) * T << ".";
std::cout << "\n* * *";
// Print a description about how much data each of the dynamocally allocated arrays represents to the file output stream.
fout << "\n\n* * *";
fout << "\nsizeof(int) := " << sizeof(int) << " byte(s).";
fout << "\nThe number of bytes of contiguous memory allocated to array A is: (sizeof(int) * S) = (" << sizeof(int) << " * " << S << ") = " << sizeof(int) * S << ".";
fout << "\nThe number of bytes of contiguous memory allocated to array B is: (sizeof(int) * T) = (" << sizeof(int) << " * " << T << ") = " << sizeof(int) * T << ".";
fout << "\n* * *";
// Print a histogram which visually depicts the frequency distribution of unique integer values in A to the command line terminal.
// Print a histogram which visually depicts the frequency distribution of unique integer values in A to the file output stream.
// print_histogram(A, S, T, std::cout); // WARNING: Calling the print_histogram function twice in a row using different ostream operators tends to cause the second ostream stream to be populated with garbage data. For that reason, the print_hisogram function call which uses std::cout as the ostream parameter is commented out so that the file output is not polluted.
std::cout << "\n\nCheck the output file to see a histogram of frequencies for each of the unique integer values stored in array A.";
print_histogram(A, S, T, fout);
// Deallocate memory which was assigned to the instantiation of array A during program runtime.
delete [] A;
// Print the command to de-allocate memory which was assigned to the dynamically-allocated array of S int type values to the command line terminal.
// Print the command to de-allocate memory which was assigned to the dynamically-allocated array of S int type values to the file output stream.
std::cout << "\n\n// Deallocate memory which was assigned to the instantiation of array A during program runtime.";
std::cout << "\ndelete [] A;";
fout << "\n\n// Deallocate memory which was assigned to the instantiation of array A during program runtime.";
fout << "\ndelete [] A;";
// Deallocate memory which was assigned to the instantiation of array B during program runtime.
for (int i = 0; i < T; i += 1) delete [] B[i];
delete [] B;
// Print the command to de-allocate memory which was assigned to the dynamically-allocated two-dimensional array named B to the command line terminal.
// Print the command to de-allocate memory which was assigned to the dynamically-allocated two-dimensional array named B to the file output stream.
std::cout << "\n\n// Deallocate memory which was assigned to the instantiation of array B during program runtime.";
std::cout << "\nfor (int i = 0; i < T; i += 1) delete [] B[i];";
std::cout << "\ndelete [] B;\n";
fout << "\n\n// Deallocate memory which was assigned to the instantiation of array B during program runtime.";
fout << "\nfor (int i = 0; i < T; i += 1) delete [] B[i];";
fout << "\ndelete [] B;\n";
// Print a closing message to the command line terminal.
std::cout << "\n--------------------------------";
std::cout << "\nEnd Of Program";
std::cout << "\n--------------------------------\n\n";
// Print a closing message to the file output stream.
fout << "\n--------------------------------";
fout << "\nEnd Of Program";
fout << "\n--------------------------------";
// Terminate the file output stream. Close the file so that program data is saved as lines of plain text in that file.
fout.close();
// program exit point
return 0;
}
</pre>
<hr>
<p><strong>Sample Program Output (Large S, Small T)</strong></p>
<hr>
<p>plain-text file: <a style="background:#000000;color:#ff9000;" href="https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/probability_output_(large_S_small_T).txt" target="_blank" rel="noopener">https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/probability_output_(large_S_small_T).txt</a></p>
<hr>
<pre>--------------------------------
Start Of Program
--------------------------------
// Declare a pointer to an int-sized block of memory.
int * A;
// Declare a pointer to a pointer to an int-sized block of memory.
int ** B;
Enter a natural number value, S, which is no larger than 1000 (and which will be used as the number of elements to include in an array of random integers):
S := 100.
Enter a natural number value, T, which is no larger than 1000 (and which will be used as the maximum number of unique states which each array element may represent):
T := 10.
// Allocate S consecutive int-sized blocks of memory to the instantiation of array A.
// A is a pointer which stores the address of the first memory cell of that chunk of S consecutive int-sized blocks of memory.
A = new int[S];
Display the Initial Contents of Array A:
A[0] := 0. (memory address of A[0] is 0x55d856f758c0).
A[1] := 0. (memory address of A[1] is 0x55d856f758c4).
A[2] := 0. (memory address of A[2] is 0x55d856f758c8).
A[3] := 0. (memory address of A[3] is 0x55d856f758cc).
A[4] := 0. (memory address of A[4] is 0x55d856f758d0).
A[5] := 0. (memory address of A[5] is 0x55d856f758d4).
A[6] := 0. (memory address of A[6] is 0x55d856f758d8).
A[7] := 0. (memory address of A[7] is 0x55d856f758dc).
A[8] := 0. (memory address of A[8] is 0x55d856f758e0).
A[9] := 0. (memory address of A[9] is 0x55d856f758e4).
A[10] := 0. (memory address of A[10] is 0x55d856f758e8).
A[11] := 0. (memory address of A[11] is 0x55d856f758ec).
A[12] := 0. (memory address of A[12] is 0x55d856f758f0).
A[13] := 0. (memory address of A[13] is 0x55d856f758f4).
A[14] := 0. (memory address of A[14] is 0x55d856f758f8).
A[15] := 0. (memory address of A[15] is 0x55d856f758fc).
A[16] := 0. (memory address of A[16] is 0x55d856f75900).
A[17] := 0. (memory address of A[17] is 0x55d856f75904).
A[18] := 0. (memory address of A[18] is 0x55d856f75908).
A[19] := 0. (memory address of A[19] is 0x55d856f7590c).
A[20] := 0. (memory address of A[20] is 0x55d856f75910).
A[21] := 0. (memory address of A[21] is 0x55d856f75914).
A[22] := 0. (memory address of A[22] is 0x55d856f75918).
A[23] := 0. (memory address of A[23] is 0x55d856f7591c).
A[24] := 0. (memory address of A[24] is 0x55d856f75920).
A[25] := 0. (memory address of A[25] is 0x55d856f75924).
A[26] := 0. (memory address of A[26] is 0x55d856f75928).
A[27] := 0. (memory address of A[27] is 0x55d856f7592c).
A[28] := 0. (memory address of A[28] is 0x55d856f75930).
A[29] := 0. (memory address of A[29] is 0x55d856f75934).
A[30] := 0. (memory address of A[30] is 0x55d856f75938).
A[31] := 0. (memory address of A[31] is 0x55d856f7593c).
A[32] := 0. (memory address of A[32] is 0x55d856f75940).
A[33] := 0. (memory address of A[33] is 0x55d856f75944).
A[34] := 0. (memory address of A[34] is 0x55d856f75948).
A[35] := 0. (memory address of A[35] is 0x55d856f7594c).
A[36] := 0. (memory address of A[36] is 0x55d856f75950).
A[37] := 0. (memory address of A[37] is 0x55d856f75954).
A[38] := 0. (memory address of A[38] is 0x55d856f75958).
A[39] := 0. (memory address of A[39] is 0x55d856f7595c).
A[40] := 0. (memory address of A[40] is 0x55d856f75960).
A[41] := 0. (memory address of A[41] is 0x55d856f75964).
A[42] := 0. (memory address of A[42] is 0x55d856f75968).
A[43] := 0. (memory address of A[43] is 0x55d856f7596c).
A[44] := 0. (memory address of A[44] is 0x55d856f75970).
A[45] := 0. (memory address of A[45] is 0x55d856f75974).
A[46] := 0. (memory address of A[46] is 0x55d856f75978).
A[47] := 0. (memory address of A[47] is 0x55d856f7597c).
A[48] := 0. (memory address of A[48] is 0x55d856f75980).
A[49] := 0. (memory address of A[49] is 0x55d856f75984).
A[50] := 0. (memory address of A[50] is 0x55d856f75988).
A[51] := 0. (memory address of A[51] is 0x55d856f7598c).
A[52] := 0. (memory address of A[52] is 0x55d856f75990).
A[53] := 0. (memory address of A[53] is 0x55d856f75994).
A[54] := 0. (memory address of A[54] is 0x55d856f75998).
A[55] := 0. (memory address of A[55] is 0x55d856f7599c).
A[56] := 0. (memory address of A[56] is 0x55d856f759a0).
A[57] := 0. (memory address of A[57] is 0x55d856f759a4).
A[58] := 0. (memory address of A[58] is 0x55d856f759a8).
A[59] := 0. (memory address of A[59] is 0x55d856f759ac).
A[60] := 0. (memory address of A[60] is 0x55d856f759b0).
A[61] := 0. (memory address of A[61] is 0x55d856f759b4).
A[62] := 0. (memory address of A[62] is 0x55d856f759b8).
A[63] := 0. (memory address of A[63] is 0x55d856f759bc).
A[64] := 0. (memory address of A[64] is 0x55d856f759c0).
A[65] := 0. (memory address of A[65] is 0x55d856f759c4).
A[66] := 0. (memory address of A[66] is 0x55d856f759c8).
A[67] := 0. (memory address of A[67] is 0x55d856f759cc).
A[68] := 0. (memory address of A[68] is 0x55d856f759d0).
A[69] := 0. (memory address of A[69] is 0x55d856f759d4).
A[70] := 0. (memory address of A[70] is 0x55d856f759d8).
A[71] := 0. (memory address of A[71] is 0x55d856f759dc).
A[72] := 0. (memory address of A[72] is 0x55d856f759e0).
A[73] := 0. (memory address of A[73] is 0x55d856f759e4).
A[74] := 0. (memory address of A[74] is 0x55d856f759e8).
A[75] := 0. (memory address of A[75] is 0x55d856f759ec).
A[76] := 0. (memory address of A[76] is 0x55d856f759f0).
A[77] := 0. (memory address of A[77] is 0x55d856f759f4).
A[78] := 0. (memory address of A[78] is 0x55d856f759f8).
A[79] := 0. (memory address of A[79] is 0x55d856f759fc).
A[80] := 0. (memory address of A[80] is 0x55d856f75a00).
A[81] := 0. (memory address of A[81] is 0x55d856f75a04).
A[82] := 0. (memory address of A[82] is 0x55d856f75a08).
A[83] := 0. (memory address of A[83] is 0x55d856f75a0c).
A[84] := 0. (memory address of A[84] is 0x55d856f75a10).
A[85] := 0. (memory address of A[85] is 0x55d856f75a14).
A[86] := 0. (memory address of A[86] is 0x55d856f75a18).
A[87] := 0. (memory address of A[87] is 0x55d856f75a1c).
A[88] := 0. (memory address of A[88] is 0x55d856f75a20).
A[89] := 0. (memory address of A[89] is 0x55d856f75a24).
A[90] := 0. (memory address of A[90] is 0x55d856f75a28).
A[91] := 0. (memory address of A[91] is 0x55d856f75a2c).
A[92] := 0. (memory address of A[92] is 0x55d856f75a30).
A[93] := 0. (memory address of A[93] is 0x55d856f75a34).
A[94] := 0. (memory address of A[94] is 0x55d856f75a38).
A[95] := 0. (memory address of A[95] is 0x55d856f75a3c).
A[96] := 0. (memory address of A[96] is 0x55d856f75a40).
A[97] := 0. (memory address of A[97] is 0x55d856f75a44).
A[98] := 0. (memory address of A[98] is 0x55d856f75a48).
A[99] := 0. (memory address of A[99] is 0x55d856f75a4c).
// Seed the pseudo random number generator with the integer number of seconds which have elapsed since the Unix Epoch (i.e. midnight of 01_JANUARY_1970).
srand(time(NULL));
Set Each Element of Array A to a Random Nonnegative Integer No Larger Than T:
A[0] := rand() % T := 1. (memory address of A[0] is 0x55d856f758c0).
A[1] := rand() % T := 1. (memory address of A[1] is 0x55d856f758c4).
A[2] := rand() % T := 6. (memory address of A[2] is 0x55d856f758c8).
A[3] := rand() % T := 2. (memory address of A[3] is 0x55d856f758cc).
A[4] := rand() % T := 0. (memory address of A[4] is 0x55d856f758d0).
A[5] := rand() % T := 4. (memory address of A[5] is 0x55d856f758d4).
A[6] := rand() % T := 4. (memory address of A[6] is 0x55d856f758d8).
A[7] := rand() % T := 2. (memory address of A[7] is 0x55d856f758dc).
A[8] := rand() % T := 7. (memory address of A[8] is 0x55d856f758e0).
A[9] := rand() % T := 3. (memory address of A[9] is 0x55d856f758e4).
A[10] := rand() % T := 1. (memory address of A[10] is 0x55d856f758e8).
A[11] := rand() % T := 4. (memory address of A[11] is 0x55d856f758ec).
A[12] := rand() % T := 0. (memory address of A[12] is 0x55d856f758f0).
A[13] := rand() % T := 9. (memory address of A[13] is 0x55d856f758f4).
A[14] := rand() % T := 0. (memory address of A[14] is 0x55d856f758f8).
A[15] := rand() % T := 4. (memory address of A[15] is 0x55d856f758fc).
A[16] := rand() % T := 8. (memory address of A[16] is 0x55d856f75900).
A[17] := rand() % T := 7. (memory address of A[17] is 0x55d856f75904).
A[18] := rand() % T := 7. (memory address of A[18] is 0x55d856f75908).
A[19] := rand() % T := 0. (memory address of A[19] is 0x55d856f7590c).
A[20] := rand() % T := 6. (memory address of A[20] is 0x55d856f75910).
A[21] := rand() % T := 3. (memory address of A[21] is 0x55d856f75914).
A[22] := rand() % T := 3. (memory address of A[22] is 0x55d856f75918).
A[23] := rand() % T := 1. (memory address of A[23] is 0x55d856f7591c).
A[24] := rand() % T := 6. (memory address of A[24] is 0x55d856f75920).
A[25] := rand() % T := 8. (memory address of A[25] is 0x55d856f75924).
A[26] := rand() % T := 7. (memory address of A[26] is 0x55d856f75928).
A[27] := rand() % T := 6. (memory address of A[27] is 0x55d856f7592c).
A[28] := rand() % T := 5. (memory address of A[28] is 0x55d856f75930).
A[29] := rand() % T := 3. (memory address of A[29] is 0x55d856f75934).
A[30] := rand() % T := 2. (memory address of A[30] is 0x55d856f75938).
A[31] := rand() % T := 9. (memory address of A[31] is 0x55d856f7593c).
A[32] := rand() % T := 6. (memory address of A[32] is 0x55d856f75940).
A[33] := rand() % T := 9. (memory address of A[33] is 0x55d856f75944).
A[34] := rand() % T := 3. (memory address of A[34] is 0x55d856f75948).
A[35] := rand() % T := 6. (memory address of A[35] is 0x55d856f7594c).
A[36] := rand() % T := 5. (memory address of A[36] is 0x55d856f75950).
A[37] := rand() % T := 9. (memory address of A[37] is 0x55d856f75954).
A[38] := rand() % T := 0. (memory address of A[38] is 0x55d856f75958).
A[39] := rand() % T := 3. (memory address of A[39] is 0x55d856f7595c).
A[40] := rand() % T := 2. (memory address of A[40] is 0x55d856f75960).
A[41] := rand() % T := 2. (memory address of A[41] is 0x55d856f75964).
A[42] := rand() % T := 7. (memory address of A[42] is 0x55d856f75968).
A[43] := rand() % T := 2. (memory address of A[43] is 0x55d856f7596c).
A[44] := rand() % T := 1. (memory address of A[44] is 0x55d856f75970).
A[45] := rand() % T := 0. (memory address of A[45] is 0x55d856f75974).
A[46] := rand() % T := 9. (memory address of A[46] is 0x55d856f75978).
A[47] := rand() % T := 1. (memory address of A[47] is 0x55d856f7597c).
A[48] := rand() % T := 7. (memory address of A[48] is 0x55d856f75980).
A[49] := rand() % T := 6. (memory address of A[49] is 0x55d856f75984).
A[50] := rand() % T := 3. (memory address of A[50] is 0x55d856f75988).
A[51] := rand() % T := 5. (memory address of A[51] is 0x55d856f7598c).
A[52] := rand() % T := 9. (memory address of A[52] is 0x55d856f75990).
A[53] := rand() % T := 6. (memory address of A[53] is 0x55d856f75994).
A[54] := rand() % T := 7. (memory address of A[54] is 0x55d856f75998).
A[55] := rand() % T := 7. (memory address of A[55] is 0x55d856f7599c).
A[56] := rand() % T := 6. (memory address of A[56] is 0x55d856f759a0).
A[57] := rand() % T := 6. (memory address of A[57] is 0x55d856f759a4).
A[58] := rand() % T := 4. (memory address of A[58] is 0x55d856f759a8).
A[59] := rand() % T := 2. (memory address of A[59] is 0x55d856f759ac).
A[60] := rand() % T := 1. (memory address of A[60] is 0x55d856f759b0).
A[61] := rand() % T := 6. (memory address of A[61] is 0x55d856f759b4).
A[62] := rand() % T := 3. (memory address of A[62] is 0x55d856f759b8).
A[63] := rand() % T := 7. (memory address of A[63] is 0x55d856f759bc).
A[64] := rand() % T := 5. (memory address of A[64] is 0x55d856f759c0).
A[65] := rand() % T := 6. (memory address of A[65] is 0x55d856f759c4).
A[66] := rand() % T := 6. (memory address of A[66] is 0x55d856f759c8).
A[67] := rand() % T := 1. (memory address of A[67] is 0x55d856f759cc).
A[68] := rand() % T := 5. (memory address of A[68] is 0x55d856f759d0).
A[69] := rand() % T := 6. (memory address of A[69] is 0x55d856f759d4).
A[70] := rand() % T := 6. (memory address of A[70] is 0x55d856f759d8).
A[71] := rand() % T := 9. (memory address of A[71] is 0x55d856f759dc).
A[72] := rand() % T := 0. (memory address of A[72] is 0x55d856f759e0).
A[73] := rand() % T := 5. (memory address of A[73] is 0x55d856f759e4).
A[74] := rand() % T := 4. (memory address of A[74] is 0x55d856f759e8).
A[75] := rand() % T := 4. (memory address of A[75] is 0x55d856f759ec).
A[76] := rand() % T := 5. (memory address of A[76] is 0x55d856f759f0).
A[77] := rand() % T := 3. (memory address of A[77] is 0x55d856f759f4).
A[78] := rand() % T := 7. (memory address of A[78] is 0x55d856f759f8).
A[79] := rand() % T := 4. (memory address of A[79] is 0x55d856f759fc).
A[80] := rand() % T := 9. (memory address of A[80] is 0x55d856f75a00).
A[81] := rand() % T := 1. (memory address of A[81] is 0x55d856f75a04).
A[82] := rand() % T := 0. (memory address of A[82] is 0x55d856f75a08).
A[83] := rand() % T := 0. (memory address of A[83] is 0x55d856f75a0c).
A[84] := rand() % T := 7. (memory address of A[84] is 0x55d856f75a10).
A[85] := rand() % T := 9. (memory address of A[85] is 0x55d856f75a14).
A[86] := rand() % T := 9. (memory address of A[86] is 0x55d856f75a18).
A[87] := rand() % T := 6. (memory address of A[87] is 0x55d856f75a1c).
A[88] := rand() % T := 5. (memory address of A[88] is 0x55d856f75a20).
A[89] := rand() % T := 3. (memory address of A[89] is 0x55d856f75a24).
A[90] := rand() % T := 0. (memory address of A[90] is 0x55d856f75a28).
A[91] := rand() % T := 9. (memory address of A[91] is 0x55d856f75a2c).
A[92] := rand() % T := 2. (memory address of A[92] is 0x55d856f75a30).
A[93] := rand() % T := 3. (memory address of A[93] is 0x55d856f75a34).
A[94] := rand() % T := 8. (memory address of A[94] is 0x55d856f75a38).
A[95] := rand() % T := 7. (memory address of A[95] is 0x55d856f75a3c).
A[96] := rand() % T := 1. (memory address of A[96] is 0x55d856f75a40).
A[97] := rand() % T := 4. (memory address of A[97] is 0x55d856f75a44).
A[98] := rand() % T := 0. (memory address of A[98] is 0x55d856f75a48).
A[99] := rand() % T := 6. (memory address of A[99] is 0x55d856f75a4c).
// Sort the integer values stored in array A in ascending order.
bubble_sort(A, S);
Display the Contents of Array A in Ascending Order:
A[0] := 0. (memory address of A[0] is 0x55d856f758c0).
A[1] := 0. (memory address of A[1] is 0x55d856f758c4).
A[2] := 0. (memory address of A[2] is 0x55d856f758c8).
A[3] := 0. (memory address of A[3] is 0x55d856f758cc).
A[4] := 0. (memory address of A[4] is 0x55d856f758d0).
A[5] := 0. (memory address of A[5] is 0x55d856f758d4).
A[6] := 0. (memory address of A[6] is 0x55d856f758d8).
A[7] := 0. (memory address of A[7] is 0x55d856f758dc).
A[8] := 0. (memory address of A[8] is 0x55d856f758e0).
A[9] := 0. (memory address of A[9] is 0x55d856f758e4).
A[10] := 0. (memory address of A[10] is 0x55d856f758e8).
A[11] := 1. (memory address of A[11] is 0x55d856f758ec).
A[12] := 1. (memory address of A[12] is 0x55d856f758f0).
A[13] := 1. (memory address of A[13] is 0x55d856f758f4).
A[14] := 1. (memory address of A[14] is 0x55d856f758f8).
A[15] := 1. (memory address of A[15] is 0x55d856f758fc).
A[16] := 1. (memory address of A[16] is 0x55d856f75900).
A[17] := 1. (memory address of A[17] is 0x55d856f75904).
A[18] := 1. (memory address of A[18] is 0x55d856f75908).
A[19] := 1. (memory address of A[19] is 0x55d856f7590c).
A[20] := 1. (memory address of A[20] is 0x55d856f75910).
A[21] := 2. (memory address of A[21] is 0x55d856f75914).
A[22] := 2. (memory address of A[22] is 0x55d856f75918).
A[23] := 2. (memory address of A[23] is 0x55d856f7591c).
A[24] := 2. (memory address of A[24] is 0x55d856f75920).
A[25] := 2. (memory address of A[25] is 0x55d856f75924).
A[26] := 2. (memory address of A[26] is 0x55d856f75928).
A[27] := 2. (memory address of A[27] is 0x55d856f7592c).
A[28] := 2. (memory address of A[28] is 0x55d856f75930).
A[29] := 3. (memory address of A[29] is 0x55d856f75934).
A[30] := 3. (memory address of A[30] is 0x55d856f75938).
A[31] := 3. (memory address of A[31] is 0x55d856f7593c).
A[32] := 3. (memory address of A[32] is 0x55d856f75940).
A[33] := 3. (memory address of A[33] is 0x55d856f75944).
A[34] := 3. (memory address of A[34] is 0x55d856f75948).
A[35] := 3. (memory address of A[35] is 0x55d856f7594c).
A[36] := 3. (memory address of A[36] is 0x55d856f75950).
A[37] := 3. (memory address of A[37] is 0x55d856f75954).
A[38] := 3. (memory address of A[38] is 0x55d856f75958).
A[39] := 3. (memory address of A[39] is 0x55d856f7595c).
A[40] := 4. (memory address of A[40] is 0x55d856f75960).
A[41] := 4. (memory address of A[41] is 0x55d856f75964).
A[42] := 4. (memory address of A[42] is 0x55d856f75968).
A[43] := 4. (memory address of A[43] is 0x55d856f7596c).
A[44] := 4. (memory address of A[44] is 0x55d856f75970).
A[45] := 4. (memory address of A[45] is 0x55d856f75974).
A[46] := 4. (memory address of A[46] is 0x55d856f75978).
A[47] := 4. (memory address of A[47] is 0x55d856f7597c).
A[48] := 4. (memory address of A[48] is 0x55d856f75980).
A[49] := 5. (memory address of A[49] is 0x55d856f75984).
A[50] := 5. (memory address of A[50] is 0x55d856f75988).
A[51] := 5. (memory address of A[51] is 0x55d856f7598c).
A[52] := 5. (memory address of A[52] is 0x55d856f75990).
A[53] := 5. (memory address of A[53] is 0x55d856f75994).
A[54] := 5. (memory address of A[54] is 0x55d856f75998).
A[55] := 5. (memory address of A[55] is 0x55d856f7599c).
A[56] := 5. (memory address of A[56] is 0x55d856f759a0).
A[57] := 6. (memory address of A[57] is 0x55d856f759a4).
A[58] := 6. (memory address of A[58] is 0x55d856f759a8).
A[59] := 6. (memory address of A[59] is 0x55d856f759ac).
A[60] := 6. (memory address of A[60] is 0x55d856f759b0).
A[61] := 6. (memory address of A[61] is 0x55d856f759b4).
A[62] := 6. (memory address of A[62] is 0x55d856f759b8).
A[63] := 6. (memory address of A[63] is 0x55d856f759bc).
A[64] := 6. (memory address of A[64] is 0x55d856f759c0).
A[65] := 6. (memory address of A[65] is 0x55d856f759c4).
A[66] := 6. (memory address of A[66] is 0x55d856f759c8).
A[67] := 6. (memory address of A[67] is 0x55d856f759cc).
A[68] := 6. (memory address of A[68] is 0x55d856f759d0).
A[69] := 6. (memory address of A[69] is 0x55d856f759d4).
A[70] := 6. (memory address of A[70] is 0x55d856f759d8).
A[71] := 6. (memory address of A[71] is 0x55d856f759dc).
A[72] := 6. (memory address of A[72] is 0x55d856f759e0).
A[73] := 6. (memory address of A[73] is 0x55d856f759e4).
A[74] := 7. (memory address of A[74] is 0x55d856f759e8).
A[75] := 7. (memory address of A[75] is 0x55d856f759ec).
A[76] := 7. (memory address of A[76] is 0x55d856f759f0).
A[77] := 7. (memory address of A[77] is 0x55d856f759f4).
A[78] := 7. (memory address of A[78] is 0x55d856f759f8).
A[79] := 7. (memory address of A[79] is 0x55d856f759fc).
A[80] := 7. (memory address of A[80] is 0x55d856f75a00).
A[81] := 7. (memory address of A[81] is 0x55d856f75a04).
A[82] := 7. (memory address of A[82] is 0x55d856f75a08).
A[83] := 7. (memory address of A[83] is 0x55d856f75a0c).
A[84] := 7. (memory address of A[84] is 0x55d856f75a10).
A[85] := 7. (memory address of A[85] is 0x55d856f75a14).
A[86] := 8. (memory address of A[86] is 0x55d856f75a18).
A[87] := 8. (memory address of A[87] is 0x55d856f75a1c).
A[88] := 8. (memory address of A[88] is 0x55d856f75a20).
A[89] := 9. (memory address of A[89] is 0x55d856f75a24).
A[90] := 9. (memory address of A[90] is 0x55d856f75a28).
A[91] := 9. (memory address of A[91] is 0x55d856f75a2c).
A[92] := 9. (memory address of A[92] is 0x55d856f75a30).
A[93] := 9. (memory address of A[93] is 0x55d856f75a34).
A[94] := 9. (memory address of A[94] is 0x55d856f75a38).
A[95] := 9. (memory address of A[95] is 0x55d856f75a3c).
A[96] := 9. (memory address of A[96] is 0x55d856f75a40).
A[97] := 9. (memory address of A[97] is 0x55d856f75a44).
A[98] := 9. (memory address of A[98] is 0x55d856f75a48).
A[99] := 9. (memory address of A[99] is 0x55d856f75a4c).
// Assign double pointer B to address of the first memory cell constituting a two-dimensional array.
// B represents a grid consisting of T rows and 2 columns.
B = get_frequency_array(A, S, T);
Display the Contents of Two-Dimensional Array B:
------------------------------------------------
Frequency of value 0 in array A is 11.
------------------------------------------------
B[0][0] := 0. (memory address of B[0][0] is 0x55d856f75ac0).
B[0][1] := 11. (memory address of B[0][1] is 0x55d856f75ac4).
------------------------------------------------
Frequency of value 1 in array A is 10.
------------------------------------------------
B[1][0] := 1. (memory address of B[1][0] is 0x55d856f75ae0).
B[1][1] := 10. (memory address of B[1][1] is 0x55d856f75ae4).
------------------------------------------------
Frequency of value 2 in array A is 8.
------------------------------------------------
B[2][0] := 2. (memory address of B[2][0] is 0x55d856f75b00).
B[2][1] := 8. (memory address of B[2][1] is 0x55d856f75b04).
------------------------------------------------
Frequency of value 3 in array A is 11.
------------------------------------------------
B[3][0] := 3. (memory address of B[3][0] is 0x55d856f75b20).
B[3][1] := 11. (memory address of B[3][1] is 0x55d856f75b24).
------------------------------------------------
Frequency of value 4 in array A is 9.
------------------------------------------------
B[4][0] := 4. (memory address of B[4][0] is 0x55d856f75b40).
B[4][1] := 9. (memory address of B[4][1] is 0x55d856f75b44).
------------------------------------------------
Frequency of value 5 in array A is 8.
------------------------------------------------
B[5][0] := 5. (memory address of B[5][0] is 0x55d856f75b60).
B[5][1] := 8. (memory address of B[5][1] is 0x55d856f75b64).
------------------------------------------------
Frequency of value 6 in array A is 17.
------------------------------------------------
B[6][0] := 6. (memory address of B[6][0] is 0x55d856f75b80).
B[6][1] := 17. (memory address of B[6][1] is 0x55d856f75b84).
------------------------------------------------
Frequency of value 7 in array A is 12.
------------------------------------------------
B[7][0] := 7. (memory address of B[7][0] is 0x55d856f75ba0).
B[7][1] := 12. (memory address of B[7][1] is 0x55d856f75ba4).
------------------------------------------------
Frequency of value 8 in array A is 3.
------------------------------------------------
B[8][0] := 8. (memory address of B[8][0] is 0x55d856f75bc0).
B[8][1] := 3. (memory address of B[8][1] is 0x55d856f75bc4).
------------------------------------------------
Frequency of value 9 in array A is 11.
------------------------------------------------
B[9][0] := 9. (memory address of B[9][0] is 0x55d856f75be0).
B[9][1] := 11. (memory address of B[9][1] is 0x55d856f75be4).
// Verify that the sum of the frequencies of unique values in A is the same as the total number of elements in A.
N = 0;
for (i = 0; i < T; i += 1) N += B[i][1];
N := 100. // which should be identical to S.
get_average_array_value(A, S) := 4.
get_smallest_array_value(A, S) := 0.
get_largest_array_value(A, S) := 9.
* * *
sizeof(int) := 4 byte(s).
The number of bytes of contiguous memory allocated to array A is: (sizeof(int) * S) = (4 * 100) = 400.
The number of bytes of contiguous memory allocated to array B is: (sizeof(int) * T) = (4 * 10) = 40.
* * *
Histogram of Unique Array Value Frequencies:
0: XXXXXXXXXXX (11)
1: XXXXXXXXXX (10)
2: XXXXXXXX (8)
3: XXXXXXXXXXX (11)
4: XXXXXXXXX (9)
5: XXXXXXXX (8)
6: XXXXXXXXXXXXXXXXX (17)
7: XXXXXXXXXXXX (12)
8: XXX (3)
9: XXXXXXXXXXX (11)
// Deallocate memory which was assigned to the instantiation of array A during program runtime.
delete [] A;
// Deallocate memory which was assigned to the instantiation of array B during program runtime.
for (int i = 0; i < T; i += 1) delete [] B[i];
delete [] B;
--------------------------------
End Of Program
--------------------------------
</pre>
<hr>
<p><strong>Sample Program Output (Small S, Large T)</strong></p>
<hr>
<p>plain-text file: <a style="background:#000000;color:#ff9000;" href="https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/probability_output_(small_S_large_T).txt" target="_blank" rel="noopener">https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/probability_output_(small_S_large_T).txt</a></p>
<hr>
<pre>--------------------------------
Start Of Program
--------------------------------
// Declare a pointer to an int-sized block of memory.
int * A;
// Declare a pointer to a pointer to an int-sized block of memory.