Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write an implementation that satisfies the doc - string in the line which says TODO your implementation here using ONLY Pycharm, please. Then, test the

Write an implementation that satisfies the doc-string in the line which says "TODO your implementation here" using ONLY Pycharm, please.
Then, test the function using the lines of code which starts from right below "TODO your implementation here"
Thank you.
class Registry(object):
def __init__(self, size, value):
"""
Purpose:
Initialize a registry of a give size filled with the
given value
Pre-conditions:
size: number of elements in the registry
value: the default initial value for all elements
"""
self.__reg =[value for i in range(size)]
def set(self, i):
"""
Purpose:
Set the registry element at i to True
Pre-conditions:
i: an index, in the correct range for reg
Post-conditions:
the registry value at i is set to True
Return:
(none)
"""
self.__reg[i]= True
def reset(self, i):
"""
Purpose:
Set the registry element at i to False
Pre-conditions:
i: an index, in the correct range for reg
Post-conditions:
the registry value at i is set to False
Return:
(none)
"""
self.__reg[i]= False
def is_registered(self, i):
"""
Purpose:
Returns the value stored at registry element i
Pre-conditions:
i: an index, in the correct range for reg
Post-conditions:
(none)
Return:
the value stored at element i
"""
return self.__reg[i]
def show(self):
"""
Purpose:
Shows the current Registry values
Pre-conditions:
(none)
Post-conditions:
(none)
Returns:
(none)
"""
print(self.__reg)
def extend(self, size, value):
"""
Purpose:
Extend the registry. This grows the registry to the given size.
The value given will be the new default value for the extended registers.
Pre-conditions:
size: number of elements in the registry
value: the default initial value for all elements
Post-conditions:
IMPORTANT: The previous entries in the registry retain their values.
The registry is expanded. Entries up to the original size are kept the same.
New entries are set to the value provided in the argument.
Returns:
(none)
Warnings:
This method asserts that the new size is greater than the original Registry size.
"""
assert size > len(self.__reg),("Error in Registry method extend(size, value).
"
"Provided size must be greater than the original Registry size.")
# TODO your implementation here
import Registry as R
# You can run this after completing Activity 4
# This test shows that extend_to adds one more register
test_extend_to = R.Registry(5, False)
test_extend_to.extend_to(6, True)
test_extend_to.show()
# This test shows that extend_by adds six more registers
test_extend_by = R.Registry(5, False)
test_extend_by.extend_by(6, True)
test_extend_by.show()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions