Repository navigation
Expand file tree
/
Copy pathUser.h
More file actions
217 lines (156 loc) · 7.41 KB
/
Copy pathUser.h
File metadata and controls
217 lines (156 loc) · 7.41 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#ifndef LIBRARY_SYSTEM_PROJECT_USER_H
#define LIBRARY_SYSTEM_PROJECT_USER_H
#include <vector>
#include "Str.h"
#include "Book.h"
using namespace std;
using namespace OurBook;
class Librarian;
class Member;
class Loan;
/*****************************************/
class User { /* An abstract class represents the general library user */
protected: /* login attributes for user */
str name;
str id;
str password;
public:
/***** constructors & destructors *****/
User() : name(""), password(""), id(""){}
User(const str &n, const str &i, const str &pass) : name(n), id(i), password(pass){}
virtual ~User(){}
/***** setters and getters *****/
str getName() const;
str getId() const;
str getPassword() const;
void setName(str s);
void setPassword(str pass);
/******** overriden methods **********/
virtual void displayInfo() const = 0; /* pure virtual function displays user info based on its role */
virtual void setId(str i) = 0; /* pure virtual function sets the user id with the correct prefix based on its role */
/********* User methods *********/
/* search by title and returns the book pointer */
Book* searchForBook_title(const vector<Book*> &, const str &);
/* search by ISBN and returns the book pointer */
Book* searchForBook_isbn(const vector<Book*> &, const str &);
/* search by author and returns vector of book pointers that has the wanted author */
vector<Book *> searchForBook_author(const vector<Book*> &, const str &);
/* search by author and returns vector of book pointers that has the wanted genre */
vector<Book *> searchForBook_genre(const vector<Book*> &, const str &);
/* search by author and returns vector of book pointers that has the wanted publication year */
vector<Book *> searchForBook_publicationyear(const vector<Book*> &, const short &);
};
/****************************************************************************************/
class Librarian : public User { /* A class which represents the librarian */
private:
void proceedToCheckOut(Loan* &);
public:
/************ Constructors ***********/
Librarian();
Librarian(str, str, str);
~Librarian() override{}
/********** overriden methods **********/
void displayInfo() const override; /* displays info of librarian user */
void setId(str i) override; /* sets User id with prefix lib */
/************** Operations on books **************/
void viewBooks(vector<Book*>&) const; /* views library books */
void addBook(vector<Book*> &); /* adds new book to library books */
void removeBook(vector<Book*> &, Book* &book); /* removes book from library books */
/* methods to update books information */
void updateBookTitle(Book* &);
void updateBookAuthor(Book* &);
void updateBookISBN(Book* &);
void updatePublicationYear(Book* &);
void updateBookGenre(Book* &);
void updateBookQuantity(Book* &);
/******************* Opeerations on Members *****************/
void addMember(vector<User *> &,int); /* adds new member to the library users */
void removeMember(vector<User *> &, Member*); /* removes member from library users */
/* methods to update member data */
void updateMemberName(Member*);
void updateMemberId(Member*);
/* method to search for member in library users based on id */
Member* Searchformember(vector<User*>,str);
User* Searchforuser(vector<User*>,str);
/******************** Operations on Loans ****************/
/* function to approve or decline loan requests made by members */
void processLoanRequest(Loan* &, bool);
/* function to check for any delay in loans and adds overdue fines based on the delayed time*/
void CheckForOverdues(Loan* &);
/* functions to print all loans and the pending loans */
void printAllLoans(vector<Loan*>) const;
void printPendingLoans(vector<Loan*>) const;
};
/****************************************************************************************/
class Member : public User { /* An abstract class represents the borrowing member of the library */
/* Inherits the login information from the class User */
protected:
/****** attributes ******/
vector<Book*> checked_out_books; /* books borrowed by member */
float overdue_fines = 0; /* fines applied to each member for late loans */
/****** private methods ******/
public:
/****** public methods ******/
Member();
Member(str, str, str);
//~Member() override{}
/* setters and getters */
void setCheckedOutBooks(vector<Book*>&);
void addToCheckedOutBooks(Book* &);
void removeFromCheckedOutBooks(Book* &);
void setOverdueFines(float&);
vector<Book*> getCheckedOutBooks() const;
float getOverdueFines() const;
int getCheckedOutBooksSize() const;
/********* Member Methods ********/
/********** Loan related methods ********/
/* a virtual function to request book loan and set loan constraints based on the member role */
virtual Loan* requestLoan(Book* &, int) = 0;
/* a virtual function to return the requested book and set the overdue fines based on the member loans */
virtual void returnBorrowedBook(Book* &, vector<Loan*> &) = 0;
};
/******************************************************************************************/
class Student : public Member { /* a class represents the borrowing student user */
public: /* inherits from Member class */
/* constructors and destructors */
Student();
Student(str, str, str);
Student(Member*);
~Student() override{}
void setId(str i) override; /* sets User id with prefix stu */
void displayInfo() const override; /* displays info of librarian user */
/* polymorphic function to request loan with student specific constraints */
Loan* requestLoan(Book* &, int) override;
/* polymorphic function to return borrowed book and set overdue fines with value specific to student member */
void returnBorrowedBook(Book* &, vector<Loan*> &) override;
};
class Faculty : public Member {
public:
/* constructors and destructors */
Faculty();
Faculty(str, str, str);
Faculty(Member*);
~Faculty() override{}
void setId(str i) override; /* sets User id with prefix fac */
void displayInfo() const override; /* displays info of librarian user */
/* polymorphic function to request loan with faculty member specific constraints */
Loan* requestLoan(Book* &, int) override;
/* polymorphic function to return borrowed book and set overdue fines with value specific to faculty member */
void returnBorrowedBook(Book* &, vector<Loan*> &) override;
};
class Staff : public Member {
public:
/* constructors and destructors */
Staff();
Staff(str, str, str);
Staff(Member*);
~Staff() override{}
void setId(str i) override; /* sets User id with prefix sta */
void displayInfo() const override; /* displays info of staff user */
/* polymorphic function to request loan with faculty member specific constraints */
Loan* requestLoan(Book* &, int) override;
/* polymorphic function to return borrowed book and set overdue fines with value specific to faculty member */
void returnBorrowedBook(Book* &, vector<Loan*> &) override;
};
/****************************************************************************************/
#endif //LIBRARY_SYSTEM_PROJECT_USER_H