Group Lab Project
Group Lab Project
Fall-2024
Grading:
CLO1 CLO2 CLO3 Total
Comments:
Group number: 15
Group member:
1. Muhammed Talha
2. Ali Abid
3. Hasnat Khan
4. Muhammad Usman
Batch: Teacher:
BSEE 2024-28 Dr. M. Tufail
Department of Electrical
Engineering
Library Management system:
Develop a system to manage library operations.
The program should:
• Maintain a collection of books with attributes (Book ID, Title, Author, Status:
Issued/Available).
• Allow issuing and returning books. (by removing and adding the book ID
respectively, in the record).
• Search books by title or author.
• Display a list of all books with their statuses.
• Update book records (add new books, remove old books).
Code:
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
struct Book {
int id;
string book_title;
string author_name;
string availability;
};
void addBook() {
if (totalBooks < MAX_BOOKS) {
Book new_Book;
cout << "Enter Book ID: ";
cin >> new_Book.id;
cin.ignore();
cout << "Enter Book Title: ";
getline(cin, new_Book.book_title);
cout << "Enter Author Name: ";
getline(cin, new_Book.author_name);
new_Book.availability = "Available";
library[totalBooks] = new_Book;
totalBooks++;
cout << "Book added successfully!" << endl;
}
else {
cout << "Library is full. Cannot add more books." << endl;
}
}
void removeBook() {
int bookId;
cout << "Enter Book ID to remove: ";
cin >> bookId;
void issueBook() {
int bookId;
cout << "Enter Book ID to issue: ";
cin >> bookId;
void returnBook() {
int bookId;
cout << "Enter Book ID to return: ";
cin >> bookId;
void searchByTitle() {
string title;
cout << "Enter Book Title to search: ";
cin.ignore();
getline(cin, title);
title = toLowercase(title);
if (!found) {
cout << "No matching books found." << endl;
}
}
void searchByAuthor() {
string author;
cout << "Enter Author Name to search: ";
cin.ignore();
getline(cin, author);
author = toLowercase(author);
if (!found) {
cout << "No matching books found." << endl;
}
}
void displayBooks() {
if (totalBooks == 0) {
cout << "No books available in the library." << endl;
return;
}
cout << "Library Books: " << endl;
for (int i = 0; i < totalBooks; i++) {
cout << "Book ID: " << library[i].id << ", Title: " << library[i].book_title
<< ", Author: " << library[i].author_name << ", Availability: " << library[i].availability <<
endl;
}
}
int main() {
int choice;
do {
cout << "\nLibrary Management System" << endl;
cout << "1. Add Book" << endl;
cout << "2. Remove Book" << endl;
cout << "3. Issue Book" << endl;
cout << "4. Return Book" << endl;
cout << "5. Search by Title" << endl;
cout << "6. Search by Author" << endl;
cout << "7. Display All Books" << endl;
cout << "8. Exit" << endl;
cout << "Enter your choice: ";
if (cin.fail()) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Invalid input! Please enter a valid choice." << endl;
continue;
}
switch (choice) {
case 1: addBook(); break;
case 2: removeBook(); break;
case 3: issueBook(); break;
case 4: returnBook(); break;
case 5: searchByTitle(); break;
case 6: searchByAuthor(); break;
case 7: displayBooks(); break;
case 8: cout << "Exiting system." << endl; break;
default: cout << "Invalid choice! Try again." << endl;
}
} while (choice != 8);
return 0;
}