Question: Write a C++ program that simulates a simple library management system. The program should allow users to perform the following operations: Add a new book

Write a C++ program that simulates a simple library management system. The program should allow users to perform the following operations:

  1. Add a new book to the library.
  2. Display the list of all books in the library.
  3. Search for a book by title.
  4. Search for a book by author.
  5. Borrow a book.
  6. Return a borrowed book.

You can use data structures like arrays or vectors to store information about books in the library. Each book should have attributes like title, author, and availability status (whether it's currently borrowed or not).

Your program should provide a menu for users to select one of the operations above, and it should continue to prompt the user for actions until they choose to exit.

Example:

Library Management System 1. Add a new book 2. Display all books 3. Search for a book by title 4. Search for a book by author 5. Borrow a book 6. Return a borrowed book 7. Exit Enter your choice: 1 Enter book title: The Great Gatsby Enter book author: F. Scott Fitzgerald Book added successfully! Enter your choice: 2 List of all books: 1. Title: The Great Gatsby, Author: F. Scott Fitzgerald, Availability: Available Enter your choice: 3 Enter book title to search: The Great Gatsby Book found: Title: The Great Gatsby, Author: F. Scott Fitzgerald, Availability: Available Enter your choice: 5 Enter book title to borrow: The Great Gatsby Book borrowed successfully! Enter your choice: 2 List of all books: 1. Title: The Great Gatsby, Author: F. Scott Fitzgerald, Availability: Borrowed Enter your choice: 6 Enter book title to return: The Great Gatsby Book returned successfully! Enter your choice: 2 List of all books: 1. Title: The Great Gatsby, Author: F. Scott Fitzgerald, Availability: Available Enter your choice: 7 Exiting the program.

Constraints:

  • Use appropriate data structures to store book information.
  • Handle cases where a book is already borrowed or not found.
  • You can choose to implement this program using classes and objects or with functions and arrays/vectors.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!