Must be done in Python (Latest Version) Design a class named Histogram to repres
ID: 3876675 • Letter: M
Question
Must be done in Python (Latest Version)
Design a class named Histogram to represent a histogram record. The Histogram class contains the following: A private int data field named range that defines the range of a histogram (e.g. 0 -9) A private int data field named max_mark that defines the maximum value A private List data field named occurrence_list that defines an occurrence list of marks. A constructor that creates a Histogram with the required information. You should create a list of zeros and assign it to the occurrence_list. The accessor and mutator methods for all data fields. .A_str__method which returns a nicely formatted string representation. A public method named append_marks which updates the occurrence list of marks. Note: the parameter value must be less than the maximum value specified in the constructor. Note - keep a copy of your solution to this task because you will use it in your A1. For example: Test Result a1= Histogram(10,9) al.append_marks(0) a1.append_marks(8) a1.drawO 0:* 1: 2: 3: 4: 5: 6: 9:Explanation / Answer
Python Program:
class Histogram:
def __init__(self, range, max_mark):
self.__range = range
self.__max_mark = max_mark
self.__occurence_list = [0]*self.__range
def __str__(self):
return "Histogram class for representing a record"
#Mutator Methods
def set_range(self, range):
self.__range = range
def set_max_mark(self, max_mark):
self.__max_mark = max_mark
def set_occurence_list(self, occurence_list):
self.__occurence_list = occurence_list
#Accessor Methods
def get_range(self):
return self.__range
def get_max_mark(self):
return self.__max_mark
def get_occurence_list(self):
return self.__occurence_list
def append_marks(self,marks):
self.__occurence_list[marks]='*'
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.