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

Lib

The document contains C++ code for a simple Library Management System that allows users to add, issue, and return books. It defines two classes, Book and Library, with methods for managing book details and library operations. The main function provides a user interface for interacting with the library system through a menu-driven approach.

Uploaded by

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

Lib

The document contains C++ code for a simple Library Management System that allows users to add, issue, and return books. It defines two classes, Book and Library, with methods for managing book details and library operations. The main function provides a user interface for interacting with the library system through a menu-driven approach.

Uploaded by

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

#include <iostream>

#include <string>

using namespace std;

class Book {

private:

int id;

string title;

string author;

bool isIssued;

public:

Book() : id(0), title(""), author(""), isIssued(false) {}

void setDetails(int bookId, string bookTitle, string bookAuthor) {

id = bookId;

title = bookTitle;

author = bookAuthor;

isIssued = false;

int getId() { return id; }

string getTitle() { return title; }

string getAuthor() { return author; }

bool getIsIssued() { return isIssued; }

void issueBook() { isIssued = true; }

void returnBook() { isIssued = false; }


void displayDetails() {

cout << "ID: " << id << ", Title: " << title << ", Author: " << author << ", Issued: " << (isIssued ? "Yes" :
"No") << endl;

};

class Library {

private:

Book books[100];

int bookCount;

public:

Library() : bookCount(0) {}

void addBook(int id, string title, string author) {

if (bookCount < 100) {

books[bookCount].setDetails(id, title, author);

bookCount++;

cout << "Book added successfully!\n";

} else {

cout << "Library is full! Cannot add more books.\n";

void issueBook(int id) {

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

if (books[i].getId() == id) {

if (!books[i].getIsIssued()) {
books[i].issueBook();

cout << "Book issued successfully!\n";

} else {

cout << "Book is already issued!\n";

return;

cout << "Book not found!\n";

void returnBook(int id) {

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

if (books[i].getId() == id) {

if (books[i].getIsIssued()) {

books[i].returnBook();

cout << "Book returned successfully!\n";

} else {

cout << "Book was not issued!\n";

return;

cout << "Book not found!\n";

void displayAllBooks() {

if (bookCount == 0) {

cout << "No books in the library.\n";


} else {

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

books[i].displayDetails();

};

int main() {

Library library;

int choice, id;

string title, author;

while (true) {

cout << "\nLibrary Management System" << endl;

cout << "1. Add Book" << endl;

cout << "2. Issue Book" << endl;

cout << "3. Return Book" << endl;

cout << "4. Display All Books" << endl;

cout << "5. Exit" << endl;

cout << "Enter your choice: ";

cin >> choice;

switch (choice) {

case 1:

cout << "Enter ID, Title, and Author: ";

cin >> id;

cin.ignore();

getline(cin, title);
getline(cin, author);

library.addBook(id, title, author);

break;

case 2:

cout << "Enter Book ID to Issue: ";

cin >> id;

library.issueBook(id);

break;

case 3:

cout << "Enter Book ID to Return: ";

cin >> id;

library.returnBook(id);

break;

case 4:

library.displayAllBooks();

break;

case 5:

cout << "Exiting program...\n";

return 0;

default:

cout << "Invalid choice! Try again.\n";

return 0;

You might also like