Homework 6
Hardware Store Inventory

Due: Tuesday, December 13 at 5pm

Outcomes

After successfully completing this assignment, you will be able to...

The Assignment

Write a C program that creates and maintains a file that stores information about the tools sold in a hardware store. For each tool in the inventory, you should store the item number (i.e. record number) for the tool, the name of the tool, the number in stock, and the unit price. The inventory should be maintained in a random-access binary file named "hardware.inv". The program provides a menu of options that allows the user to Each of the operations on the database (inserting an item, listing all items, deleting an item, updating an item, and initializing the database) should be implemented as a separate function. One of the parameters that is passed to each of these functions should be the stream that you associated with the inventory file. You may choose other parameters for the functions as needed.

Assumptions and restrictions

Include files

Sample execution

*** Hardware Inventory Program ***

What would you like to do?

Enter
    1  to insert a new item into the datatbase
    2  to list all the tools in the database
    3  to delete an item from the database
    4  to update the information about an item in the database
    5  to initialize the database

Type any other number to quit

-->  1
Enter the item number for the new item:  24
What is the name of the item?  Jig saw
How many items are on hand?  21
What is the unit cost?  11.00

What would you like to do?

Enter
    1  to insert a new item into the datatbase
    2  to list all the tools in the database
    3  to delete an item from the database
    4  to update the information about an item in the database
    5  to initialize the database

Type any other number to quit

-->  1
Enter the item number for the new item:  3
What is the name of the item?  Electric sander
How many items are on hand?  7
What is the unit cost?  57.98

What would you like to do?

Enter
    1  to insert a new item into the datatbase
    2  to list all the tools in the database
    3  to delete an item from the database
    4  to update the information about an item in the database
    5  to initialize the database

Type any other number to quit

-->  2

*** List of Items in the Inventory ***

   3  Electric sander     7  $57.98

  24  Jig saw            21  $11.00

What would you like to do?

Enter
    1  to insert a new item into the datatbase
    2  to list all the tools in the database
    3  to delete an item from the database
    4  to update the information about an item in the database
    5  to initialize the database

Type any other number to quit

-->  3
Enter the item number of the item you would like to delete:  3
Item 3 has been deleted.

What would you like to do?

Enter
    1  to inser a new item into the database
    2  to list all the tools in the database
    3  to delete an item from the database
    4  to update the information about an item in the database
    5  to initialize the database

Type any other number to quit
    
-->  4
Enter the item number of the item you would like to update:  24
Do you want to update the quantity (enter 1) or the price (enter 2)?  1
Enter the new quantity:  51
Item 24 has been updated.

What would you like to do?

Enter
    1  to insert a new item into the datatbase
    2  to list all the tools in the database
    3  to delete an item from the database
    4  to update the information about an item in the database
    5  to initialize the database

Type any other number to quit

-->  2

*** List of Items in the Inventory ***

  24  Jig saw    51  $11.00

What would you like to do?

Enter
    1  to insert a new item into the datatbase
    2  to list all the tools in the database
    3  to delete an item from the database
    4  to update the information about an item in the database
    5  to initialize the database

Type any other number to quit

-->  0
Program terminating.

Hints

Get the main program structure working first (i.e., in a loop display the menu and accept the user's response; terminate the program when the user types a number other than 1, 2, 3, 4, or 5). Then, one at a time, implement each of the operations.

Deliverables

Submit your C source code file and a README.txt file using the following turnin command:

/cs/bin/turnin submit cs2301 PROJECT6 inventory.c README.txt

Programs submitted after 5pm on December 13 will be tagged as late, and will be subject to the late homework policy.

Grading

This assignment is worth 35 points: Programs must compile successfully in order to receive points for correctness.