Question: In python. We are given the ADT already, but we need to add more operations. class Statistics(object): def __init__(self): Purpose: Initialize a Statistics object

In python. We are given the ADT already, but we need to add more operations.

In python. We are given the ADT already, but we need to

class Statistics(object): def __init__(self): """ Purpose: Initialize a Statistics object instance. """ self.__count = 0 self.__avg = 0 def add(self, value): """ Purpose: Use the given value in the calculation of mean and variance. Pre-Conditions: :param value: the value to be added Post-Conditions: none Return: :return none """ self.__count += 1 k = self.__count diff = value - self.__avg self.__avg += diff / k def mean(self): """ Purpose: Return the average of all the values seen so far. Post-conditions: (none) Return: The mean of the data seen so far. Note: if no data has been seen, 0 is returned. This is clearly false. """ return self.__avg def count(self): """ Purpose: Return the number of values seen so far. Post-conditions: (none) Return: The number of values seen so far. Note: if no data has been seen, 0 is returned. This is clearly false. """ return self.__count

Statistics.py, which is an ADT covered in class and in the readings. For your convenience, we re- moved some of the calculations and operations (e.g., var() and sampvar(), that were not relevant to this exercise, which would have made testing too onerous. In this question you will define four new operations for the ADT: range() Returns the range (difference between the minimum and maximum) based on every value recorded by the Statistics object. mode () Returns the mode (the value that occurs most frequently) based on every value recorded by the Statistics object. max() Returns the maximum value ever recorded by the Statistics object. min() Returns the minimum value ever recorded by the Statistics object. Note: For each of the above, if not data was seen, the function should return None. Hint: To accomplish this task, you may have to modify other operations of the Statistics ADT. You will also improve the test script from Q2 to test the new version of the ADT, and ensures that all oper- ations are correct. Remember: you have to test all operations because you don't want to introduce errors to other operations by accident the only way to know is to test all the operations, even the ones you didn't change. To make the marker's job easier, label your new test cases and scripts so that they are easy to find

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!