0% found this document useful (0 votes)
9 views5 pages

Group Lab Project

C++ code

Uploaded by

rayyanquddusi683
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

Group Lab Project

C++ code

Uploaded by

rayyanquddusi683
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

Computer Fundamental and Programming

Fall-2024
Grading:
CLO1 CLO2 CLO3 Total

Comments:

1st semester Date of Submission: 26/12/2024

Title: Project of CFP(Lab)

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;
};

const int MAX_BOOKS = 100;


Book library[MAX_BOOKS];
int totalBooks = 0;

string toLowercase(const string& str) {


string lowerStr;
for (char ch : str) {
lowerStr += tolower(ch);
}
return lowerStr;
}

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;

for (int i = 0; i < totalBooks; i++) {


if (library[i].id == bookId) {
for (int j = i; j < totalBooks - 1; j++) {
library[j] = library[j + 1];
}
totalBooks--;
cout << "Book removed successfully!" << endl;
return;
}
}
cout << "Book not found!" << endl;
}

void issueBook() {
int bookId;
cout << "Enter Book ID to issue: ";
cin >> bookId;

for (int i = 0; i < totalBooks; i++) {


if (library[i].id == bookId && library[i].availability == "Available") {
library[i].availability = "Issued";
cout << "Book issued successfully!" << endl;
return;
}
}
cout << "Book not available or doesn't exist!" << endl;
}

void returnBook() {
int bookId;
cout << "Enter Book ID to return: ";
cin >> bookId;

for (int i = 0; i < totalBooks; i++) {


if (library[i].id == bookId && library[i].availability == "Issued") {
library[i].availability = "Available";
cout << "Book returned successfully!" << endl;
return;
}
}
cout << "Book not found or already available!" << endl;
}

void searchByTitle() {
string title;
cout << "Enter Book Title to search: ";
cin.ignore();
getline(cin, title);

title = toLowercase(title);

bool found = false;


for (int i = 0; i < totalBooks; i++) {
string bookTitleLower = toLowercase(library[i].book_title);
if (bookTitleLower == title) {
cout << "Book ID: " << library[i].id << ", Title: " << library[i].book_title
<< ", Author: " << library[i].author_name << ", Availability: " << library[i].availability <<
endl;
found = true;
}
}

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);

bool found = false;


for (int i = 0; i < totalBooks; i++) {
string authorNameLower = toLowercase(library[i].author_name);
if (authorNameLower == author) {
cout << "Book ID: " << library[i].id << ", Title: " << library[i].book_title
<< ", Author: " << library[i].author_name << ", Availability: " << library[i].availability <<
endl;
found = true;
}
}

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: ";

cin >> 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;
}

You might also like