Library Management System Using C
Library Management System Using C
Algorithm
Define the maximum number of books, maximum length of book title, and
maximum length of author name using #define.
Define a structure named "Book" that contains four elements:
A. title - character array of length MAX_TITLE_LEN to store the title of the
book.
B. author - character array of length MAX_AUTHOR_LEN to store the
name of the author.
C. id - integer to store the unique ID of the book.
d. num_copies - integer to store the number of copies of the book. Define
another structure named "Library" that contains two elements:
A.books - an array of Book structures of length MAX_BOOKS to
store all the books in the library.
b. num_books - integer to store the current number of books in the library.
Define a function named "display_books" that takes a Library structure as an
argument and displays all the books in the library along with their details.
Define a function named "add_book" that takes a pointer to a Library
structure as an argument and adds a new book to the library. a. Check if the
library is full.
A. If not, get the title, author name, ID, and number of copies of
the new book from the user.
c. Add the new book to the books array of the library.
d. Increment the num_books variable of the library.
Define a function named "remove book" that takes a pointer to a Library
structure and an ID of the book to be removed as arguments and removes the
book from the library.
a. Find the index of the book in the books array of the library using its ID.
b. If the book is found, remove it by shifting all the elements in the array
after it one position to the left.
c. Decrement the num_books variable of the library.
In the main function, create a new Library structure with num_books
initialized to 0.
Define a loop that displays a menu of options for the user to choose from.
Get the user's choice from the menu.
Depending on the user's choice, call the appropriate function. If the
user chooses to quit, exit the program.
Flowchart
+------------------------------------------------+
| Start Program |
+------------------------------------------------+
|
|
+------------------------------------------------+
| Initialize library and variables |
+------------------------------------------------+
|
|
+------------------------------------------------+
| Display menu and accept user input |
+ -------------------------------------------- +
|
|
+---------------------------------------------------------+
| Check user input and perform action |
+---------------------------------------------------------+
| | |
| | |
+---------------------------------------------------------+
| Display books Add book Remove book |
+---------------------------------------------------------+
| | |
| | |
C program code
#include <stdio.h>
#include <string.h>
// define maximum number of books in the library
#define MAX_BOOKS 100
1
This is a C program for library management system