[Contest] Library Management System
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:
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)
Create a class
Library
that stores a collection ofBook
objects. TheLibrary
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 (setisAvailable
tofalse
).returnBook(string ISBN)
to allow a user to return a book (setisAvailable
totrue
).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.
Implement data encapsulation by making the attributes of the
Book
class private and providing appropriate getter and setter methods.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.
Ensure efficient book tracking by using data structures like vectors, maps, or arrays to store and manage the books in the library.
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 theLibrary
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