Library Management System
Managing Books, Libraries, and Users

This project is a comprehensive implementation of a Library System written in C++. The system is designed to manage books, library users, and their interactions through an intuitive driver code that serves as the user interface. It provides an adequate foundation for managing a library's operations and can be extended with additional features.

code preview from the library system project

Why This Project?

This project was built to explore and apply advanced C++ programming concepts in a real-world context. It simulates a functional library system while showcasing coding best practices and modular design.

I wanted to challenge my learning and encorporate different concepts of my knowledge to showcase my skills. I picked this project because it provides a solution to a real-world system; storing books, and library user information. Some next steps to evolve this project, could be to integrate a graphical interface, and creating different inherit (sub-class) users with their own special attributes.

What did I learn?

This project provided a learning curve to my programming skillset, constantly challenging me to learn new concepts and finding more efficient solutions to the methods I created. By no means is my development strategy the most optimal, it is simply one method to create a library management system. I learned how to implement object-oriented programming principles, manage memory effectively, and apply advanced C++ concepts, including inheritance, polymorphism, encapsulation, and data abstraction.

To showcase my learning, you can view my implementation of books, a library system, and library users and their respective attributes, constructors, and methods. You can find more information about this project on my Github.

Class Book

Attributes

Title, Author, Genre, Year_Published

Methods

Constructors

  • Default Constructor:
    The default constructor sets all three attributes (title, author, genre) to "n/a".
  • Parameterized Constructors:
    Initializes one, two, or more attributes (title, author, genre, and year published) using the parameterized constructors. Any attributes not initialized will be set to "n/a".

get_title()

  • Returns the title of the book.

get_author()

  • Returns the author of the book.

get_genre()

  • Returns the genre of the book.

get_year_published()

  • Returns the year the book was published.

operator==

  • Implements equality operator overloading to compare two Book objects.
  • Two books are considered equal if their attributes (title, author, genre, year published) are the same.
  • Use: Prevent duplicate addition of a book to the library.

print()

  • Outputs the current values stored inside the Book object.

Class Library

Attributes

Vector of Book Object Pointers
Vector of Is_Borrowed

Methods

Constructors

  • Default Constructor:
    The default constructor with no parameters implicitly initializes the vector attribute.
  • Parameterized Constructors:
    The parametric constructor takes a vector of Book objects pointer and stores the Book values from that vector into the vector attribute.

Insertion

  • Insertion (Book Pointer):
  • This method takes a pointer to a Book object and stores it in the library's vector. The is_borrowed vector is adjusted accordingly.
  • Checks: The method will check if a book with the exact same details (title, author, genre, year published) already exists in the library using the overloaded equality operator (operator==).

Removal

  • Removal (Book Pointer):
  • This method accepts a pointer to a Book object and removes the corresponding book from the library.
    • If the book is found and removed, the method returns true and adjusts the is_borrowed vector.
    • If the book is not found, it returns false.

Advanced Search

  • Advanced Search (Substring Math):
  • This method searches for books in the library based on substrings of title, author, and genre. It takes input strings for title, author, and genre, which can be partial matches.
    • If a match is found, the book information is printed using the book->print() method.
    • If no match is found, a message indicating that the book is not in the library is printed.
    • The search is case-insensitive.

Borrow Book

  • Borrow Book:
  • This method allows a LibraryUser to borrow a book from the library. It takes the user's object and the title of the book to be borrowed as input.
  • Conditions:
      • The book must not already be borrowed.
      • The user's borrow_count must be smaller than their borrow-limit.
  • If all conditions are met, the is_borrowed value of the book is updated, and the user's borrow() method is called. A message is printed indicating the user and book title.
  • If the conditions are not met, a message indicating the issue is printed.

Return Book

  • Return Book:
  • This method allows a LibraryUser to return a borrowed book to the library. It takes the user's object and the title of the book being returned.
  • Conditions:
      • The book must be marked as borrowed.
  • If the book is borrowed, the is_borrowed value is updated, and the user's return() method is called. A message is printed indicating the user and book title.
  • If the conditions are not met, a message indicating the issue is printed.

Print

  • This method prints all the books stored in the library. For each book, it prints the index in the vector followed by the details of the book, which are obtained using book->print().

Class Library_User

Objective

The class Library_User stores user information and methods of interacting with the library. It is the parent class for the two types of users:

  • The class Student inherits from the class Library_User and has some special attributes and methods.
  • The class Teacher inherits from the class Library_User and has some special attributes and methods.

Attributes

name, user_id, borrowed_count

Methods

Constructors

  • Default Constructor:
    The default constructor sets the attributes name and user_id to "n/a", and borrowed_count to 0.
  • Parameterized Constructors:
    Initializes all attributes (name, user_id, and borrowed_count) using the parametric constructors.

get_name()

  • Returns the name attribute of the user.

get__user_id()

  • Returns the user_id attribute of the user.

get_borrowed_count()

  • Returns the borrowed_count attribute of the user (number of the books borrowed).

borrow()

  • Increments the borrowed_count attribute of the user.

return()

  • Decrements the borrowed_count attribute of the user.

print()

  • Print the current values of the user attributes.

Library-User Sublass: Student and Teacher

The LibraryUser class serves as a base class for both Student and Teacher subclasses, managing attributes and methods common to all users of the library. The Student and Teacher classes inherit from LibraryUser and each add unique features such as borrowing limits and additional functionalities for teachers (e.g., adding and updating books in the library).

Student Class Methods (Inherits from LibraryUser)

  • Attributes:
    • graduated: Indicates whether the student has graduated (True/False).
    • borrow_limit (const int): The maximum number of books a student can borrow. The borrow limit for students is typically lower than that for teachers.
  • Constructors:
    • Default Constructor: Initializes the graduated attribute to False and borrow_limit to the default value specific to students.
    • Parameterized Constructor: Initializes the borrow_limit and attributes from LibraryUser by calling the parameterized constructor of LibraryUser.
  • Methods:
    • get_borrow_limit():
      • Returns the borrow-limit specific to the student.
    • print():
      • Prints details about the student, including whether they are a student, their name, borrow count, and the graduated status.

Teacher Class Methods (Inherits from LibraryUser)

  • Attributes:
    • borrow_limit (const int): The maximum number of books a teacher can borrow. This value is typically higher than that of a student.
  • Constructors:
    • Default Constructor: Initializes the borrow_limit to the default value specific to teachers.
    • Parameterized Constructor: Initializes the borrow_limit and attributes from LibraryUser by calling the parameterized constructor of LibraryUser.
  • Methods:
    • get_borrow_limit():
      • Returns the borrow-limit specific to the teacher.
    • add_book_to_library():
      • Adds a Book pointer to a Library object. This method is only available to teachers, as they are allowed to add books to the library.
    • update_book_details():
      • Updates the details (author, genre, year published) of an existing book in the library, if the title matches. This method is only available to teachers.
    • print():
      • Prints details about the teacher, including whether they are a teacher, their name, borrow count, and the borrow limit.