-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary_management.cpp
More file actions
121 lines (107 loc) · 3.08 KB
/
library_management.cpp
File metadata and controls
121 lines (107 loc) · 3.08 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <iostream>
using namespace std;
class Book {
public:
int id, price;
string title, author;
bool available = true;
void add() {
cout << "Enter ID: ";
cin >> id;
cout << "Enter Title: ";
cin>>title;
cout<<"\n";
cout << "Enter Author: ";
cin>>author;
cout<<"\n";
cout << "Price: ";
cin >> price;
}
void display() {
cout << "\nID: " << id << "\n";
cout << "Title: " << title << "\n";
cout << "Author: " << author << "\n";
cout << "Price: " << price << "\n";
cout << "Available: " << (available ? "Yes" : "No") << "\n";
}
void issue() {
if (available) {
available = false;
cout << "Book issued!\n";
} else {
cout << "Already issued!\n";
}
}
bool searchById(int searchId) {
return id == searchId;
}
};
int main() {
Book books[10];
int count = 0, choice, id;
bool found;
while (true) {
cout << "\n1. Add Book\n";
cout << "2. Display All Books\n";
cout << "3. Issue Book\n";
cout << "4. Search Book by ID\n";
cout << "5. Exit\n";
cout << "Choice: ";
cin >> choice;
switch (choice) {
case 1:
if (count < 10) {
books[count++].add();
} else {
cout << "Library is full!\n";
}
break;
case 2:
if (count == 0) {
cout << "No books available.\n";
} else {
for (int i = 0; i < count; i++) {
books[i].display();
}
}
break;
case 3:
cout << "Enter ID: ";
cin >> id;
found = false;
for (int i = 0; i < count; i++) {
if (books[i].searchById(id)) {
books[i].issue();
found = true;
break;
}
}
if (!found) {
cout << "Book not found!\n";
}
break;
case 4:
cout << "Enter ID: ";
cin >> id;
found = false;
for (int i = 0; i < count; i++) {
if (books[i].searchById(id)) {
cout << "\nBook Found:\n";
books[i].display();
found = true;
break;
}
}
if (!found) {
cout << "Book not found!\n";
}
break;
case 5:
cout << "Exiting...\n";
return 0;
default:
cout << "Invalid choice!\n";
}
}
return 0;
}