Repository navigation
Expand file tree
/
Copy pathLoan.cpp
More file actions
99 lines (89 loc) · 4.15 KB
/
Copy pathLoan.cpp
File metadata and controls
99 lines (89 loc) · 4.15 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
#include "Loan.h"
#include "Book.h"
#include "User.h"
Loan::Loan(Member* member, Book* book):borrower(member), borrowed_book(book), loan_status(false){}
//Getters
Member* Loan::getBorrower() { return borrower; }
Book* Loan::getBorrowedBook() { return borrowed_book; }
bool Loan::getStatus() { return loan_status; }
Date Loan::getBorrowDate() { return borrowing_date; }
Date Loan::getDueDate() { return due_date;}
//Setters
void Loan::set_status(bool status) { loan_status = status; }
void Loan::set_borrowingDate() {borrowing_date.getCurrentData();
}
void Loan::set_dueDate(){ // sets due date based on the type of the member using dynamic_cast as each member has a max number of borrowing days
if(dynamic_cast<Student*>(borrower)){
due_date = due_date.addDate(borrowing_date, 7);
}
if(dynamic_cast<Faculty*>(borrower)){
due_date = due_date.addDate(borrowing_date, 10);
}
if(dynamic_cast<Staff*>(borrower)){
due_date = due_date.addDate(borrowing_date, 5);
}
due_date.stringDate = std::to_string(due_date.day)+"-"+std::to_string(due_date.month)+"-"+std::to_string(due_date.year);
}
void Loan::set_borrowingDate(const string& dateInString) { // extract the date in the string and assign it to the borrowing date day, month, year
// format of the string: 25-4-2024
string buffer = "";
int dashCount = 0;
// Loop through each character in the string
for (size_t i = 0; i <= dateInString.size(); i++) {
// Check for dash or end of string
if (i == dateInString.size() || dateInString[i] == '-') {
if (dashCount == 0) {
borrowing_date.day = stoi(buffer); // First part is the day
} else if (dashCount == 1) {
borrowing_date.month = stoi(buffer); // Second part is the month
} else if (dashCount == 2) {
borrowing_date.year = stoi(buffer); // Third part is the year
}
buffer = ""; // Reset buffer for next number
dashCount++; // Increment dash count to move to the next date component
} else {
buffer += dateInString[i]; // Accumulate digits in buffer
}
}
borrowing_date.stringDate = std::to_string(borrowing_date.day)+"-"+std::to_string(borrowing_date.month)+"-"+std::to_string(borrowing_date.year);
}
void Loan::set_dueDate(const string& dateInString) { // extract the date in the string and assign it to the borrowing date day, month, year
// format of the string: 25-4-2024
string buffer = "";
int dashCount = 0;
// Loop through each character in the string
for (size_t i = 0; i <= dateInString.size(); i++) {
// Check for dash or end of string
if (i == dateInString.size() || dateInString[i] == '-') {
if (dashCount == 0) {
due_date.day = stoi(buffer); // First part is the day
} else if (dashCount == 1) {
due_date.month = stoi(buffer); // Second part is the month
} else if (dashCount == 2) {
due_date.year = stoi(buffer); // Third part is the year
}
buffer = ""; // Reset buffer for next number
dashCount++; // Increment dash count to move to the next date component
} else {
buffer += dateInString[i]; // Accumulate digits in buffer
}
}
due_date.stringDate = std::to_string(due_date.day)+"-"+std::to_string(due_date.month)+"-"+std::to_string(due_date.year);
}
//Methods
void Loan::generateReport(){
cout << "-------Loan Report-------" << endl;
cout <<"Member Name: "<<borrower->getName()<<endl
<<"Borrowed Book: "<<borrowed_book->getTitle()<<endl
<<"Borrowing Date: "<<borrowing_date.day<<"-"<<borrowing_date.month<<"-"<<borrowing_date.year<<endl
<<"Due Date: "<<due_date.day<<"-"<<due_date.month<<"-"<<due_date.year<<endl;
if(Student* ptr = dynamic_cast<Student*>(borrower)){
cout<<"Member Role: "<<"student"<<endl;
}
else if(Faculty* ptr = dynamic_cast<Faculty*>(borrower)){
cout<<"Member Role: "<<"faculty"<<endl;
}
else if(Staff* ptr = dynamic_cast<Staff*>(borrower)){
cout<<"Member Role: "<<"staff"<<endl;
}
}