CS167 C Programming
Spring 1998

The wood-screw inventory

Goals

To write a program that uses a single array of integers, and functions to contain subtasks.

Problem description

Write a C program that keeps an inventory of different sizes of wood-screw. The sizes are 4, 6, 8, 10, and 12. Assume all the screws are the same length, and made from the same material. The program should start from a zero inventory and be able to accept input in the form of a screw size and an amount by which to increase or decrease (if negative) the holding of that size of screw. The cost of each supply item is constant and is hard-coded in the program. At the end of the input, a list of screw sizes, their amounts and the total money worth of the inventory should be printed.

Procedure

Follow these steps to end up with a successful program:

  1. Think of the program in terms of at least three separate subtasks, which you should write as separate functions:
    1. reading a 'transaction', i.e. a line of input that specifies the screw size and an increase or decrease amount
    2. updating the inventory, i.e. the number of each size of screw held
    3. printing the inventory
    4. you may want to treat initialization as a separate subtask
  2. Write the main program to call these three functions appropriately.
  3. The program should create an "empty" inventory that can handle the screw sizes mentioned above, here with their (fixed) unit cost:

4 $0.30

6 $0.35

8 $0.45

10 $0.50

12 $0.65

Deliverables:

6 1000
8 1500
10 1200

4 500

12 100

8 -255

4 -62

10 -720

8 500

4 100

9999 0

Notes and hints

Due Date

Submit your completed assignment before 5pm. on Friday March 20th.