Building a Simple Library Management System in C++

Overview

In this post, we’ll explore a simple Library Management System developed in C++ that enables basic library functions such as adding, searching, and listing books as well as issuing and returning books. This system demonstrates key object-oriented programming (OOP) concepts, making it an ideal mini-project for students and those looking to enhance their coding skills.

Project Features

The Library Management System comprises two user roles:

  1. Admin: Responsible for managing books in the library.
  2. Student: Can search, issue, and return books.

Key functionalities include:

  • Adding books with attributes like title, author, pages, and price.
  • Listing all books or books by a specific author.
  • Searching for books by title.
  • Issuing and returning books, tracked by an isIssued status.

Code Walkthrough

1. Book Class

The Book class encapsulates the properties of a book, including its title, author, number of pages, price, and issuance status.

class Book {
public:
string title;
string author;
int pages;
float price;
bool isIssued;

Book(string t = “”, string a = “”, int p = 0, float pr = 0.0)
: title(t), author(a), pages(p), price(pr), isIssued(false) {}
};

2. Library Class

The Library class acts as a container for Book objects, providing methods to manage the books:

  • addBook(): Adds a new book to the library.
  • displayBooks(): Displays details of all books.
  • searchBook(): Searches for a book by its title.
  • listBooksByAuthor(): Lists books by a particular author.
  • issueBook(): Marks a book as issued.
  • returnBook(): Marks a book as returned.

class Library {
private:
static const int MAX_BOOKS = 100;
Book books[MAX_BOOKS];
int count;

public:
Library() : count(0) {}

void addBook(const Book& book) {
if (count < MAX_BOOKS) {
books[count] = book;
count++;
cout << “Book added successfully!” << endl;
} else {
cout << “Library is full, cannot add more books.” << endl;
}
}

void displayBooks() {
if (count == 0) {
cout << “No books in the library.” << endl;
return;
}
for (int i = 0; i < count; i++) {
cout << “Title: ” << books[i].title
<< “, Author: ” << books[i].author
<< “, Pages: ” << books[i].pages
<< “, Price: $” << books[i].price
<< “, Issued: ” << (books[i].isIssued ? “Yes” : “No”) << endl;
}
}

// Other methods for search, issue, return, etc., omitted for brevity.
};

3. User Menus

To enhance usability, the system provides a menu-based interface for both admin and student users, allowing interaction with the library.

void adminMenu(Library& library) {
// Admin menu logic for adding, displaying, and managing books.
}

void studentMenu(Library& library) {
// Student menu logic for searching, issuing, and returning books.
}

int main() {
Library library;
int userType;

do {
cout << “Welcome to the Library Management System” << endl;
cout << “Select User Type: ” << endl;
cout << “1. Admin” << endl;
cout << “2. Student” << endl;
cout << “3. Exit” << endl;
cin >> userType;

switch (userType) {
case 1:
adminMenu(library);
break;
case 2:
studentMenu(library);
break;
case 3:
cout << “Exiting the system…” << endl;
break;
default:
cout << “Invalid user type selected. Please try again.” << endl;
}
} while (userType != 3);

return 0;
}

Key Concepts and Benefits

This mini-project is a great way to learn and apply OOP principles like encapsulation and modularity. It also introduces fundamental concepts such as:

  • Array-based storage: Using a fixed-size array to store books.
  • Menu-based navigation: Simple console menus for a better user experience.
  • State management: Tracking book issuance using a boolean variable.

Possible Improvements

While this system covers the basics, there is room for future enhancements, such as:

  • Implementing persistent storage using file I/O.
  • Adding user authentication for admin and student roles.
  • Enhancing the search functionality with more criteria.

Source Code  File And Access Link for the Bank Management System

Library_Management_System_report

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Explore More

How to Work in the AI Generation as a Full Stack Web Developer

April 6, 2024 0 Comments 0 tags

The use of artificial intelligence (AI) has transformed a number of businesses in today’s digital world, including web development. The need for full-stack web developers—skilled individuals who can handle the complexity of the AI generation—is growing as technology develops. This post offers insightful analysis and useful advice on how to survive in this hectic, and constantly-changing industry. Key Strategies for Success in the AI Generation Accepting AI-Powered Products Full-stack web developers must accept AI technologies and keep up with the most recent developments as AI

BANK MANAGEMENT SYSTEM MINI PROJECT Building a Simple Bank Management System in C++: A Complete Guide

November 7, 2024 0 Comments 1 tag

Building a Simple Bank Management System in C++: A Complete Guide In today’s digital world, managing and automating banking operations is more essential than ever. If you’re a student or

How Big Is Tata Group?

Tata Sons Private Limited
August 20, 2023 0 Comments 9 tags

Jamsetji Nusserwanji Tata started Tata Group of company In 1868 with a capital of ₹21000. In today’s days, Tata Group pays 2.25% of India’s total tax. there are 100+ operating