-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMember.cpp
More file actions
118 lines (95 loc) · 2.86 KB
/
Member.cpp
File metadata and controls
118 lines (95 loc) · 2.86 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
//
// Created by tarek on 4/5/2024.
//
#include "User.h"
using namespace std;
// Use nlohmann's json library
using json = nlohmann::json;
// Static list of all members
vector<Member> Member::members={};
// Default constructor
Member::Member():Name(""),Type(""),ID(0),Fines(0) {}
// Constructor with name, ID, and type. Fines are set to 0.
Member::Member(const Custom_String_Class& N,int I,const Custom_String_Class& T): Name(N),ID(I),Type(T){
Fines=0;
}
// Getter for name
Custom_String_Class Member::getName() const{
return Name;
}
// Getter for list of members
vector<Member>& Member::getMembers(){
return members;
}
// Getter for ID
int Member::getID() const {
return ID;
}
// Getter for type
Custom_String_Class Member::getType() const{
return Type;
}
// Getter for fines
int Member::getFines() const{
return Fines;
}
// Getter for checked out books
vector<Loan>& Member::getCheckedOutBooks(){
return checkedOutBooks;
}
// Setter for name
void Member::setName(const Custom_String_Class& name) {
Name = name;
}
// Setter for ID
void Member::setID(int id) {
ID = id;
}
// Setter for type
void Member::setType(const Custom_String_Class& type) {
Type = type;
}
// Setter for fines
void Member::setFines(int f){
Fines=f;
}
// Function to calculate total fines
int Member::calculateTotalFines (){
Fines=0;
for(auto it: checkedOutBooks){//iterate over the list of checkedout books for a member and calculate their total fines
Fines+=it.calculateFines();
}
return Fines;
}
// Function to update total fines
void Member::updateTotalFines (){
Fines=calculateTotalFines();
}
// Function to display member details
void Member::display(){
std::cout << "Name: " << Name << std::endl;
std::cout << "ID: " << ID << std::endl;
std::cout << "Type: " << Type << std::endl;
std::cout << "Number of Checked Out Books: " << checkedOutBooks.size() << std::endl;
std::cout << "Overdue Fines: " << calculateTotalFines() << std::endl;
cout<< "--------------------\n";
}
// Function to display loaned books
void Member::displayloaned() const{
int j=1;
cout<< "--------------------\n";
for (int i = 0; i < this->checkedOutBooks.size(); ++i) {
cout<<j++<<" ";
std::cout << "you have borrowed a book with ID " << this->checkedOutBooks[i].getBookID() << " \n";
}
cout<< "--------------------\n";
}
// Function to request to borrow a book
void Member::requestBorrow(Book& book) {
Loan ln(ID, book.getISBN());//create a new loan
Librarian::addBorrowRequest(ln);//send loan request to the library
}
// Function to return a book
void Member::returnBook(Book book) {
Librarian::returnBook(*this, book);//send return request to library which will be processed automatically
}