Question: The software is being further developed to store whether the whole party is present or not; party complete being 0 indicates the party is incomplete
The software is being further developed to store whether the whole party is present or not; party complete being
indicates the party is incomplete and so cannot yet be seated and party complete being indicates the party
is complete, and therefore can be seated when a table becomes available.
The code below implents this as a class. The asdict method can be used to return a dictionary of the bookings
which can be used for testing purposes.
In :
run i marray
class Bookings:
A dynamic array implementation
to store bookings.
def initself:
Create a new empty array.
Write a problem definition for a function which returns a tuple with two values: the first being the count of
bookings with parties which are incomplete and the second being the count of bookings with parties which are
complete.
Write your answer here
Function: Inputs: Preconditions: Output: Postconditions:
Qc marks
The code below extends the Bookings class by adding a method which, for a given reservation ID will set the
party complete value to or if a party becomes complete or incomplete.
The code below creates a number of bookings, assigns each with an initial completeness status, and checks the
completeness status of one of them, then changes its completeness status, and checks it again.
self.bookings DynamicArray
def addbookingself reservationID: int, name: str table: int None:
Adds a booking to the array.
size self.bookings.length
self.bookings.resizesize
self.bookings.setitemsizereservationID name, table,
def getpartycompleteself reservationID: int int:
Precondition: reservationID exists.
for index in rangeselfbookings.length:
booking self.bookings.getitemindex
if booking reservationID:
return booking
def asdictself None:
Returns dictionary version
of the bookings array.
bookings dict
for index in rangeselfbookings.length:
booking self.bookings.getitemindex
bookingsbooking bookingbookingbooking
return bookings
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
