[Contest] Library Management System


Submit solution

Points: 10
Time limit: 0.5s
Memory limit: 3M

Author:
Problem type
Allowed languages
C++

Library Management System

Certainly! Here's another complex C++ lab exercise for classes and objects with a different use case: a library management system.

Exercise: Library Management System

Objective: Create a C++ program for a library management system using classes and objects. The program should allow users to manage books, check them out, return them, and view the library's catalog. Additionally, implement data encapsulation, error handling, and efficient book tracking.

Requirements:

  1. Create a class Book with the following attributes:

    • title
    • author
    • ISBN (a unique identifier)
    • isAvailable (a boolean indicating if the book is available for checkout)
  2. Create a class Library that stores a collection of Book objects. The Library class should have the following methods:

    • addBook(Book book) to add a book to the library's catalog.
    • removeBook(string ISBN) to remove a book from the catalog by its ISBN.
    • checkoutBook(string ISBN) to allow a user to check out a book (set isAvailable to false).
    • returnBook(string ISBN) to allow a user to return a book (set isAvailable to true).
    • searchBook(string title) to search for a book by title and display its information.
    • displayCatalog() to display a list of all books in the library, including their availability status.
  3. Implement data encapsulation by making the attributes of the Book class private and providing appropriate getter and setter methods.

  4. Implement error handling to handle cases where a user tries to check out a book that is already checked out or return a book that is already available.

  5. Ensure efficient book tracking by using data structures like vectors, maps, or arrays to store and manage the books in the library.

  6. Create a menu-driven program where users can:

    • Add a new book to the library.
    • Remove a book from the library.
    • Check out a book.
    • Return a book.
    • Search for a book by title.
    • Display the library's catalog.
    • Exit the program.

Notes:

  • You can use a container (e.g., vector or map) to store and manage the Book objects in the Library class.
  • Handle duplicate ISBNs or books with the same title gracefully.
  • Implement appropriate constructors and destructors to initialize and clean up resources.

Hints:

  • Use a switch-case statement for the menu-driven interface.
  • Implement functions to validate user inputs, such as ISBN format validation and checking for the existence of books before checkout or return.

This exercise will challenge students to design and implement a complex library management system using classes and objects, encapsulate data effectively, and handle errors and user interactions gracefully. ChatGPT


Comments

There are no comments at the moment.