-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrary Management System
More file actions
72 lines (59 loc) · 1.74 KB
/
Copy pathLibrary Management System
File metadata and controls
72 lines (59 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Book {
public:
string title;
string author;
bool isIssued;
Book(string t, string a) : title(t), author(a), isIssued(false) {}
};
class Library {
private:
vector<Book> books;
public:
void addBook(const string& title, const string& author) {
books.push_back(Book(title, author));
cout << "Book added: " << title << endl;
}
void issueBook(const string& title) {
for (auto& book : books) {
if (book.title == title && !book.isIssued) {
book.isIssued = true;
cout << "Book issued: " << title << endl;
return;
}
}
cout << "Book not available or already issued!" << endl;
}
void returnBook(const string& title) {
for (auto& book : books) {
if (book.title == title && book.isIssued) {
book.isIssued = false;
cout << "Book returned: " << title << endl;
return;
}
}
cout << "This book was not issued or doesn't exist!" << endl;
}
void displayBooks() {
cout << "Available Books in Library:\n";
for (const auto& book : books) {
cout << book.title << " by " << book.author;
if (book.isIssued) cout << " (Issued)";
cout << endl;
}
}
};
int main() {
Library lib;
lib.addBook("C++ Programming", "Bjarne Stroustrup");
lib.addBook("The Catcher in the Rye", "J.D. Salinger");
lib.addBook("To Kill a Mockingbird", "Harper Lee");
lib.displayBooks();
lib.issueBook("C++ Programming");
lib.returnBook("C++ Programming");
lib.displayBooks();
return 0;
}