logo

Crowdly

This problem is adapted from Programming in C++ by Michael D. Adams. You can ac...

✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.

This problem is adapted from Programming in C++ by Michael D. Adams. You can access the textbook via Google Books.

In this question, you will develop a Histogram class to create histograms (counting how many values fall in each of a number of intervals). 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.

Більше питань подібних до цього

Хочете миттєвий доступ до всіх перевірених відповідей на learning.monash.edu?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!

Browser

Додати до Chrome