A complete Library Management System implemented in C++ using Object-Oriented Programming principles and a MySQL database backend (via MySQL Connector/C++).
- Features
- OOP Concepts Implemented
- System Architecture
- Installation
- Database Setup
- Usage
- Database Structure
- Modules
- Screenshots
- Technical Specifications
- License
- Add new books with complete details
- Remove books (only if no active borrowings)
- Search by title, author, or ID
- Display all available books
- Track total and available copies
- Digital book support (download link & download limit)
- Register new users
- Remove users (only if no active borrowings)
- Display all users
- View borrowing history
- Issue books to registered users
- Return books with overdue fine calculation (₹2/day after 14 days)
- Borrowing limit enforcement
- Persistent storage in MySQL
- Relational schema for books, users, and borrow records
- Transactions for issuing/returning books to maintain consistency
Concept | Implementation Example |
---|---|
Encapsulation | Private data members with public getters/setters |
Inheritance | DigitalBook derived from Book base class |
Polymorphism | Virtual methods for dynamic behavior |
Abstraction | Simplified menu & DB access layers |
Composition | Library contains Book and User objects |
Library Management System
├── Core Classes
│ ├── Book / DigitalBook
│ ├── User
│ ├── BorrowRecord
│ ├── Database (MySQL interface)
│ ├── Library (Business logic)
│ └── LibrarySystem (Menu/UI)
├── Database (library_db)
│ ├── books
│ ├── users
│ └── borrow_records
└── MySQL Connector/C++
- C++11 compatible compiler (e.g., g++)
- MySQL Server 5.7+ (or MariaDB equivalent)
- MySQL Connector/C++ (X DevAPI version)
- Standard C++ libraries
Run the following SQL commands in MySQL:
CREATE DATABASE IF NOT EXISTS library_db;
USE library_db;
CREATE TABLE books (
book_id VARCHAR(20) PRIMARY KEY,
title VARCHAR(100) NOT NULL,
author VARCHAR(50),
total_copies INT NOT NULL,
available_copies INT NOT NULL,
is_active BOOLEAN DEFAULT TRUE,
download_link VARCHAR(200),
download_limit INT
);
CREATE TABLE users (
user_id VARCHAR(20) PRIMARY KEY,
name VARCHAR(50) NOT NULL,
email VARCHAR(50) UNIQUE,
phone VARCHAR(15),
is_active BOOLEAN DEFAULT TRUE
);
CREATE TABLE borrow_records (
record_id INT AUTO_INCREMENT PRIMARY KEY,
user_id VARCHAR(20) NOT NULL,
book_id VARCHAR(20) NOT NULL,
borrow_date DATE NOT NULL,
return_date DATE,
is_returned BOOLEAN DEFAULT FALSE,
FOREIGN KEY (user_id) REFERENCES users(user_id),
FOREIGN KEY (book_id) REFERENCES books(book_id)
);
- Start your MySQL server.
- Compile and run the program.
- Edit the connection string in
main()
to match your MySQL username, password, and host:
mysqlx::Session sess("mysqlx://root:YOUR_PASSWORD@localhost/library_db");
- Use the menu to:
- Add/remove/search/display books
- Register/remove/display users
- Issue/return books
- View borrowed books per user
- See library statistics
Table | Description |
---|---|
books | Stores book info, copies, and digital data |
users | Stores user details and status |
borrow_records | Tracks issued books, dates, and return status |
- Book Module: Handles book-related CRUD
- User Module: Manages user records
- Transaction Module: Issues and returns books
- Database Module: Encapsulates MySQL operations
- UI Module: Displays menus and handles input
- Language: C++11
- Database: MySQL (
library_db
) - Connector: MySQL Connector/C++ (X DevAPI)
- Date Handling: SQL
DATE
fields &strftime
in C++ - Transactions: Used for issuing/returning books
- Error Handling: SQL exceptions and input validation
- Platform: Cross-platform (Windows/Linux/Mac)
This project is licensed under the MIT License.