Question: Sample run 2 : Books: id: 1 name: Let _ Us _ C author: Y . Kanetkar quantity: 1 1 rackno: 3 id: 2 name:

Sample run 2:
Books:
id: 1
name: Let_Us_C
author: Y.Kanetkar
quantity: 11
rackno: 3
id: 2
name: Head_First_C
author: D.Griffiths
quantity: 10
rackno: 45
id: 6
name: C_Prog
author: C.Brown
quantity: 45
rackno: 6
Enter id of the book to be updated:
6
How many books will be added(+) or removed(-):
5
Books:
id: 1
name: Let_Us_C
author: Y.Kanetkar
quantity: 11
rackno: 3
id: 2
name: Head_First_C
author: D.Griffiths
quantity: 10
rackno: 45
id: 6
name: C_Prog
author: C.Brown
quantity: 50
rackno: 6
Enter id of the book to be deleted:
2
Books:
id: 1
name: Let_Us_C
author: Y.Kanetkar
quantity: 11
rackno: 3
id: 6
name: C_Prog
author: C.Brown
quantity: 50
rackno: I have a C Programming assaignment. We have to complete a code structure. I will put the required sample run for the code. Also, there is a binary file library.bin which contains records of books in a library. Each book record will be stored using bookData struct. I will also put the library.bin file. Assaignment Description: You are given a binary file library.bin (you can download from Moodle) which contains records of books in a library. Each book record will be stored using bookData struct.
typedef struct
{
int id; // book id
char name[20]; // book name
char author[20]; // author of book
int quantity; // quantity of book
int rackno; // rack no of the book
} bookData;
Library.bin file consists of 100 records. 96 of them are blank records. The other 3 records (not blank) are placed in specific positions of the binary file based on their ids. For example, if id of the book is 5, its record is the fifth record in the file. The size of each record is equal to the size of bookData struct. The records are sorted according to their id number.
Implement the following functions:
void showRecords()- It shows and lists all records in the binary file.
int updateRecord(int id, int diff)- This function updates quantity of the book whose id is provided in the parameter id. The update is performed by adding the number in the parameter diff to the quantity of the book with the given id. If there is a book record with the given id, the new quantity of the book is written to library.bin and the function returns 1; otherwise, it returns 0.
int deleteRecord(int id)- This function removes the book with the given id from binary file (library.bin) by setting its fields to {0,"","",0,0}. If the given id is found in the binary file, the book record will be removed from the binary file and the function returns 1; otherwise, it returns 0. A skeleton code (HW3_skeleton.c) provided in Moodle. Note that, in each function, you should open library.bin,
perform your task, and close the file. In showRecords fuction, open the file with rb, in updateRecord and deleteRecord function open the file with rb+.
Hint: fseek() is used to move file pointer associated with a given file to a specific position. You need to use fseek () function to add, update and delete any record in binary file. Here is the code structure that needs to be complete: #include
#include
typedef struct
{
int id; // book id
char name[20]; // book name
char author[20]; // author of book
int quantity; // quantity of book
int rackno; // rack no of the book
} bookData;
void showRecords();
int updateRecord(int id, int diff);
int deleteRecord(int id);
int main()
{
int id;
int diff;
printf("Books:");
showRecords();
printf("Enter id of the book to be updated:");
scanf("%d",&id);
printf("How many books will be added(+) or removed(-):");
scanf("%d",&diff);
if (updateRecord(id, diff)==0)
printf("There is no book with id %d",id);
printf("Books:");
showRecords();
printf("Enter id of the book to be deleted:");
scanf("%d",&id);
if (deleteRecord(id)==0)
printf("There is no book with id %d".,id);
printf("Books:");
showRecords();
return 0;
}
void showRecords()
{
// implement here
}
int updateRecord(int id, int diff)
{
// implement here
}
int deleteRecord(int id)
{
// implement here
}
 Sample run 2: Books: id: 1 name: Let_Us_C author: Y.Kanetkar quantity:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!