-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrary.cpp
More file actions
80 lines (72 loc) · 1.54 KB
/
Library.cpp
File metadata and controls
80 lines (72 loc) · 1.54 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
#include "Library.h"
#include <iostream>
using namespace std;
bool Library::add(Item *item){
if(find(items.begin(),items.end(),item)==items.end()){
items.push_back(item);
return true;
}
else{
return false;
}
}
bool Library::add(Borrower *borrower){
if(find(borrowers.begin(),borrowers.end(),borrower)==borrowers.end()){
borrowers.push_back(borrower);
return true;
}
else{
return false;
}
}
void Library::listBorrowers() const{
for(int i=0; i<borrowers.size(); i++){
borrowers[i]->print();
cout<<endl;
cout<<"Borrowed Items: "<<endl;
borrowers[i]->listItems();
cout<<endl;
}
}
void Library::listItems() const{
for(int i=0; i<items.size(); i++){
items[i]->print();
cout<<endl;
}
}
Item* Library::findItem(int itemID){
for(int i=0; i<items.size(); i++){
if(items[i]->getID()==itemID){
return items[i];
}
}
return NULL;
}
Borrower* Library::findBorrower(string name){
for(int i=0; i<borrowers.size(); i++){
if(borrowers[i]->getName()==name){
return borrowers[i];
}
}
return NULL;
}
bool Library::acceptBorrow(string borrowerName, int itemID){
Item *item;
Borrower *borrower;
if(((item=findItem(itemID))!=NULL)&&((borrower=findBorrower(borrowerName))!=NULL)){
if(item->isAvailable()){
item->BorrowedBy(borrower);
borrower->borrowItem(item);
return true;
}
}
return false;
}
Library::~Library(){
for(int i=0; i<borrowers.size(); i++){
delete borrowers[i];
}
for(int i=0; i<items.size(); i++){
delete items[i];
}
}