CS U212 - Lab 3

As usual, 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. (Do not design a whole program to solve the problem!)

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. Develop a program that consumes a table and reserves it for the night.

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). Design a program that consumes a dish and its temperature and determines if the dish can be served.

Exercise 3: A food order consists of an appetizer, an entree, and a dessert. Each course is a dish as described in Exercise 2. Develop a program that determines the total cost of a given order, including an 18% gratuity.

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. Design 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 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 of the structure field contains. Refer to Section 6.4 of HtDP if you need to review!

Quiz


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!
  1. Complete Exercise 2.
  2. Our software should generate the restaurant menus automatically. Design a function that consumes a dish and produces an image containing that dish's name and price as it would appear in the menu.
  3. 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.
  4. 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.

Now, complete Exercises 1, 3, and 4.


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.


Last modified: Thu Jan 25 16:37:20 EST 2007