Question: OBJECT ORIENTED PROGRAMMING IN PYTHON Give an implementation of this a LeakyStack abstraction, using circular array with appropriate storage capacity. Modify the code below considering

OBJECT ORIENTED PROGRAMMING IN PYTHON

Give an implementation of this a LeakyStack abstraction, using circular array with appropriate storage capacity. Modify the code below considering the following requirements and situations:

a. The stack size is 5, and the storage capacity is 10.

b. If at a point, the stack (i.e. the inner array of the stack) is as follows: [4, 1, 3, 2, 5, None, None, None, None, None], where 4 is the end of the stack and 5 is the top of the stack, and a new number 8 is pushed in the stack, the stack should be as follows: [None, 1, 3, 2, 5, 8, None, None, None, None, None]. This means 4 is ignored (leaked).

c. If at a point the stack is as follows: [2, 3, None, None, None, None, None, 8, 9, 1], where 8 is the end of the stack and 3 is the top of the stack, and a new number 5 is pushed in the stack, the stack will becomes: [2, 3, 5, None, None, None, None, None, 9, 1]. This means 8 is ignored (leaked).

d. Other special situations should be considered such as performing a pop operation when the stack is empty.

e. The other menu option should be to exit the program. With the menu you should have two options: one to allow the user to change the value of maxlen (the inner array) and the other to rerun the script to see the output with the change. The other menu option should be to exit the program.

A sample output of code should show as per image attached.OBJECT ORIENTED PROGRAMMING IN PYTHON Give an implementation of this a LeakyStack

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

class Full(Exception): pass

class Empty(Exception): pass

class MyLeakyStack(): """complete this class by adding more functions within the class""" DEFAULT_CAPACITY = 10 #storage capacity is 10 def __init__(self, maxlen, capacity): """note: this function is partially completed""" self._maxlen = maxlen self._capacity = capacity # size of the circular array self._storage = [None] * capacity # initialise storage room, this is treated as a circular array

def menu(self): """ Either end or change the maxlen of the inner array """

####### don't edit between here and the comment below ######## def run(self): for i in range(12): try: S.push(i) print("after push "+str(i), S._storage) except Exception as e: print(e, " after push "+str(i), S._storage)

for i in range(6): try: a=S.pop() print("after pop "+str(a), S._storage) except Exception as e: print(e, S._storage)

for i in range(5): try: S.push(i+100) print("after push " + str(i+100), S._storage) except Exception as e: print(e, S._storage) ###### don't edit the above lines - add anything below as you with

#### don't add anything below here if __name__ == '__main__': S = MyLeakyStack(5, 10) # stack size should be 5 and the capacity of the array should be 10 S.run()

after push 0 [0, None, None, None, None, None, None, None, None, None] after push 1 [0, 1, None, None, None, None, None, None, None, None] after push 2 [0, 1, 2, None, None, None, None, None, None, None] after push 3 [0, 1, 2, 3, None, None, None, None, None, None) after push 4 [0, 1, 2, 3, 4, None, None, None, None, None) Reached stack limit, forget elemento after push 5 [None, 1, 2, 3, 4, 5, None, None, None, None] Reached stack limit, forget element 1 after push 6 [None, None, 2, 3, 4, 5, 6, None, None, None] Reached stack limit, forget element 2 after push 7 [None, None, None, 3, 4, 5, 6, 7, None, None] Reached stack limit, forget element 3 after push 8 [None, None, None, None, 4, 5, 6, 7, 8, None] Reached stack limit, forget element 4 after push 9 [None, None, None, None, None, 5, 6, 7, 8, 9] Reached stack limit, forget element 5 after push 10 [10, None, None, None, None, None, 6, 7, 8, 9] Reached stack limit, forget element 6 after push 11 [10, 11, None, None, None, None, None, 7, 8, 9] after pop 11 [10, None, None, None, None, None, None, 7, 8, 9] after pop 10 [None, None, None, None, None, None, None, 7, 8, 9] after pop 9 [None, None, None, None, None, None, None, 7, 8, None) after pop 8 [None, None, None, None, None, None, None, 7, None, None] after pop 7 [None, None, None, None, None, None, None, None, None, None] Stack is empty [None, None, None, None, None, None, None, None, None, None] after push 100 [None, None, None, None, None, None, None, 100, None, None] after push 101 [None, None, None, None, None, None, None, 100, 101, None] after push 102 [None, None, None, None, None, None, None, 100, 101, 102] after push 103 [103, None, None, None, None, None, None, 100, 101, 102] after push 104 [103, 104, None, None, None, None, None, 100, 101, 102] Enter 1 to exit or 2 to change the array size Enter a number for the new maxlen of the inner array: Reached stack limit, forget element 100 after push 0 [103, 104, 0, None, None, None, None, None, 101, 102] Reached stack limit, forget element 101 after push 1 [103, 104, 0, 1, None, None, None, None, None, 102] Reached stack limit, forget element 102 after push 2 [103, 104, 0, 1, 2, None, None, None, None, None] Reached stack limit, forget element 103

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To implement the MyLeakyStack using a circular array with the given specifications follow these step... View full answer

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!