600.102: Foundations of Computer Science

Fall Semester 2005: September 8, 2005 - December 12, 2005

Assignment 6: Cashing in Objects

Out on: October 31, 2005
Due by: November 6, 2005 by 5:59 pm for full credit (11:59 pm for 10% off, hard deadline)
Collaboration: None
Grading: Packaging 10%, Style 10%, Performance 10%, Design 10%, Functionality 60%

Overview

The sixth assignment for 600.102: Foundations of Computer Science covers material from Weeks 7 and 8 and the corresponding reading.

Problem 1: Revenge of Random Python

Your first task is to (once again) rewrite your random number generator from the last assignment. The resulting random.py module should contain a class Random that encapsulates the random number generator itself. Clients can then create objects as follows:

...
import random as R
...
r = R.Random()
print r.random()
...
q = R.Random()
print q.random()
...

However, some clients won't need this generality (i.e. being able to create multiple random number generators). For their benefit, you should also provide a function random() that simply returns another random number. Clients can use that function as follows:

...
import random as R
...
print R.random()
...

There's an easy way of doing this without duplicating the code for random number generation; find it and use it. Also write a short test program test_random.py that uses both ways (separate objects and the random function) to print out some random numbers. And if for some reason your code from the last assignment didn't work, email me and I'll send you a working version.

Problem 2: The Trouble with Cash Registers

Your second task is to develop a simulation for cash registers. You all know how these work, and maybe you have even used one before during a summer job or something? Maybe you'll gain some new appreciation for them after you have finished this problem... :-)

A cash register starts out with a certain number of coins and bills in it. During its "lifetime" a cash register processes a series of transactions. Each transaction is for a certain amount of money that you need to "collect" from a customer; the customer pays for the transaction with a certain number of bills and coins, making it necessary (most of the time anyway) to give the customer back some change. Given a particularly "unlucky" sequence of transactions, it is of course possible for the cash register to "run out" of needed bills or coins.

Here is how your simulation register.py should work: It first reads 13 numbers from the standard input that give the "original" configuration. The numbers are in the following order: $100 bills, $50 bills, $20 bills, $10 bills, $5 bills, $2 bills, $1 bills; $1 coins, 50c coins, 25c coins, 10c coins, 5c coins, 1c coins. You initialize your cash register (which should be a class of course) with these values. Then you read a series of transactions from the standard input; a transaction has the following format: the total cost for the transaction, followed by the 13 numbers for the bills and coins the customer hands you; these 14 values are separated by spaces.

To process a transaction, you have to determine the smallest number of bills and coins you can use to give change to the customer. You get bills and coins from the customer, and you hand bills and coins to the customer; so obviously your totals change with each transactions. Your simulation needs to keep track of the bills and coins in your cash register; once you read a transaction for which you cannot provide change, the simulation stops with an error message; otherwise it stops when the transactions end.

Aside from the code for this problem, please hand in at least four test cases; describe how you chose the test cases in your README file. Each test case should be in a separate text file.

Problem 3: More Trouble?

Imagine you're in charge of the cash registers for a big chain, some gas station company for example. You don't want to run into situations where you can't give change, but you don't want to have too much cash on hand either. Outline a process you could use to "optimize" the amount of bills and coins your employees take from the safe each morning. Note that you're not solving any particular problem here, just outlining the general approach you would take, and what impact that would have on your registers (i.e. what they need to be able to do).

Deliverables

Please turn in a gzip compressed tarball of your assignment (the extension should be .tar.gz). The tarball should uncompress into a directory cs102-assignment-6-login with login replaced by your Unix login name (so I would use cs102-assignment-6-phf); uncompressing should not create any other files in the current directory. Include a README file that briefly explains what your programs do and contains any other notes you want us to check out before grading (and of course your answers to "written" problems). This file should be a plain Unix text file (not M$ Word, not PDF); it should be formatted in a decent way and it should contain your contact information.

Grading

For reference, here is a short explanation of the grading criteria. Packaging refers to the proper organization of the stuff you hand in, following the guidelines for Deliverables above. Style refers to programming style, including things like consistent indentation, appropriate identifiers, useful comments, etc. Simple, clean, readable code is what you should be aiming for. Performance refers to how fast your program can produce the required results compared to other submissions. Design refers to proper modularization and the proper choice of algorithms and data structures. Functionality refers to your programs being able to do what they should according to the specification given above; if the specification is ambiguous and you had to make a certain choice, defend that choice in your README file.

If your programs do not run because of syntax errors you will get no points whatsoever. If your programs fail miserably, i.e. terminate with an exception of any kind, we will take off 10%.

Bonus Problem

Once again, there is no bonus problem for this assignment. But please think ahead a little, the circuit simulator is coming for sure. :-)

Updated: $Id: assignment-5.html 75 2005-10-25 03:22:14Z phf $ Validate: XHTML CSS
Copyright © 2005 Peter H. Fröhlich. All rights reserved.