Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objectives: - Structures and Structure Pointers - Linked Lists - Function Pointers - Passing Command Line Arguments to main() - Header files and Make files

Objectives:

- Structures and Structure Pointers

- Linked Lists

- Function Pointers

- Passing Command Line Arguments to main()

- Header files and Make files

LAB DESCRIPTION

PART 1. CLASSIC BOOKSTORE INVENTORY SYSTEM:

Mandatory file names: lab3main.c GetDataAndBuildList.c

createNodeAndGetData.c createNodeAndGetStdinData.c insert.c delete.c calculateAverageProfit.c calculateTotalProfit.c calculateCapitalInvestment.c calculateTotalBooksSold.c calculateTotalRevenue.c calculateWholeSaleCost.c freeAllNodes.c getUserOption.c printInStock.c printOutOfStock.c writeInventoryToDisk.c

You will write a program to store and process data in order to manage inventory and to keep business records for a bookstore which deals in (mostly) classic book titles.

The program will execute in the following format: lab3 filename1 filename2

where lab3 is the name of the executable filename1 is the data file that contains the inventory to input 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 a test inventory file called book_inventory. All of the data for the book titles to be stored in the inventory system will be in this file. Once the program has read in the book 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 book titles which will be in the file, so your code must be able to deal with an indeterminate number of different books (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 books 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:

- Book title (We will assume the title may possibly contain white spaces; check the initial book_inventory file on Piazza)

- Author's name (We will assume there will be a single author line for each book, with the

name(s) possibly containing white spaces; see the sample data posted on Piazza)

- Bookstocknumber(1-10000)

- Wholesalepriceofthebookindollars(afloatingpointvalue)

- Retailpriceofthebookindollars(afloatingpointvalue)

- Wholesalequantitypurchasedbybookstore(awholenumbergreaterthanorequaltozero)

- Retailquantitypurchasedbycustomers(awholenumbergreaterthanorequaltozero)

Data about each book will not be separated from the data for the following book; that is, the first line of input for the next book will immediately follow the book which precedes it on the following line. The end of the input for the books will be indicated when an fread() function returns EOF. There will be data about at least one book in the file. The linked list which you program builds for the books should store them in order of increasing book stock number, but the books will not necessarily appear in the input in this order. After reading the input data about the books, and constructing the linked list, your program should

a) Tell the user that the inventory of books has been read in from the file and how many book titles were read in.

b) Prompt the user to select from the following options for processing of the data.(getUserOptions.c) Use an Array of Function Pointers to call the Users Choice of Function for options 1 through 8.

Determineandprinttotalrevenue(fromallbooks):Thisisthesumof(retailprice*retail quantity) for all books (calculateTotalRevenue.c);

Determineandprinttotalwholesalecost(forallbooks):Thisisthesumof(wholesaleprice* wholesale quantity) for all books (calculateWholeSaleCost.c);

Determineandprintthecurrentinvestmentinbooks:Thisisthesumof(wholesaleprice* (wholesale quantity retail quantity)) (calculateCapitalInvestment.c);

Determineandprinttotalprofit(forallbooks):Thisistotalrevenue(#1)minustotalwholesale cost(#2) plus cost of current inventory (#3) (calculateTotalProfit.c);

Determineandprinttotalnumberofsales(totalnumberofbookssold):Thisisthesumofthe retail quantities for all books(calculateTotalBooksSold.c);

Determineandprintaverageprofitpersale:Thisistotalprofit(#4)dividedbytotalnumberofsales (#5)( calculateAverageProfit.c);

Printbooksinstock:ThisfunctionshouldprinteachbookonBooklistwhere(Wholesale quantity Retail quantity >0). The output would be a Title Line that says something like Books in Stock then on subsequent lines, the number of books currently in stock (Wholesale Retail) followed by a tab character then the title of the book followed by the tab character then the author of the book.( printInStock.c);

Printbooksoutofstock:ThisfunctionshouldprinteachbookonBooklistwhere(Wholesale quantity Retail quantity == 0). The output would be a Title Line that says something like

Books out of Stock then on subsequent lines, the title of the book followed by a tab character then the author of the book. (printOutOfStock.c);

9. Addasinglebook(prompttheusertoenterthebookdataforasinglebook,intheformat given above from the keyboard (createNodeAndGetStdinData.c/insert()));

10.Delete book (prompt the user to enter the book stock number: if the book is not found in the linked list, print a message indicating an error, or if the list is empty, print an error indicatingthat) (delete.c);

11.Exit the program. (This option would call writeInventoryToDisk.c and freeAllNodes.c)

The user will enter a choice of one of these eleven options by entering 1 11 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 book which has not been added to the list of books. 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 book from stdin (rather than from a file on disk (i.e. createNodeAndGetStdinData.c)) into a node after allocating storage for the node.

Be sure, for each of the functions above, which is required to print output, to print a label which describes the output, along with the appropriate output on the same line (except for the function to print the books in stock list or books out of stock list, where each title/author pair should be printed on separate line).

GUIDANCE Declare the struct Node shown below at file scope:

struct Data { char title[50];

char author[50]; int StockNumber; float WholesalePrice; float RetailPrice; int WholesaleQuantity; int RetailQuantity;

};

typedef struct Node { struct Data book;

struct Node *next; } Node;

You should write and debug the following functions first:

main the program to read in the inventory data from disk (getDataAndBuildList.c which would

call createNodeAndGetData.c) the functions to print the nodes in the list (i.e. in-stock list and out-of-stock list); find and

carefully follow the sketch of the algorithm in the class slides on linked lists. a function insert (insert.c), to add a node to the list; find and carefully follow the sketch of

the algorithm in the classslides.

DONOTWRITETHECODEFOROTHERFUNCTIONSUNTILTHEFUNCTIONS ABOVE ARE WORKING!!!

If the output for either print statement is empty (e.g. the print out-of-stock list has no books to print, you should print a statement to that effect. Similarly, if you are asked to delete a book with a stock number that is not found in the list, print a statement that says that.

Until you are ready to write the code for the other functions, you can write stub functions with empty parameters and empty blocks for the other functions in the program; if these functions are called in the program, they will do nothing, so this will create no problems for testing and debugging.

After the functions above are working, write a function called delete (delete.c), to delete a single node from the list; find and carefully follow the sketch of the algorithm in the class slides.

Then, write the remaining functions (they are similar to the function to print in or out of stock books in the list.)

CONSTRAINTS

The book data must be stored in a singly-linked list, where each node in the list contains the data for one booktitle.

You are not permitted to declare any variables at file scope; you should, however, declare the Node type used to store the data for the linked list at file scope (but no variables can be declared as part of this declaration). See the description of the declaration of the Node type above.

All floating point data will be entered with two digits of precision and should also be output with two digits ofprecision and using monetary symbols and commas.

You must allocate the storage for each book node structure dynamically.

The book name and author's name should each be stored in strings declared to be of type

array of char of size 50. (See the description of the declaration of the Node type above.)

If a book is deleted, you should call free() to free the storage for the node for the book.

You must write the inventory list to disk (filename2) and then free the space for the individual nodes that still contain data before the program terminates when the user selects option 11.

See the text file posted on Piazza with sample input for Part 1.

You must create a Makefile that creates your executable lab3. Insure that file contains all appropriate dependencies.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago