dsalab3
dsalab3
#include <string>
using namespace std;
class Book {
public:
string title;
string author;
string isbn;
class Library {
public:
Book* books[5]; // Array to store book pointers (maximum 5 books for
simplicity)
int count;
int main() {
Library library;
int choice;
while (true) {
cout << "\nLibrary Management System" << endl;
cout << "1. Add Book" << endl;
cout << "2. Display All Books" << endl;
cout << "3. Search Book by Title" << endl;
cout << "4. Exit" << endl;
cout << "Enter your choice: ";
cin >> choice;
cin.ignore(); // To ignore newline character from previous input
switch (choice) {
case 1:
// Add a new book
{
string title, author, isbn;
cout << "Enter book title: ";
getline(cin, title);
cout << "Enter author name: ";
getline(cin, author);
cout << "Enter ISBN: ";
getline(cin, isbn);
library.addBook(title, author, isbn);
break;
}
case 2:
// Display all books
library.displayAllBooks();
break;
case 3:
// Search for a book by title
{
string searchTitle;
cout << "Enter book title to search: ";
getline(cin, searchTitle);
library.searchByTitle(searchTitle);
break;
}
case 4:
// Exit the program
cout << "Exiting the Library Management System." << endl;
return 0;
default:
cout << "Invalid choice. Please try again." << endl;
}
}
return 0;
}