-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrary.cpp
More file actions
47 lines (40 loc) · 1013 Bytes
/
Library.cpp
File metadata and controls
47 lines (40 loc) · 1013 Bytes
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
//include headers and libraries
#include <iostream>
#include "Library.h"
Library::Library() {
for (int i = 0; i < 10; i++) {
books[i] = "";
}
}
bool Library::addBook(string bookName) {
for (int i = 0; i < 10; i++) {
if (books[i] == bookName) {
return false; // Book already exists
}
}
for (int i = 0; i < 10; i++) {
if (books[i] == "") {
books[i] = bookName;
return true; // Book added successfully
}
}
return false; // Library is full
}
bool Library::removeBook(string bookName) {
for (int i = 0; i < 10; i++) {
if (books[i] == bookName) {
books[i] = "";
return true; // Book removed successfully
}
}
return false; // Book not found
}
void Library::print() {
cout << "Library contents:" << endl;
for (int i = 0; i < 10; i++) {
if (books[i] != "") {
cout << books[i] << endl;
}
}
}
//implement class functions