Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
0 indicates the party is incomplete (and so cannot yet be seated), and party complete being 1 indicates the party
is complete, and therefore can be seated when a table becomes available.
The code below implents this as a class. The as_dict method can be used to return a dictionary of the bookings
which can be used for testing purposes.
In []:
%run -i m269_array
class Bookings:
"""A dynamic array implementation
to store bookings.
"""
def __init__(self):
"""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:
Q2(c)(8 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 1 or 0 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(0)
def add_booking(self, reservation_ID: int, name: str, table: int)-> None:
"""Adds a booking to the array.
"""
size = self.bookings.length()
self.bookings.resize(size+1)
self.bookings.set_item(size,(reservation_ID, name, table, 0))
def get_party_complete(self, reservation_ID: int)-> int:
"""Precondition: reservation_ID exists.
"""
for index in range(self.bookings.length()):
booking = self.bookings.get_item(index)
if booking[0]== reservation_ID:
return booking[3]
def as_dict(self)-> None:
"""Returns dictionary version
of the bookings array.
"""
bookings = dict()
for index in range(self.bookings.length()):
booking = self.bookings.get_item(index)
bookings[booking[0]]= booking[1],booking[2],booking[3]
return bookings

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

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

7. Understand the challenges of multilingualism.

Answered: 1 week ago