The wood-screw inventory

Goals

To write a program that uses an array of objects embedded in another object.

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 nay number of lines of input, each 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.      Use two classes: one to represent the whole inventory, and one to represent a single screw. The inventory then contains an array of screws.

2.      Think of the program in terms of at least three separate subtasks, which you should write as separate functions:  

a.       reading a 'transaction', i.e. a line of input that specifies the screw size and an increase or decrease amount

b.      updating the inventory, i.e. the number of each size of screw held

c.       printing the inventory

3.      You may want to treat initialization as a separate subtask. Write the main program to call these functions appropriately.

4.      The program should create an "empty" inventory that can handle the screw sizes mentioned above, here with their (fixed) unit cost:

·        screws of  size 4 each cost $0.30

·        screws of  size 6 each cost $0.35

·        screws of  size 8 each cost $0.45

·        screws of  size 10 each cost $0.50

·         screws of  size 12 each cost $0.65

Deliverables:

1.      your source code, suitably commented and with good layout, printed and handed to me (RTH)

2.      the output produced by the program with the following input sequence, printed and handed to me. The first number is the size of screw, and the second is the change in the inventory amount.

6 1000
8 1500
10 1200
4 500
12 100
8 -255
4 -62
10 -720
8 500
4 100

3.      your source code submitted using the assignment submitter.

 

Notes and hints

·        A screw has three properties: its size, the number held in the inventory and its cost.

·        The program is an example of a "loop" program where the main task is a loop of some sort. Input is done within the loop. The output phase, is separate, however, and is done after all input and processing have been completed. Use end-of-file to terminate the input.

·        Prompt the user for input, mentioning especially the sentinel value used for teminating the input.

·        Display screen output with reasonable layout, taking note of the display of money (see below).

·        Use an array for the numbers of screws of each size. Index the array by applying a function to the screw size: e.g. screw size 4 goes in array element 0, size 6 goes in element 1 etc. This will be described in class.

·        If you want to print out the total cost in dollars and cents, use the following sequence before you print the value:

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

Due Date

Submit your completed assignment before 5pm. on Friday March 3rd.