This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: [CSM51A W09] Solution to Assignment 6 Assigned: 02/16/09, Due: 02/23/09 TAs: Pouya Dormiani (email@example.com), Gabriel Pan (firstname.lastname@example.org) Homework Problems (45 points total) Problem 1 (15 points) Our goal is to design a vending machine which sells stamps. The price of a stamp is 35 cents (for the sake of the problem). The machine accepts only nickels (5 cents), dimes (10 cents), and quarters (25 cents). When the total value of coins is equal to or larger than the price of the stamp, the machine deploys the stamp, and returns any change as necessary. The change is given in nickels or dimes, and is returned in a way such that the total number of coins returned is the smallest possible. For example, if the amount of change is 30 cents, the machine returns 3 dimes, and not a mixture of dimes and nickels which will result in a higher coin count. The machines control module looks like the diagram below. It has an input Coin which denotes the type of coin deposited, and has three outputs: Deploy , which is 1 when the machine needs to deploy a stamp and 0 otherwise, N c , number of nickels to return as change, and D c , number of dimes to return as change. Vending Machine Controller Coin Deploy N c D c 1. (5 points) What is the minimum number of states necessary for the control module? What would each state represent? ( Hint: To find the minimum number of states, we can write a loose state description of the problem and reduce the number of states by obtaining P 1 , P 2 , and so on as necessary. ) Solution : One way of representing states would be to have a state for each possible total value of coins that have been inserted into the vending machine up to that time point. As the coin with the minimum value is a nickel, we can go up in multiples of 5. Any input which makes the current total of coins go overvalue is a nickel, we can go up in multiples of 5....
View Full Document
This note was uploaded on 03/26/2010 for the course CS 187154200 taught by Professor Ercegovac,m.d. during the Winter '09 term at UCLA.
- Winter '09