Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this problem you will fill out three functions to completethe Group ADT and the Diner ADT. The goal is to organize how dinersmanage the

In this problem you will fill out three functions to completethe Group ADT and the Diner ADT. The goal is to organize how dinersmanage the groups that want to eat there and the tables where thesegroups sit.

It is important to take the time to read through the docstringsand the doctests. Additionally, make sure to not violateabstraction barriers for other ADTs, i.e. when implementingfunctions for the Diner ADT, do not violate abstraction barriersfor the Group ADT, and vice versa.

# Diner ADTdef make_diner(name):    """ Diners are represented by their name and the number of free tables they have."""    return [name, 0]def num_free_tables(diner):    return diner[1]def name(diner):    return diner[0]# You will implement add_table and serve which are part of the Diner ADT# Group ADTdef make_group(name):    """ Groups are represented by their name and their status."""    return [name, 'waiting']def name(group):    return group[0]def status(group):    return group[1]def start_eating(group, diner):    group[1] = 'eating'# You will implement finish_eating which is part of the Group ADT    

Question 1

Implement add_table which increases the diner's numberof free tables by 1:

def add_table(diner):    """    >>> din = make_diner("Croads")    >>> num_free_tables(din)    0    >>> add_table(din)    >>> add_table(din)    >>> num_free_tables(din)    2    """

"*** YOUR CODE HERE ***"

Use OK to test your code:

python3 ok -q add_table

Question 2

Implement serve so that the diner uses one of its freetables to seat the group. If there are no free tables, return thestring 'table not free'. If there are free tables, the group'sstatus should be updated to 'eating' and the diner should have oneless free table.

def serve(diner, group):    """    >>> din = make_diner("Cafe 3")    >>> add_table(din)    >>> g1 = make_group("Vandana's Group")    >>> g2 = make_group("Shreya's Group")    >>> serve(din, g1)    >>> status(g1)    'eating'    >>> num_free_tables(din)    0    >>> serve(din, g2)    'table not free'    >>> status(g2)    'waiting'    """

"*** YOUR CODE HERE ***"

Use OK to test your code:

python3 ok -q serve

Question 3

Implement finish_eating which sets a group's status to'finished' and frees the table they were using so that the dinerhas one more free table.

def finish_eating(group, diner):    """    >>> din = make_diner("Foothill")    >>> add_table(din)    >>> g1 = make_group("Nick's Group")    >>> serve(din, g1)    >>> num_free_tables(din)    0    >>> finish_eating(g1, din)    >>> num_free_tables(din)    1    >>> status(g1)    'finished'    """

"*** YOUR CODE HERE ***"

Use OK to test your code:

python3 ok -q finish_eating

 

Step by Step Solution

3.33 Rating (156 Votes )

There are 3 Steps involved in it

Step: 1

Question 1 def addtablediner din makedinerCroads numfreetablesdin 0 addtabledin addtabledin numfreetablesdin 2 diner1 1 The function addtable increase... 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

Physical Chemistry

Authors: Thomas Engel, Philip Reid

3rd edition

805338423, 080533842X, 978-0321812001

More Books

Students also viewed these Electrical Engineering questions

Question

=+b) Which model do you prefer? Explain briefly. Section 18.4

Answered: 1 week ago

Question

Calculate the percentage change in utilization for the two months.

Answered: 1 week ago