Tags: C, Link List, Function Pointers, Data Structure
LAB DESCRIPTION
PART 1. GROCERY STORE INVENTORY SYSTEM:
Mandatory filenames:
1) lab4main.c – will hold main()
2) lab4.h – will hold any local typedefs or struct definitions, function prototypes, etc. NO VARIABLES can be declared here.
3) you must have an additional .c file for every function that you write. (e.g. insert_node.c, delete_node.c, etc.)
Mandatory executable name: lab4
PROBLEM:
You will write a program to store and process data in order to manage inventory and to keep business records for a grocery store.
The program will execute in the following format:
lab4 filename1 filename2
where lab4 is the name of the executable
filename1 is the data file that contains current inventory information to read in
filename2 is a data file that your program will create with the output inventory
This means that you will have to read two parameters from the command line.
You will be supplied with an initial inventory file called store_inventory. All of the data for the grocery items to be stored in the inventory system will be in this file. Once the program has read in the data, a user will be able to select options related to what to do with the data. You do not know the number of different grocery items which will be in the file, so your code must be able to deal with an indeterminate number of them (up to the limits of memory).
First, your program should open the file specified by the filename1 parameter and read in the initial inventory. There will be options for adding or deleting grocery items provided to the user later by the program after the initial data is read in and used to build the linked list. The data will be entered in the following format, with each item of data listed entered on a different line:
Grocery Item (Assume there will be a single line possibly containing white spaces; check the initial store_inventory file on Piazza)
Grocery Store Department (Assume there will be a single line possibly containing white spaces; see the sample data posted on Piazza)
stock number (1 - 10000)
Wholesale price of the item in dollars (a floating point value)
Retail price of the item in dollars (a floating point value)
Wholesale quantity purchased by this store (a whole number greater than or equal to zero)
Retail quantity purchased by customers (a whole number greater than or equal to zero)
Data about each grocery item will not be separated from the data for the following item; that is, the first line of input for the next grocery item will immediately follow the item which precedes it on the following line. The end of the input for the items will be indicated when an fscanf() function returns EOF. There will be data about at least one grocery item in the file. The linked list that your program builds for the store should create a linked list based on increasing stock number; the grocery items will not necessarily appear in the input in this order. You program MUST order all items as it inserts them into the linked list. [This means that you CANNOT read all items in with no concern for order, then, subsequently, order the linked list. If you choose to do this, you will receive 0 points for the lab.]
After reading the input data, and constructing the linked list, your program should:
a) Tell the user that the inventory has been read in from the file and how many grocery item records were read in.
b) Prompt the user to select from the following options for processing of the data.
(REQUIRED: Use an Array of Function Pointers to call the User’s Choice of
Function for options 1 through 9.
(retail price * retail quantity) for all grocery items;
(wholesale price * wholesale quantity) for all grocery items;
(wholesale price * (wholesale quantity – retail quantity));
wholesale cost (#2) plus cost of current inventory (#3);
as the sum of the retail quantities for all grocery items;
(#5);
where (Wholesale quantity – Retail quantity >0). The output would be a “Title Line” that says
something like “Grocery items in Stock” then on subsequent lines, the number of grocery items
currently in stock (Wholesale – Retail) followed by a tab character then the stock number followed
by a tab character, then the Grocery store department followed by the tab character then the name
of the grocery item;
(Wholesale quantity – Retail quantity == 0). The output would be a “Title Line” that says
something like “Grocery items out of Stock” then on subsequent lines the stock number followed
by a tab character, then the Grocery store department followed by the tab character then the name
of the grocery item;
Department Name, this function should print each item on the inventory list where the Department
Name contains that string. For example, if the Department Name is “DAIRY DEPARTMENT”
and the substring read is “DAIRY” or “dairy”, then all “DAIRY DEPARTMENT” inventory items
should be printed out with appropriate headings along with the current number of items in stock.
10.Add a new grocery item (prompt the user to enter the data for a single grocery item, in the
format given above from the keyboard;
11.Delete grocery item (prompt the user to enter a stock number to delete from inventory: if the item
is not found in the linked list, print a message indicating an error, or if the list is empty, print an
error indicating that);
12.Write the current inventory in the linked list out to disk using filename2 from the command line,
free all dynamically allocated memory and exit the program. (The format of the file written would be
such that it could be used as input to the program the next time it ran.)
The user will enter a choice of one of these twelve options by entering 1 - 12 immediately followed by
enter (new line). You can assume that all user input will be correct, except that the user may
inadvertently attempt to delete a grocery stock ID number which is not in the list of grocery items.
You should write a separate function to do the necessary computations and print output for each of
these options. Some of these functions may call some of the other functions. The goal is to make
main() as small and succinct as possible, while creating functions that make it as easy as possible to
monitor, modify and execute the code. You should also write a separate function to read the data for a
single grocery item from stdin into a node after allocating storage for the node.