-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibraryManagement.cpp
More file actions
84 lines (72 loc) · 2.08 KB
/
LibraryManagement.cpp
File metadata and controls
84 lines (72 loc) · 2.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
#include <iostream>
#include <string>
using namespace std;
struct Book {
int id;
string title;
string author;
};
Book library[50];
int countBooks = 0;
void addBook() {
if (countBooks < 50) {
cout << "Enter Book ID: ";
cin >> library[countBooks].id;
cin.ignore();
cout << "Enter Book Title: ";
getline(cin, library[countBooks].title);
cout << "Enter Author Name: ";
getline(cin, library[countBooks].author);
countBooks++;
cout << "Book added successfully!\n\n";
} else {
cout << "Library is full!\n\n";
}
}
void displayBooks() {
if (countBooks == 0) {
cout << "No books in library.\n\n";
return;
}
cout << "\nBooks in Library:\n";
for (int i = 0; i < countBooks; i++) {
cout << "ID: " << library[i].id
<< " | Title: " << library[i].title
<< " | Author: " << library[i].author << endl;
}
cout << endl;
}
void searchBook() {
int id;
cout << "Enter Book ID to search: ";
cin >> id;
for (int i = 0; i < countBooks; i++) {
if (library[i].id == id) {
cout << "Book found!\n";
cout << "ID: " << library[i].id
<< " | Title: " << library[i].title
<< " | Author: " << library[i].author << endl << endl;
return;
}
}
cout << "Book not found!\n\n";
}
int main() {
int choice;
while (true) {
cout << "===== Library Management System =====\n";
cout << "1. Add Book\n";
cout << "2. Display All Books\n";
cout << "3. Search Book by ID\n";
cout << "4. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1: addBook(); break;
case 2: displayBooks(); break;
case 3: searchBook(); break;
case 4: cout << "Exiting... Goodbye!\n"; return 0;
default: cout << "Invalid choice! Try again.\n\n";
}
}
}