0% found this document useful (0 votes)
5 views11 pages

pbl1

The document outlines a project for an Online Library Management System (OLMS) designed to automate library resource management. It includes C code for functionalities such as borrowing, returning, and reserving books, along with data structures for managing books, reservations, and user actions. The system allows users to interact through a menu-driven interface for various library operations.

Uploaded by

thakurajay8865
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views11 pages

pbl1

The document outlines a project for an Online Library Management System (OLMS) designed to automate library resource management. It includes C code for functionalities such as borrowing, returning, and reserving books, along with data structures for managing books, reservations, and user actions. The system allows users to interact through a menu-driven interface for various library operations.

Uploaded by

thakurajay8865
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Name:-Ajay Chauhan

Sub-Data Structure
Sec-3A
Project based Learning
Online Library Management System
Objective
The Online Library Management System (OLMS) aims to streamline and
automate the management of library resources, enabling users and
administrators to access and manage books efficiently.

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#define MAX_BOOKS 100

#define MAX_USERS 100

typedef struct {

char title[100];

int available;

} Book;

typedef struct {

int front, rear;


int reservations[MAX_USERS];

} ReservationQueue;

typedef struct {

int top;

int history[MAX_USERS];

} BorrowHistoryStack;

Book library[MAX_BOOKS];

ReservationQueue queue;

BorrowHistoryStack stack;

int total_books = 0;

int total_users = 0;

void initQueue() {

queue.front = -1;

queue.rear = -1;

void enqueue(int userID) {

if (queue.rear == MAX_USERS - 1) {

printf("Queue is full. Cannot reserve more books.\n");


} else {

if (queue.front == -1) {

queue.front = 0;

queue.rear++;

queue.reservations[queue.rear] = userID;

int dequeue() {

if (queue.front == -1) {

return -1;

int userID = queue.reservations[queue.front];

queue.front++;

if (queue.front > queue.rear) {

queue.front = queue.rear = -1;

return userID;

void initStack() {

stack.top = -1;

}
void pushStack(int userID) {

if (stack.top == MAX_USERS - 1) {

printf("Stack is full. Cannot record more actions.\n");

} else {

stack.top++;

stack.history[stack.top] = userID;

int popStack() {

if (stack.top == -1) {

return -1;

int userID = stack.history[stack.top];

stack.top--;

return userID;

void addBook(char title[]) {

strcpy(library[total_books].title, title);

library[total_books].available = 1;

total_books++;

void listBooks() {
printf("Available Books in the Library:\n");

for (int i = 0; i < total_books; i++) {

if (library[i].available) {

printf("%d. %s\n", i + 1, library[i].title);

void borrowBook(int userID) {

listBooks();

int bookID;

printf("Enter the book number to borrow: ");

scanf("%d", &bookID);

if (bookID < 1 || bookID > total_books || library[bookID - 1].available == 0) {

printf("Book is not available.\n");

} else {

library[bookID - 1].available = 0;

pushStack(userID);

printf("Book '%s' borrowed successfully!\n", library[bookID - 1].title);

void returnBook(int userID) {

listBooks();
int bookID;

printf("Enter the book number to return: ");

scanf("%d", &bookID);

if (bookID < 1 || bookID > total_books || library[bookID - 1].available == 1) {

printf("This book was not borrowed or is already returned.\n");

} else {

library[bookID - 1].available = 1;

printf("Book '%s' returned successfully!\n", library[bookID - 1].title);

int userIDForReservation = dequeue();

if (userIDForReservation != -1) {

printf("Reservation fulfilled for user %d.\n", userIDForReservation);

void reserveBook(int userID) {

listBooks();

int bookID;

printf("Enter the book number to reserve: ");

scanf("%d", &bookID);

if (bookID < 1 || bookID > total_books || library[bookID - 1].available == 0) {

printf("Book is currently not available for reservation.\n");


enqueue(userID);

} else {

library[bookID - 1].available = 0;

printf("Book '%s' reserved successfully!\n", library[bookID - 1].title);

void undo() {

int userID = popStack();

if (userID == -1) {

printf("No borrowing actions to undo.\n");

} else {

printf("Undoing borrow action for user %d.\n", userID);

int main() {

initQueue();

initStack();

addBook("The C Programming Language");

addBook("Data Structures and Algorithms");

addBook("Design Patterns in C");

addBook("Introduction to Algorithms");
int choice, userID;

while (1) {

printf("\n------ Online Library Reservation System ------\n");

printf("1. Borrow Book\n");

printf("2. Return Book\n");

printf("3. Reserve Book\n");

printf("4. Undo Last Borrow Action\n");

printf("5. Exit\n");

printf("Enter your choice: ");

scanf("%d", &choice);

switch (choice) {

case 1:

printf("Enter your user ID: ");

scanf("%d", &userID);

borrowBook(userID);

break;

case 2:

printf("Enter your user ID: ");

scanf("%d", &userID);

returnBook(userID);

break;

case 3:

printf("Enter your user ID: ");

scanf("%d", &userID);
reserveBook(userID);

break;

case 4:

undo();

break;

case 5:

printf("Exiting system.\n");

exit(0);

default:

printf("Invalid choice. Please try again.\n");

return 0;

output

------ Online Library Reservation System ------

1. Borrow Book

2. Return Book

3. Reserve Book

4. Undo Last Borrow Action

5. Exit

Enter your choice: 1

Enter your user ID: 1234


Available Books in the Library:

1. The C Programming Language

2. Data Structures and Algorithms

3. Design Patterns in C

4. Introduction to Algorithms

Enter the book number to borrow: 4

Book 'Introduction to Algorithms' borrowed successfully!

------ Online Library Reservation System ------

1. Borrow Book

2. Return Book

3. Reserve Book

4. Undo Last Borrow Action

5. Exit

Enter your choice: 2

Enter your user ID: 1234

Available Books in the Library:

1. The C Programming Language

2. Data Structures and Algorithms

3. Design Patterns in C

Enter the book number to return: 4

Book 'Introduction to Algorithms' returned successfully!

------ Online Library Reservation System ------

1. Borrow Book

2. Return Book

3. Reserve Book
4. Undo Last Borrow Action

5. Exit

Enter your choice: 5

Exiting system.

You might also like