Library Management in C++
Library management includes book management and member management. Book management includes the member variables as id,title,author and a Boolean variable isIssued. It has the following member functions.
getBookId(), getBookTitle(),getBookstatus(),issueBook() and
returnBook().
Member management includes membered,name. getId(),getName()
are member functions.
In the main() function, create the objects for above
classes. Call the function to get the output.
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Book {
int b_id;
string b_title;
string b_author;
bool b_isIssued;
public:
Book(int i, string
t, string a) : b_id(i), b_title(t), b_author(a), b_isIssued(false) {}
int getBookId() {
return b_id; }
string
getBookTitle() { return b_title; }
string
getBookAuthor() { return b_author; }
bool
getBookStatus() { return b_isIssued; }
void issueBook() {
b_isIssued = true; }
void returnBook()
{ b_isIssued = false; }
};
class l_Member {
int l_memberId;
string l_name;
public:
l_Member(int id,
string n) : l_memberId(id), l_name(n) {}
int getId() {
return l_memberId; }
string getName() {
return l_name; }
};
class LibraryMgt {
vector<Book>
book1;
vector<l_Member> member1;
public:
void addBook(Book
b) { book1.push_back(b); }
void
addMember(l_Member m) { member1.push_back(m); }
void showBooks() {
for (auto
&b : book1) {
cout
<< b.getBookId() << " - " << b.getBookTitle()
<< " by " << b.getBookAuthor()
<< (b.getBookStatus() ? " [Issued]" : "
[Available]") << endl;
}
}
void issueBook(int
bookId) {
for (auto
&b : book1) {
if
(b.getBookId() == bookId && !b.getBookStatus()) {
b.issueBook();
cout
<< "Book is issued successfully!" << endl;
return;
}
}
cout <<
"Book is not available!" << endl;
}
void
returnBook(int bookId) {
for (auto
&b : book1) {
if
(b.getBookId() == bookId && b.getBookStatus()) {
b.returnBook();
cout
<< "Book is returned successfully!" << endl;
return;
}
}
cout <<
"Invalid return request!" << endl;
}
};
int main() {
LibraryMgt li_mt;
li_mt.addBook(Book(1, "Let us c++", "yaswant
kanitker"));
li_mt.addBook(Book(2, "Object oriented programming in C++",
"E.BalaGurusamy"));
li_mt.addMember(l_Member(101, "Rajeeva"));
cout <<
"Available Books:" << endl;
li_mt.showBooks();
li_mt.issueBook(1);
li_mt.showBooks();
li_mt.returnBook(1);
li_mt.showBooks();
return 0;
}
Output:
Available Books:
1 - Let us c++ by yaswant kanitker [Available]
2 - Object oriented programming in C++ by E.BalaGurusamy
[Available]
Book is issued successfully!
1 - Let us c++ by yaswant kanitker [Issued]
2 - Object oriented programming in C++ by E.BalaGurusamy
[Available]
Book is returned successfully!
1 - Let us c++ by yaswant kanitker [Available]
2 - Object oriented programming in C++ by E.BalaGurusamy
[Available]
That’s all. The C++ program to create library management was
done successfully. Keep coding!!!!
Comments
Post a Comment