Tuesday, December 13, 2011

Lab 10 - counting digits

This assignment requires that you generate 100 pseudo-random numbers, between 0 and 9, inclusive. You need to use an array to keep track of how many times each digit is generated. The most efficient way to do this is to create one ten-integer array, named counts, and to increment the contents of the appropriate array location each time its value is randomly generated. That is, each time your code generates a 0, you increment the contents of counts[0]; each time your code generates a 1, you increment the contents of counts[1]; and so on.

Remember to seed your rand by calling srand first.

You must create the histogram in a function. This is its header:

   void generateHistogram(int hist[], int base)

You must also display your results using a method. This is its header:

   void printIndexAndValue(int hist[], int base
      string leader)


Extra Credit Alternatives
  1. You may implement this solution using the vector class.
  2. You may impose sort order so that the randomly generated numbers are ordered from least to greatest by number of occurrences.

  3. Note: Using vectors and/or imposing sort order will require the use of either parallel or multidimensional arrays AND a sort function.

Sample Output
Here are screenshots of my code running.

Counting Digits output

Counting Digits with sort output

Refer to the deliverables post for comment formatting and required program identification information.

Due Date:
Monday, December 18th, 8:00am