Hi I need help with my C program to print a Library receipt using Linux with a driver program that can’t be changed and h file.
Change processTransaction:
o Receives Node **ppHead instead of the bookM array and count
o Uses searchLL to find a book in the ordered linked list.
p = searchLL(*ppHead book.szBookId &pPrecedes);
o Uses pointer notation to update the contents of a node instead of the contents of an array element
(e.g. p0>book.szCustomerId instead of bookM[i].szCustomerId)
Change processCustomerCommand:
o Receives Node **ppHead instead of the bookM array and count
o Invokes processTransaction passing ppHead instead of the bookM array and count
Change processBookCommand:
o Receives Node **ppHead instead of the bookM array and count
o Uses searchLL to find a book in the ordered linked list:
p = searchBooks(*ppHead book.szBookId &pPrecedes);
o Uses pointer notation to reference a book instead of referencing an element of the bookM array.
o Add code for the new BOOK NEW subcommand. This should sscanf the data into elements of a Book
structure (declared using Book book). It should then pass that book to insertLL.
Here is what I have so far.
// If compiling using visual studio tell the compiler not to give its warnings
// about the safety of scanf and printf
#define _CRT_SECURE_NO_WARNINGS 1
#include
#include
#include
#include cs1713p4.h
void printBook(Book * book) {
printf( %-9s %-6s %-10s %lf %lf %40sn
book->szBookId
book->szCustomerId
book->szCheckedOutDt
book->dLateFeePerDay
book->dMaxLateFee
book->szTitle);
}
void printBookHeading() {
printf( %-9s %-6s %-10s %-6s %-6s %-40sn
Book Id Customer Id Checked Out Date Late Fee Per Day Max Late Fee Title);
}
/******************** printBooks **************************************
void printBooks(char *pszHeading Book bookM[] int iBookCnt)
Purpose:
Prints each book in a table format
Parameters:
I char *pszHeading Heading to print before printing the table of books
I Book bookM[] Array of books
I int iBookCnt Number of elements in the bookM array.
Returns:
n/a
Notes:
**************************************************************************/
void printBooks(char *pszHeading Node *pHead) {
printf(%sn pszHeading);
printBookHeading();
while(pHead != NULL) {
printBook(&(pHead->book));
pHead = pHead->pNext;
}
}
/********************processCustomerCommand *****************************
void processCustomerCommand(Book bookM[] int iBookCnt
char *pszSubCommand char *pszRemainingInput
Customer *pCustomer)
Purpose:
Processes the subcommands associated with the CUSTOMER command:
CUSTOMER BEGIN szBookId szCustomerId szCheckedOutDt dLateFeePerDay dMaxLateFee szTitle
specifies the beginning of customer request and includes all the identification information from program 2.
CUSTOMER ADDRESS szStreetAddressszCityszStateCdszZipCd
specifies the address for a customer (separated by commas)
CUSTOMER TRANS cTransType szBookId szTransDt
specifies a single book transaction. Steps:
– Print the Transaction Type Book Id and Transaction Date
– Lookup the book ID using a binary search. If not found print a warning (but do not terminate your program) and return.
– If the transaction date is invalid show a message stating invalid date but do not terminate. Use the validateDate function.
– If the transaction type is C (meaning checkout):
o If the book is already checked out show a message stating already checked out but do not terminate.
o Otherwise check out the book to this customer setting the book’s customer ID. The book’s checked out date needs to be set to the transaction’s date.
– If the transaction type is R (meaning return):
o Use dateDiff to subtract the book’s szCheckOutDt from the transaction’s szTransDt
o If the difference is more than 14:
— Determine the number of days late by subtracting 14 from that difference.
— Compute the late fee by multiplying the number of days late by the book’s dLateFeePerDay.
— If that late fee is greater than the book’s dMaxLateFee change it to dMaxLateFee.
— Print the late fee.
— Add the computed late fee to the customer’s dFeeBalance
o Set the book’s customer ID to NONE.
o Set the book’s check out date to 0000-00-00.
CUSTOMER COMPLETE
specifies the completion of a customer. Print the total fees for this customer.
Parameters:
I/O Book bookM[] Array of books
I int iBookCnt Number of elements in bookM[]
I char *pszSubCommand Should be BEGIN ADDRESS REQUEST or COMPLETE
I char *pzRemainingInput Points to the remaining characters in the input
line (i.e. the characters that following the
subcommand).
I/O Customer *pCustomer The BEGIN subcommand begins a new customer.
Notes:
**************************************************************************/
void processCustomerCommand(Node **ppHead
char *pszSubCommand char *pszRemainingInput
Customer *pCustomer) {
int iScanfCnt;
Transaction transaction;
double *pdCustomerTotalFees;
// Determine what to do based on the subCommand
if (strcmp(pszSubCommand BEGIN) == 0)
{
// get the Customer Identification Information
// your code
iScanfCnt = sscanf(pszRemainingInput %s %d %s %sn pCustomer->szCustomerId pCustomer->dFeeBalance pCustomer->szEmailAddr pCustomer->szFullName);
// Check for bad customer identification data
if (iScanfCnt < 4)
exitError(ERR_CUSTOMER_ID_DATA pszRemainingInput);
}
else if (strcmp(pszSubCommand COMPLETE) == 0)
{
// print the customer's total fees
// your code
printf(tttt%-10s %8s %10s %8.2fn Total Fees *pdCustomerTotalFees);
printf(***********************************************************************n);
*pdCustomerTotalFees = 0;
}
else if (strcmp(pszSubCommand ADDRESS) == 0)
{
// get the postal address and print it
// your code
iScanfCnt = sscanf(pszRemainingInput %30[^]%20[^]%2[^]%[0-9] &pCustomer->szStreetAddress
&pCustomer->szCity &pCustomer->szStateCd &pCustomer->szZipCd);
if (iScanfCnt < 4)
exitError(ERR_CUSTOMER_ADDRESS_DATA pszRemainingInput);
//print the customer
printCustomer(pCustomer);
// print the column heading for the transactions
printf(ttttt%-5s %-9s %-10sn Trans Book Date);
}
else if (strcmp(pszSubCommand TRANS) == 0)
{
printf(n);
}
else printf( *** %s %sn ERR_CUSTOMER_SUB_COMMAND pszSubCommand);
}
/********************processBookCommand *****************************
void processBookCommand(Book bookM[] int iBookCnt
char *pszSubCommand char *pszRemainingInput)
Purpose:
Processes the subcommands associated with the BOOK command:
BOOK CHANGE szBookId dLateFeePerDay dMaxLateFee
change the Late Fee Per Day and Max Late Fee to the specified values
BOOK SHOW szBookId
requests a display of a particular book. Show all of its information.
Parameters:
I/O Book bookM[] Array of books
I int iBookCnt Number of elements in bookM[]
I char *pszSubCommand Should be CHANGE or SHOW
I char *pzRemainingInput Points to the remaining characters in the input
line (i.e. the characters that following the
subcommand).
Notes:
**************************************************************************/
void processBookCommand(Node **ppHead
char *pszSubCommand char *pszRemainingInput) {
Book book;
int iQuantity; // quantity of Books
int iScanfCnt;
// Determine what to do based on the subCommand
// your code
}
double processTransaction(Node **ppHead Customer customer Transaction transation);
And here is the Driver program provided.
And here is the h file provided.
Here us the p4Command.txt
And here is the p4Book.txt