Description
You are tasked with creating a simple program to manage book records in a library.
You will use C structs and pointers to implement the system. Each book in the library has the following information:
– Title (string)
– Author (string)
– ISBN (string)
– Year of publication (integer)
– Available copies (integer)
– Total copies (integer)
Your program should allow the following operations:
1. Add a new book to the library.
2. Display the details of a specific book based on its ISBN.
3. Display a list of all books in the library.
4. Update the number of available copies for a book.
5. Delete a book (along with its copies) from the library.
You must use pointer / offset notation in this assignment instead of array notation. For instance, if you have an array named a, to access its content under subscript 5, you must write: “(a + 5) instead of a[5]. Please note that points will be deducted if this requirement is not followed.
**Requirements:**
1. Create a struct to represent a book’s information.
2. Implement a dynamic data structure to store multiple book records (an array of size 100).
3. Implement functions for each of the operations listed above.
4. Display appropriate messages to inform the user of the success or failure of each operation.
5. Implement a menu-driven interface for the user to interact with the program.
6. You must write the c files for the corresponding header files:
—
### addBook.h:
void addBook(struct Book* library, int* bookCount);
disployBookByISBN:
void displayBookByISBN(struct Book* library, int bookCount);
displayAllBooks.h:
void displayAllBooks(struct Book* library, int bookCount);
updateAvailableCopies.h:
void updateAvailableCopies(struct Book* library, int bookCount);
deleteBook.h:
void deleteBook(struct Book* library, int* bookCount);
8. You must write an appropriate Makefile.
Using the following main.c to test your c files.
int main() {
struct Book* library = (struct Book*)malloc(100 * sizeof(struct Book));
int bookCount = 0;
if (library == NULL) {
printf(“Memory allocation failed. Exiting:\n”);
return 1;
}
int choice;
while (i) {
printf(“\nWelcome to the Library Book Record System\n”);
printf(“1. Add a new book\n”);
printf(“2. Display book details by ISBN\n”);
printf(“3. Display all books\n”);
printf(“4. Update available copies\n”);
printf(“5. Delete a book\n”);
printf(“6. Exit\n”);
printf(“Enter your choice: “);
scanf(“%d”, &choice);
switch (choice) {
case 1:
addBook(library, &bookCount);
break;
case 2:
displayBookByISBN(library, bookCount);
break;
case 3:
displayAllBooks(library, bookCount);
break;
case 4:
updateAvailableCopies(library, bookCount);
break;
case 5:
deleteBook(library, &bookCount);
break;
case 6:
free(library);
printf(“Goodbye!\n”);
return 0;
default
printf(“Invalid choice. Please enter a valid option.\n”);
}
return 0;
Sample Run:
Welcome to the Library Book Record System!
1. Add a new book
2. Display book details by ISBN
3. Display all books
4. Update available copies
5. Delete a book
6. Exit
Enter your choice: 1
Enter book title: xyz
Enter author: bbb
Enter ISBN: 9780316769
Enter year of publication: 1950
Enter total copies: 3
Enter available copies: 3
Book added successfully!
Enter your choice: 2
Enter ISBN to search: 9780316769
Book details:
Title: xyz
Author: bbb
ISBN: 9780316769
Year of publication: 1950
Total copies: 3
Available copies: 3
Enter your choice: 3
List of all books:
1. Title: xyz
Author: bbb
ISBN: 978031679
Year of publication: 1950
Total copies: 3
Available copies: 3
Enter your choice: 4
Enter ISBN to update available copies: 9780316769
Enter year available copies: 2
Available copies updated successfully!
Enter your choice: 5
Enter ISBN to delete: 9780316769
Book deleted successfully!
Enter your choice: 3
List of all books: (no books left)
Enter your choice: 6
Goodbye!
To submit your makefile and C files on Moodle:
1. Create a folder with your last name.
2. Place your c file(s), header file(s) and makefile inside the folder.
3. Zip the folder.
4. Upload it into Moodle.