0% found this document useful (0 votes)
27 views6 pages

Library Management System

The document outlines a Library Management System project implemented in C++, designed to manage books, members, and borrowing records using Object-Oriented Programming and file handling. Key features include adding new books, displaying all books, searching by ID, issuing and returning books, and maintaining file records. The provided C++ code demonstrates the implementation of these features, including user interaction for managing library operations.

Uploaded by

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

Library Management System

The document outlines a Library Management System project implemented in C++, designed to manage books, members, and borrowing records using Object-Oriented Programming and file handling. Key features include adding new books, displaying all books, searching by ID, issuing and returning books, and maintaining file records. The provided C++ code demonstrates the implementation of these features, including user interaction for managing library operations.

Uploaded by

sundarsham874
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Library Management System (C++ Project)

Project Aim

To create a system that manages Books, Members, and Borrow/Return Records of a library
using Object-Oriented Programming and File Handling.

Features

1. Add New Book (ID, Title, Author, Quantity)

2. Display All Books

3. Search Book by ID

4. Issue Book to Member

5. Return Book

6. Maintain File Records (books.txt, issue.txt)

C++ Code

#include <iostream>

#include <fstream>

#include <vector>

#include <string>

using namespace std;

class Book {

public:

int id;

string title;

string author;

int quantity;

void input() {
cout << "Enter Book ID: ";

cin >> id;

cin.ignore();

cout << "Enter Title: ";

getline(cin, title);

cout << "Enter Author: ";

getline(cin, author);

cout << "Enter Quantity: ";

cin >> quantity;

void display() {

cout << "\nID: " << id

<< "\nTitle: " << title

<< "\nAuthor: " << author

<< "\nQuantity: " << quantity << "\n";

};

// Save book details to file

void saveBook(Book b) {

ofstream fout("books.txt", ios::app);

fout << b.id << "," << b.title << "," << b.author << "," << b.quantity << "\n";

fout.close();

// Display all books

void showBooks() {
ifstream fin("books.txt");

string line;

cout << "\n--- Library Books ---\n";

while (getline(fin, line)) {

cout << line << endl;

fin.close();

// Search book by ID

void searchBook(int searchId) {

ifstream fin("books.txt");

string line;

bool found = false;

while (getline(fin, line)) {

int id = stoi(line.substr(0, line.find(',')));

if (id == searchId) {

cout << "\nBook Found: " << line << endl;

found = true;

break;

fin.close();

if (!found) cout << "\nBook not found!\n";

// Issue book

void issueBook(int bookId, string memberName) {


ofstream fout("issue.txt", ios::app);

fout << "BookID: " << bookId << ", Issued to: " << memberName << "\n";

fout.close();

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

// Show issued books

void showIssuedBooks() {

ifstream fin("issue.txt");

string line;

cout << "\n--- Issued Books ---\n";

while (getline(fin, line)) {

cout << line << endl;

fin.close();

int main() {

int choice;

do {

cout << "\n===== Library Management System =====\n";

cout << "1. Add Book\n2. Show Books\n3. Search Book\n4. Issue Book\n5. Show Issued
Books\n6. Exit\n";

cout << "Enter choice: ";

cin >> choice;

if (choice == 1) {

Book b;
b.input();

saveBook(b);

else if (choice == 2) {

showBooks();

else if (choice == 3) {

int id;

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

cin >> id;

searchBook(id);

else if (choice == 4) {

int id;

string member;

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

cin >> id;

cin.ignore();

cout << "Enter Member Name: ";

getline(cin, member);

issueBook(id, member);

else if (choice == 5) {

showIssuedBooks();

} while (choice != 6);

return 0;
}

Sample Output

===== Library Management System =====

1. Add Book

2. Show Books

3. Search Book

4. Issue Book

5. Show Issued Books

6. Exit

Enter choice: 1

Enter Book ID: 101

Enter Title: C++ Programming

Enter Author: Bjarne Stroustrup

Enter Quantity: 5

===== Library Management System =====

Enter choice: 2

--- Library Books ---

101,C++ Programming,Bjarne Stroustrup,5

You might also like