Steps for modifying the restaurants program to include restaurants with a menu field:

  1. You need data definitions for three classes to replace the one rrant class: One for the new rrant class (a structure with four fields, a name, cuisine, phone, and menu), one for the menu (a list of dishes), and one for a dish (a structure with two fields, a name and a price).

    By separating out each of these classes, you have a way of thinking about which type of data each function (and each helper function) you write needs to act on.

  2. You need to handle the input of the new restaurants. This involves three things: Asking the user for a single dish (name and price), asking the user for a menu (i.e., repeatedly asking for individual dishes), and creating the new restaurant with the entered menu. For the middle task, you need some way to let the user indicate he or she is finished entering dishes. One way would be to ask the user to enter the empty string ("") instead of a name when there are no more dishes to enter. Another would be to have a separate (sub-)menu command to add a new dish (and a command to quit adding new dishes).

  3. To print out a restaurant, you need to print its menu (which means you need a way to print a nicely formatted dish).

  4. The change-prices function needs to work on a list of dishes. One good approach would be to write a dish-adjust-price function that takes a dish and a percentage and returns the dish with the price changed by the specified percentage (up or down, as before). Then you can apply dish-adjust-price to a whole menu.

David G. Kay,
Friday, October 24, 2008 7:03 AM