Programming Assignment 5 - Inventory Reordering

Introduction to Computer Science II, Summer 2001


Table of Contents

Due Date

This assignment is due on Tuesday, 31 July, no later than 2:00 p.m.

See the assignment turn-in page for instructions on turning in your assignment.

Background

The Happy Mouse Cheese Shoppe Co. uses single-source distribution to keep their shoppes stocked. Every evening after closing each shoppe sends its sales receipts to the distribution center, where the quantities of each cheese sold at each shoppe are tallied and used to determine which, if any, stock needs to be delivered to the shoppe the next morning.

The distribution center keeps information about cheeses on hand in a text file called the inventory file. Each line in an inventory file has the following form

max current min type

where

Each field is separated from the next by at least one, and possibly more, space character, and each line ends in a newline. Lines appear in an inventory file in no particular order. Here is an example inventory file:

 25  15  10 stilton
100 100  50 limberger
 50  30  40 goat

You may assume an inventory file never contains more than 25 lines.

All the shoppes' sales receipts are aggregated into a text file called the sales file. Each line in a sales file has the following form

store amount type

where

Each field is separated from the next by at least one, and possibly more, space character, and each line ends in a newline. Lines appear in a sales file in no particular order. Here is an example sales file:

store10 3 swiss
store10 5 brie
storeCN01 10 monterey jack

Problem

You've been hired by Happy Mouse to write a program to determine when the distribution center should replenish its stock. When run, the program reads the inventory file inventory.dat and the sales file sales.dat and adjusts the amount of cheese on hand by the daily sales.

When both files have been read and processed, the program writes an inventory file called new-inventory.dat and an reorder file called reorders.dat. new-inventory.dat contains the new amounts-on-hand after processing the daily sales; reorders.dat contains the amounts and types of cheeses the distribution center should order to replenish its stocks.

A reorder file is a text file in which each line in the file has the form

amount type

where

The fields are separated by at least one, and possibly more, space character, and each line ends in a newline. Lines in a reorder file appear in any order.

Processing proceeds according to these rules:

  1. The amount of each cheese on hand should never drop below zero. For example, if the distribution has 5 edam cheeses and a store sells 7, the amount of edam on hand after processing is 0, not -2.

  2. The distribution center should reorder a cheese when the amount-on-hand drops below the minimum. The quantity of cheese to reorder should bring the amount-on-hand up to the maximum. For example, if, after processing the sales file, the amount of feta cheese on hand is 5, the minimum is 10, and the maximum is 23, then the distribution center should reorder 23 - 5 = 18 feta cheeses.

Testing

There are two sets of data files you can use to test your program:

  1. inventory-1.dat, sales-1.dat, new-inventory-1.dat, and reorders-1.dat

  2. inventory-2.dat, sales-2.dat, new-inventory-2.dat, and reorders-2.dat

Note that you will have to rename the input files to use them with your program. You can download these files from a browser (shift-left-click on the link) or access them directly at

/export/home/us/csfac/cs176-summer2001/pa/5

from any PC lab machine running linux or rockhopper.


This page last modified on 18 July 2001.