CS U212 - Lab 3
The lab assignment is to be completed in pairs. Each pair works at one computer. Remember to trade roles!
Part I: Structure Definitions
For each of the following word problems, extract
structure definitions for the data involved.
Exercise 1:
A restaurant reservation system keeps track of tables in the
restaurant. For each table, the system knows how many seats there
are and whether or not it is currently reserved.
Exercise 2:
Each dish served by the restaurant must be served within a particular
temperature range. A dish has a name, a price, a minimum serving temperature,
and a maximum serving temperature (in degrees Fahrenheit).
Partner Switch
Exercise 3:
A food order consists of an appetizer, an entree, and a dessert.
Each course is a dish as described in Exercise 2.
Exercise 4:
The restaurant is divided into a bar area, three sections of tables,
and the entry area. The bar is staffed by one bartender, and the
entry area is staffed by the maitre d'. Each section is tended by
two servers.
Part II: Data Definitions
Take your first three structure definitions from above and turn them into data definitions. Recall that a data definition for structured data specifies what kind of data each structure field contains. Refer to Section 6.4 of HtDP if you need to review!
Part III: Templates
Construct a template for each of the data definitions from Part II. Recall that the template describes what we know about the input to a function. For each expression in your template, record the kind of data to which it evaluates. If you need to review templates for compound data, look in Section 6.5 of HtDP.
Part IV: From Templates to Functions
Consider the template you built from the data definition from Exercise 2. Design the following functions based on this one template. You must formulate examples and tests!
-
Using your solution to Exercise 1 above (data definition, structure
definition and template), develop a program that consumes a table
and reserves it for the night
-
Using your solution to Exercise 2 above (data definition, structure
definition and template), develop a program that consumes a dish
and its temperature and determines if the dish can be served.
-
Our software should generate the restaurant menus automatically.
Develop a program that consumes a dish and produces an image containing
that dish's name and price as it would appear in the menu.
-
Our Boston restaurant is a huge success, and so we will open a new
location in Paris. The chefs there do not understand the Fahrenheit
temperature ranges within which our dishes must be served. Develop a
program that consumes a dish and produces a dish just like the given
one, but where the temperature range is given in Celcius.
-
Our Parisian customers cannot pay in US dollars. Develop a program
that consumes a dish and produces one whose price is given in Euros.
Use Google to find the conversion rate.
-
Using your solution to Exercise 3 above (data definition, structure
definition and template), develop a program that determines the
total cost of a given order, including a 21% gratuity.
-
Using your solution to Exercise 4 above (data definition, structure
definition and template), develop a program that consumes a
restaurant and an employee's name, and determines the name of the
area in which the given employee is working.
Part V: Challenge Problem
Done already? Then try to solve this problem:
Our restaurant needs a steady throughput of customers, but, sometimes, a
party stays at their table too long after finishing their meal. Then the
maitre d' has to give them the "evil eye" to encourage them to
be on their way. Develop a program that consumes the party's reservation
and the current time and determines how much longer before the maitre d'
should take action. Parties usually finish dinner in one hour, and on
weekdays they may remain for 30 minutes more. On weekends, they may
only linger for 15 minutes.