Some Practice Problems for Exam 3

There are two unrelated sets of problems: the first gives more practice with set! and set-structure!. The second gives practice with accumulators. Skip around and do whichever problems are most helpful to you in preparing for the exam.

You are writing programs to run the order tracking software for a
pizzeria.  The software allows wait staff to enter orders into the
system, for the cooks to remove orders as they make the pizzas, and
for wait staff to change orders that have already been placed if the
pizza hasn't yet been made.  An order indicates the customer's name,
pizza size (small, medium, large) and the toppings to put on the pizza
(any number, things like mushrooms, pepperoni, etc).  The system
stores a list of the orders that haven't yet been prepared.

1. Develop the data definitions and define the variables that you need
   for this problem.

2. Write a function place-order that consumes a customer's name, pizza
   size and desired toppings and stores a new order for the cooks.
   The new order should be entered at the end of the orders (so that
   the cooks make the pizzas in the same order as the customers' asked
   for them). [HINT: use append]

3. Write a function next-order that gives the cook the order for the
   first pizza to make (but doesn't change the stored orders).

4. Write a function prepared-pizza that removes the first pizza to make
   from the pending orders for the cook.

5. Write a function add-topping that consumes a customer name and a
   new topping and changes that customer's order to include the new
   topping.  If the order has already been made (is not in the list of
   pending orders), produce a string (not an error) saying that the
   pizza is already in the oven.

6. Propose a test sequence for the above problems.

7. The programs from the previous problems are good for handling the
   cook's side of the operation, but don't help the cashiers, since
   the orders are deleted as soon as the cooks put the pizzas in the
   oven.  Introduce another variable for the orders that have been
   prepared but need to be picked up.  Then, modify (or write a new
   version of) prepared-pizza that not only removes the order from the
   pending order for the cook, but also puts it into the set of orders
   that need to be picked up.

8. Write a program pizza-claimed that takes a customer's name and
   removes their order from those waiting to be picked up.  

9  Augment pizza-claimed to also return the price that the customer
   owes for their pizza.  Charge a base price of $8/$10/$12 for
   small/medium/large pizzas, plus $1 per topping.


Practice Problems with Accumulators

Write each of the following functions in accumulator style

1. ;; sum-of-positives : list-of-number -> number
   ;; produce sum of all numbers in list that are larger than 0

2. ;; extract-positives : list-of-number -> list-of-number
   ;; produces list of all positive numbers from list

   ;; [HINT: do a first version where the list comes out backwards.
   ;;  Then modify the function to reverse the list just before
   ;;  returning it.  Use Scheme's built-in reverse function that 
   ;;  consumes a list and reverses the order of its elements]

3. Assume you have a structure

   ;; a symcount is (make-symcount symbol number)
   (define-struct symcount (symname count))

   That can store how many times a symbol appeared in a list.  Write

   ;; times-appearing : symbol list-of-symbol -> symcount
   ;; given symbol and list of symbol, returns symcount for number of
   ;; times given symbol appears in given list

   ;; hint: accumulate the count and make the symcount only in the
   ;; empty? case

This page maintained by Kathi Fisler
Department of Computer Science Worcester Polytechnic Institute