logo

Crowdly

Define a histogram class that creates histograms (counting how many values fa...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

Define a histogram class that creates histograms (counting how many values fall in each of a number of intervals) given the values and bounds. The class should satisfy the following:

  1. The constructor should be passed a single argument that is a vector of doubles containing the bounds of the histogram bins. The elements of the vector can be assumed to be strictly increasing (each value is greater than the previous value). For example, instantiating the class with the vector: {0.0, 3.14, 20.0, 42.42, 69} would create a histogram with four bins, corresponding to the intervals: [0, 3.14), [3.14, 20), [20. 42.42), [42.42, 69).

  1. The histogram class should have a method named clear, that clears the histogram statistics.

  1. The histogram class should have a method named update, that is passed a single argument: a double that represents a new data point to add to the histogram. You can assume all data passed to this method will be within the range of the histogram bins.

  1. The histogram class should have a method named display, that prints each bin’s range, followed by the number of values that fall into that bin.

For example, if the histogram was initialised with the vector : {0.0, 3.14, 20.0, 42.42, 69} and the update method was called with the following numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, then calling the display method would print the following:

[0, 3.14): 3

[3.14, 20): 7

[20, 42.42): 3

[42.42, 69): 2

  1. All data attributes of the class should be private.

Note:

  1. Your code MUST be submitted as a .txt file below BEFORE the end of the test. Late submissions cannot be accepted.
  2. Your .txt file should be named as q6_studentID.txt, eg q6_12345678.txt

  3. You should use good programming practices

More questions like this

Want instant access to all verified answers on learning.monash.edu?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome