You are on page 1of 19

Part 1:

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<windows.h>

struct Book {
char author[40];
char title[40];
int isbn;
char subject[40];
char loan[40];
int shelf;
char loan_status[40];
int no_copies;
char mark[40];
};

struct User {
char name[40];
int id;
int max;
int current;
int allocated[100];
char date_start[100][40];
char date_end[100][40];
int charges;
int account_status;

};

int book_section(struct Book *, int);

int add_book(struct Book *, int);

void display_book(struct Book *, int, int);

int search_book(struct Book *, int);

void update_book(struct Book *, int);

/////////////////////////
int user_section(struct User *, struct Book *, int, int);

int add_user(struct User *, int);

void display_user(struct User *, int, int);

int search_user(struct User *, int);

void allocate_book(struct User *, struct Book *, int, int);

void return_book(struct User *, struct Book *, int, int);

void display_user_book(struct User *, struct Book *, int, int);

void account_block(struct User *, int);

void library_statistics(struct Book *, struct User *, int, int);


////
////

int book_section(struct Book *book, int b) {


char ch;
do {
system("cls");
printf("\n-------------------------------\n");
printf(" Library Management System");
printf("\n-------------------------------\n");
printf("A to Add Book");
printf("\nD to Display List of Books");
printf("\nS to Search Book");
printf("\nU to Update Book");
printf("\nM to Go To Main Menu");
printf("\nE to Exit");
printf("\n-------------------------------\n");

ch = getch();
switch (ch) {

case 'A':
case 'a':
system("cls");
printf("---------------------\n");
printf(" Add New Book\n");
printf("---------------------\n");
b = add_book(book, b);
break;

case 'D':
case 'd':
display_book(book, 0, b);
break;

case 's':
case 'S':
printf(" Search Book");
printf("\n-------------------------------\n");
search_book(book, b);
break;

case 'U':
case 'u':
printf(" Update Book");
printf("\n-------------------------------\n");
update_book(book, b);
break;

case 'm':
break;
case 'M':
break;

case 'e':
case 'E':
exit(0);
break;

default:
printf("\n-- Note : Invalid Choice --\n");
break;
}
printf("\n-------------------------\n");
printf("Press Any Key To Continue");
printf("\n-------------------------\n");
getch();
} while (ch != 'm' && ch != 'M');
return b;
}

int add_book(struct Book *book, int b) {

printf("Enter Author Name: ");


scanf("%s", book[b].author);
fflush(stdin);

printf("Enter Title: ");


scanf("%s", book[b].title);
fflush(stdin);
printf("Enter ISBN: ");
scanf("%d", &book[b].isbn);
fflush(stdin);

printf("Enter Subject: ");


scanf("%s", book[b].subject);
fflush(stdin);

printf("Enter Loan Type: ");


scanf("%s", book[b].loan);
fflush(stdin);

printf("Enter Loan Status: ");


scanf("%s", book[b].loan_status);
fflush(stdin);

printf("Enter Shelf Number: ");


scanf("%d", &book[b].shelf);
fflush(stdin);

printf("Enter Number of Copies: ");


scanf("%d", &book[b].no_copies);
fflush(stdin);

b++;
return b;
}

void display_book(struct Book *b, int n, int z) {


system("cls");
printf("---------------------\n");
printf(" Display Books \n");
printf("---------------------\n");

printf("\n Author | Title | ISBN | Shelf | Subject | Loan Type |


Loan Status | Copies | Mark\n");

printf("--------------------------------------------------------------------------------------
----------------------\n");
for (; n < z; n++) {
printf("%12s", b[n].author);
printf(" |%12s", b[n].title);
printf(" |%6d", b[n].isbn);
printf(" |%7d", b[n].shelf);
printf(" |%10s", b[n].subject);
printf(" |%12s", b[n].loan);
printf(" |%15s", b[n].loan_status);
printf(" |%8d", b[n].no_copies);
printf(" |%10s\n", b[n].mark);
}

int search_book(struct Book *book, int b) {


char temp[40], is[40];
printf("\nEnter Title or ISBN to Search Book: ");
scanf("%s", temp);
fflush(stdin);
int i;
for (i = 0; i < b; i++) {
itoa(book[i].isbn, is, 30);
if (strcmp(temp, book[i].title) == 0 || strcmp(temp, is) == 0) {
display_book(book, i, i + 1);
return i;
}
}
printf("\n-- No Data Found --\n");
return -1;
}
void update_book(struct Book *book, int b) {
int i = 0;
char ch;
i = search_book(book, b);
if (i != -1) {

printf("\n--------------------------\n");
printf(" Update Book");
printf("\n--------------------------");
printf("\n Press A To Add Mark");
printf("\n Press U To Update Details");
printf("\n Press M To Go Back");
printf("\n--------------------------\n");
ch = getch();
if (ch == 'a' || ch == 'A') {
printf("Enter Mark to Book: ");
scanf("%s", book[i].mark);
printf("\n-- Mark Added Successfully --");
} else if (ch == 'u' || ch == 'U') {
printf("\n Enter Updated Data");
printf("\n--------------------------\n");
add_book(book, i);
printf("\n-- Data Updated Successfully --");
} else if (ch == 'm' || ch == 'M') {
return;
} else {
printf("Invalid Choice\n");
}
}
}

////
////

int user_section(struct User *user, struct Book *book, int u, int b) {


char ch;
do {
system("cls");
printf("\n-------------------------------\n");
printf(" Library Management System");
printf("\n-------------------------------\n");
printf("A to Add Add User");
printf("\nB to Allot Book");
printf("\nR to Return Book");
printf("\nP for Payment Account");
printf("\nD to Display List of Users");
printf("\nS to Search User & Display Statistics");
printf("\nU to Update User Info");
printf("\nM to Go To Main Menu");
printf("\nE to Exit");
printf("\n-------------------------------\n");

ch = getch();
switch (ch) {

case 'A':
case 'a':
system("cls");
printf("---------------------\n");
printf(" Add New User\n");
printf("---------------------\n");
u = add_user(user, u);
break;

case 'B':
case 'b':
allocate_book(user, book, u, b);
break;

case 'R':
case 'r':
return_book(user, book, u, b);
break;

case 'D':
case 'd':
system("cls");
display_user(user, 0, u);
break;

case 's':
case 'S':
printf(" Search User");
printf("\n-------------------------------\n");
int i = search_user(user, u);
display_user_book(user, book, i, b);
break;

case 'U':
case 'u':
printf(" Search User To Update Privilege");
printf("\n-------------------------------\n");
int z = search_user(user, u);
printf("\nEnter Updated Max Number of Books");
scanf("%d", &user[z].max);
printf("\n-- Data Updated Successfully --\n");
break;

case 'p':
case 'P':
account_block(user, u);
break;

case 'm':
case 'M':
break;

case 'e':
case 'E':
exit(0);
break;

default:
printf("\n-- Note : Invalid Choice --\n");
break;
}
printf("\n-------------------------\n");
printf("Press Any Key To Continue");
printf("\n-------------------------\n");
getch();
} while (ch != 'm' && ch != 'M');
return u;
}

int add_user(struct User *user, int u) {

printf("Enter User Name: ");


scanf("%s", user[u].name);
fflush(stdin);

printf("Enter Id: ");


scanf("%d", &user[u].id);
fflush(stdin);

printf("Maximum Number of Book: ");


scanf("%d", &user[u].max);
fflush(stdin);

user[u].account_status = 1;
user[u].current = 0;
user[u].charges = 0;
u++;
return u;
}

void display_user(struct User *b, int n, int z) {


printf("---------------------\n");
printf(" Display User \n");
printf("---------------------\n");

printf("\n Name | ID | Max Books | Borrowed Books | Total


Charges | Account Status");

printf("\n------------------------------------------------------------------------------------
-----------\n");
for (; n < z; n++) {
printf("%15s", b[n].name);
printf(" |%10d", b[n].id);
printf(" |%15d", b[n].max);
printf(" |%15d", b[n].current);
printf(" |%15d", b[n].charges);
if (b[n].account_status == -1) {
printf(" | Blocked\n");
} else {
printf(" | Active\n");
}

void display_user_book(struct User *user, struct Book *book, int u, int b) {


system("cls");
display_user(user, u, u + 1);

printf("\n____________________________________________________________________________________
_________________________\n");
int i;
printf("\nSr. # | Author | Title | ISBN | Shelf | Subject | Issue
Date | Due Date\n");

printf("--------------------------------------------------------------------------------------
----------------------\n");
for (i = 0; i < user[u].current; i++) {
int n = user[u].allocated[i];
printf("%5d", i + 1);
printf(" |%12s", book[n].author);
printf(" |%12s", book[n].title);
printf(" |%6d", book[n].isbn);
printf(" |%7d", book[n].shelf);
printf(" |%10s", book[n].subject);
printf(" |%15s", user[u].date_start[i]);
printf(" |%15s\n", user[u].date_end[i]);

}
}

int search_user(struct User *user, int u) {


char temp[40], is[40];
printf("\nEnter Name or Id to Search User: ");
scanf("%s", temp);
fflush(stdin);
int i;
for (i = 0; i < u; i++) {
itoa(user[i].id, is, 30);
if (strcmp(temp, user[i].name) == 0 || strcmp(temp, is) == 0) {
system("cls");
display_user(user, i, i + 1);
return i;
}
}
printf("\n-- No Data Found --\n");
return -1;
}

void allocate_book(struct User *user, struct Book *book, int u, int b) {


system("cls");
printf("\n-----------------------------\n");
printf(" Book Allocation");
printf("\n-----------------------------\n");
int us, bo;
us = search_user(user, u);
if (us != -1) {
if (user[us].current >= user[us].max) {
printf("\n-- NOTE: Maximum Limit For The User Has Reached --\n");
} else if (user[us].account_status == -1) {
printf("\n-- NOTE: User Account Has Been Blocked --\n");
} else {
bo = search_book(book, b);
if (bo != -1) {
user[us].charges = user[us].charges + 200;
user[us].allocated[user[us].current] = bo;

printf("\nEnter Issue Date: ");


scanf("%s", user[us].date_start[user[us].current]);
printf("\nEnter Due Date: ");
scanf("%s", user[us].date_end[user[us].current]);
printf("\n-- NOTE: Book Issued Successfully --\n");
user[us].current++;
display_user_book(user, book, us, bo);
}
}

}
}

void return_book(struct User *user, struct Book *book, int u, int b) {


system("cls");
printf("\n-----------------------------\n");
printf(" Book Return");
printf("\n-----------------------------\n");
int us, bo;
us = search_user(user, u);
if (us != -1) {
if (user[us].current < 1) {
printf("\n-- NOTE: No Book Issued Yet --\n");
} else {
display_user_book(user, book, us, bo);
printf("\nEnter Sr. # Return Book: ");
int sr, num;
scanf("%d", &sr);
if (sr <= user[us].current) {
for (num = (sr - 1); num < user[us].current - 1; num++) {
user[us].allocated[num] = user[us].allocated[num + 1];
strcpy(user[us].date_start[num + 1],
user[us].date_start[num]);
strcpy(user[us].date_end[num + 1],
user[us].date_end[num]);
}
user[us].current--;
user[us].charges = user[us].charges - 200;
system("cls");
display_user_book(user, book, us, bo);
printf("\n-- Book Returned Successfully --\n");
} else {
printf("\n-- Note: No Such Book --");
}
}
}
}

void account_block(struct User *user, int u) {


printf("\n--------------------------\n");
printf(" User Account ");
printf("\n--------------------------\n");
int acc;
char ch;
acc = search_user(user, u);
if (acc != (-1)) {
if (user[acc].account_status == -1) {
printf("\nPress A to Activate Account: ");
ch = getch();
if (ch == 'A' || ch == 'a') {
user[acc].account_status = 1;
printf("\n-- Account has Been Activated Successfully --");
} else {
printf("\n Invalid Input");
}
} else {
printf("\nPress B to Block Account: ");
ch = getch();
if (ch == 'B' || ch == 'b') {
user[acc].account_status = -1;
printf("\n-- Account has Been Blocked Successfully --");
} else {
printf("\n Invalid Input");
}
}
display_user(user, acc, acc + 1);
}
}

void library_statistics(struct Book *book, struct User *user, int b, int u){
system("cls");
printf("\n-------------------------------\n");
printf(" Library Statistics");
printf("\n-------------------------------\n\n");
display_book(book,0,b);

printf("\n____________________________________________________________________________________
____________\n");
display_user(user,0,u);

printf("\n-------------------------\n");
printf("Press Any Key To Continue");
printf("\n-------------------------\n");
getch();
}

int main() {
struct Book book[100];
struct User user[100];
int b = 0, u = 0;
char ch;

do {
system("cls");
printf("\n-------------------------------\n");
printf(" Library Management System");
printf("\n-------------------------------\n");
printf("Press\n");
printf("B For Book Section\n");
printf("U For User Section\n");
printf("L For Library Section\n");
printf("E To Exit\n");
printf("-------------------------------\n");

ch = getch();
switch (ch) {
case 'b':
case 'B':
b = book_section(book, b);
break;

case 'U':
case 'u':
u = user_section(user, book, u, b);
break;

case 'L':
case 'l':
library_statistics(book, user, b, u);
break;

case 'e':
case 'E':
exit(0);

default:
printf("\n-- Note : Invalid Choice --\n");
printf("\n-------------------------\n");
printf("Press Any Key To Continue");
printf("\n-------------------------\n");
getch();
break;
}
} while (1);
}
Part 2:
1. Problem Specification:
Here the problem specification is to digitalize the current manual system of
university library where user can manage thing digitally and efficiency of working can
be increased.

2. Analysis:

a. Input:
In this system inputs will be:
i. Book details for adding new book.
ii. Updated details for present book.
iii. Book status.
iv. Details for new user.
v. Book name for searching.
b. Output:
Output will be complete Library Management System having different functions:
i. In case of search the output will be details of specified book.
ii. In case or statistics, the output will be the complete statistics of.
iii. Book Status
c. Requirement:
i. It must be able to store the set of books including their author(s), title,
ISBN, subject, loan type (normal, short loan, no-take-out), shelf mark,
loan status, number of copies, etc. Also, it should provide options for
altering the details of a book, mark it as lost/damaged/ordered, etc.
ii. Registration of a new library user with varying privileges (e.g., maximum
number of books), which can be altered for any existing user at any time.
iii. Search for a particular book and allocate a book to a specific borrower for
a specific period. Also, implement returns and renewals.
iv. Provide library statistics about the number of books and borrowers and if
possible, their different types.
v. Provide borrower statistics about the number of books and charges
incurred to a particular account. Implement payment and account
blocking.
3. Design:
Following steps are required to solve the problem.
Adding Record:
1. Allow user to enter choice to perform a specific function.
2. Get input from the user to add new book.
3. Store the input in a list of already present books.
4. Add new user.
5. Set privilege for a user.
Search, Display and Updating Record:
6. Display the list of stores books.
7. Get name of the book to search it.
8. Display searched book.
9. Get updated details to update any searched book.
10. Display list of users.
11. Search for user.
Book Allotment:
10. Search for book to allot.
11. Allot a book to a user for a specific time.
12. Set option for return and renewal.
13. Manage Payment
Library Statistics:
13. Display library statistics.
14. Provide borrower statics.

4. Implementation:
1. main () It controls the flow of program. (Step 1)
2. book_section() It controls the flow of book section.
3. user_sectio() It controls the flow of user section.
4. add_book () Used to add new book. (Step 2-3)
5. add_user() Used to add new user. (Step 4-5)
6. display_book () Used to display the list of all books. (Step 6)
7. search_book() Used to search and display specific book. (Step 7-8)
8. update_book () Used to update the details of book. (Step 9)
9. allocate_book() It is used to allocate a book to user. (Step 10-11)
10. return_book() It is used to return the book from user. (Step 12)
11. account_block() It is used to block and activate an account for user. (13)
12. Library_statistics() It is used to display the statistics of library. (Step 13-14)
5. Testing:
Program is tested several times by using multiple inputs to check for any
logical or conceptual error. Here are the output screenshots to verify the testing
phase.

Main Panel:

Book Section:

Adding a New Book:


Verifying the New Book By Displaying:

Searching for the book:


User Section:

Adding a New User:

Verifying the entered user:


Book Allotment to a user:

Returning the book:


Updating Privilege:
Blocking/Unblocking Account:
Part 3:

User Manual:
This program is developed to manage library tasks. User can add, update records.

Main Section:
After running the program main section will appear. Use can choose to navigate to book
section, user section or library statistics.
 Press B for Book Menu.
 Press U for User Menu.
 Press L for Library Statistics.
 Press E to Exit.
Do not worry if wrong key is pressed. Program will show an invalid input message and
prompt the user to enter input again.

Book Section:
In book section user can add, update and search for books.
 Press A to Add Book
 Press D to Display List
 Press S to Search
 Press U to Update
 Press M for Main Menu
 Press E to Exit
Add Book:
In this section program will ask for the details of book and book will be stored in the
list.
Display Book
This option will display a list of all the present books.
Search Book
In this option program will ask the user to enter title or ISBN of book. If book found,
it will be displayed. Otherwise Not Found message will be shown.
Update Book
This option is used to update the details of existing book.

User Section:
In this section record of library user will be maintained and allotment of books will
be handled.

 A to Add User
 B to Allot Book
 R to Return Book
 P for Payment Account
 D to Display List of Users
 S to Search User & Display Statistics
 U to Update User Info
 M to Go To Main Menu
 E to Exit
Add User
This option will prompt the user to enter user details to store it.
Allot Book
In this section program will ask the user to input username. If found, then it will ask
for book title or number. If found, it will ask for issue date and due date. After this the
book will issued to that specific user and can be seen from Search User & Display
Statistics option.
Return Book
In this option first program will ask for the username. If found, it will show the list of
allocated books to that user if any. From that list user will enter the serial number to
return the book. After entering, the book will be returned and can be confirmed from
Search User & Display Statistics option.
Payment Account
In this option the user can block or activate a user account. If account is activated, a
block option will be shown and of account is already blocked, an option to activate will
be displayed.
Display List of Users
This function is used to display the list of all users.
Search User & Display Statistics
This function shows the complete statistics for a user. In this option, user will be
asked to enter username. Complete detail of user along with complete detail of all books
allotted to that user will be shown.
Update User Info
In this option user can search for a specific registered user and his privileges can be
updated.

Library Section:
In this section the complete list of books and user will be shown.

You might also like