Homework Assignment 8
An Inventory Management Program
CS 1510
Introduction to Computing
Fall Semester 2014
Due: Monday, November 3, at 10:00 AM
Introduction
For this assignment, you will write a new program from scratch.
The focus is writing functions and practicing more with file
I/O.
Spec 1: Inventory Management
Your client this week is a candy bar distributor that caters to
the nostalgia market. This small company distributes just four
products: Chunky, Skybar, Valomilk, and Zagnut. It needs a
simple program to help it track its inventory of these vintage
candy bars.
The program uses three text files:
- the initial inventory,
- the week's transactions, and
- the updated inventory.
Each inventory file consists of four lines, one per product.
Each line contains a product name followed by the number of
cases of that product in the warehouse. The name and number are
separated by whitespace. The order of the four products in the
file is not specified; neither is the case used for the candy
bar name. For example, here are two possible input files:
example one example two
--------------- ---------------
Chunky 12 ZAGNUT 8
Zagnut 8 VALOMILK 3
Skybar 19 SKYBAR 19
Valomilk 3 CHUNKY 12
The transaction file lists all the transactions for the week,
both sales to customers and purchases from candy manufacturers.
Each line of this file consists of the data for a single
transaction.
- A sale transaction line contains, in order, the word
sale, one of the four product names, and
a positive whole number of cases of this product sold to
a customer.
- A purchase transaction line contains, in order, the word
purchase, one of the four product names,
and a positive whole number of cases of this product
purchased from a manufacturer.
As with the inventory files, the data on each line are
separated by whitespace, and the case used for the transaction
types and candy bar names is unspecified. For example, here
are a few possible transaction lines:
sale chunky 1
PURCHASE ZAGNUT 8
Sale zagnut 8
SALE VALOMILK 3
Purchase chunky 5
The program must take the following input from keyboard:
- the name of the file with the week's beginning
inventory,
- the name of the file containing the week's transactions,
and
- the name of the file in which to write the week's closing
inventory.
In addition to producing an output file that lists the week's
closing inventory, the program must also print to the screen:
- a table displaying the week's beginning inventory,
- the number of sales transactions processed,
- the number of purchase transactions processed, and
- a table displaying the week's ending inventory.
You may assume the following:
- The user enters valid file names.
- The input files exist.
- The data in the input files conforms to the specifications
given above.
- A sale transaction never results in a negative inventory
value.
Here is some design and programming advice:
- Create several input files to test your program. Verify
the results by hand. (I will use test data files that
are too large to make hand calculation of the results
convenient.)
- Break the problem into high-level operations that need
to be done. Implement and test each, one at a time.
- Use functions to implement your high-level operations.
This will make your program easier to understand, and it
will enable you to avoid duplicating code. For example,
your program needs to display to the screen both the
beginning inventory and the closing inventory. A single
function can do both.
- Give your functions and formal parameters names that are
clear and descriptive. Use comments to explain any idea
that your names cannot communicate.
- Use the string method split() with no
arguments to break your input lines into parts. Use
parallel assignment to assign the resulting values to
variables.
- Close each data file as soon as your program is finished
using it.
Name your program candybar_inventory.py.
Demonstration of Correctness
Start a fresh Python shell. Run the final version of
your program on at least three sets of input files for
beginning inventory and transactions. These input files
should demonstrate that your program satisfies the program
specification.
Save your shell to a text file named
interactions.py.
Deliverables
By the due date and time, submit:
- interactions.py
- candybar_inventory.py
Use
the on-line submission system.
Make sure that your program meets
the course programming standards.
Eugene Wallingford .....
wallingf@cs.uni.edu .....
October 26, 2014