Tally Lab

Background
A researcher wishes to calculate some statistical properties for a collection of
data values. The data values are represented by the array tally.
The indexes of the array represent the possible values of the actual data values
from zero to the maximal value (15 in the example below). Each array location
contains the frequency (number of occurrences) of the value corresponding to its
index. In the example below, tally[4] is 10, which means that the value 4 occurs
ten times in the collection of data; whereas tally[8] is 0, which means that
the value 8 does not occur in the data collection.

tally

Value      0   1    2   3   4   5   6   7   8   9   10   11   12   13   14    15
Frequency  0   0   10   5  10   0   7   1   0   6    0   10    3    0    0     1

Assignment Part 1 - "Tally" array

Assignment Part 2 - findMax() function
Assignment Part 3 - calculateModes() function
Assignment Part 4 - kthDataValue() function

C programming examples

  1. Compiling C and C++ programs
  2. keyboard I/O: cout/cin (C++), printf() and scanf() (C)
  3. file creation and file i/o: ifstream infile() and ofstream outfile() (C++),
    FILE >infile, FILE *outfile, and fopen() (C) nd fprintf() (C)
  4. Constants: const int MAXVALS=100; (C++)
    #define MAXVALS 100 (C)
  5. static array: int myarray[MAXVALS]: C++ and C
  6. dynamic arrays: C++:
    int *myarray;
    cin >> numVals; myarray=new int[numVals];
  7. dynamic arrays: C:
    int *myarray;
    scanf("%d", &numVals); myarray=(int *)malloc(sizeof(int)*numVals);
    "malloc" stands for "memory allocation"
  8. deletion of dynamic arrays
    delete myarray (C++)
    free(myarray) (C)
  9. "Random" numbers in C and C++