6.6

Assignment 19

home work!

Programming Language ISL

Due Date Monday 12/3 at 9pm

Purpose To practice designing with accumulators.

Expectations
  • You should submit a single .rkt file containing your responses to all exercises via the Handin Server. We accept NO email submissions.

  • You are only allowed to use one of the language specified at the top of this page: failure to do so will result in a 0.

  • You are expected to use pre-defined abstractions when stated and/or when appropriate.

Exercise 1 Design a function, relative->absolute, that takes a list of numbers which represent relative distances and convert them to absolute distances. For example, picture a map program telling you to drive 1 mile, then 2 miles, then 5 miles, etc. At each step, you would have driven 1 mile, then 3 miles, then 8 miles, etc. Do not traverse the list more than once.

Exercise 2 You are a cashier at a movie theater where all of the tickets cost 5 dollars (if only). All customers approach the ticket window with either a credit card, a 5 dollar bill, or a 10 dollar bill. Today, your manager left n 5 dollar bills in the cash register to start the day. Design a function, as well as any data definitions you may need, that takes in n as well as a list of payments, where the first customer is at the head of the list, and returns how many tickets you will be able to sell. Tickets can only be sold so long as change, if needed, can be made. Customers you cannot sell to will go to a different movie theater in protest.

Exercise 3 Recall exercise 2 from Assignment 17. Re-implement the problem, but do not assume the network is acyclic.