-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.cpp
More file actions
189 lines (185 loc) · 4.87 KB
/
Book.cpp
File metadata and controls
189 lines (185 loc) · 4.87 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
#ifndef BOOK_CPP
#define BOOK_CPP
#include <iostream>
#include <string>
#include "Book.h"
#include "Time.h"
using namespace std;
//constructor creates a book with given title, author, genre.
Book::Book(string title, string author, string genre)
{
Title=title;
Author=author;
Genre=genre;
TimeUntilReturn=Time::getTime()+15;
checkedOut=false;
PopularityScore=0;
Renewed=0;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//Constructor makes book given id, due date, and times renewed
Book::Book(int ID, int DueDate, int numRenew)
{
BookID=ID;
TimeUntilReturn=DueDate;
Renewed=numRenew;
PopularityScore=0;
checkedOut=false;
TimeUntilReturn=Time::getTime()+15;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//creates book given info stored in a vector(reading a file)
Book::Book(vector<string> Bookinfo)
{
BookID = atoi((Bookinfo[0]).c_str()); //stoi
Title = Bookinfo[1];
Author = Bookinfo[2];
Genre = Bookinfo[3];
PopularityScore = atoi((Bookinfo[4]).c_str());
TimeUntilReturn=Time::getTime()+15;
checkedOut=false;
Renewed=0;
BorrowerID=-1;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//Resets book information
void Book::refresh()
{
TimeUntilReturn=Time::getTime()+15;
checkedOut=false;
Renewed=0;
BorrowerID=-1;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//Prints short data of a book
void Book::PrintBookDataShort()
{
cout<<"\""<<Title<<"\" by "<< Author<<
" (BookID# "<<BookID<<") ["<<Genre<<"]. ";
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void Book::PrintStatus()
{
if (checkedOut)
{
cout<<"CHECKED OUT (AccountID# "<<BorrowerID<<")."<<endl;
}
else
{
cout<<"AVAILABLE. "<<endl;
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//Prints full data of a book
void Book::PrintBookDataFull()
{
cout<<"Title: \""<<Title<<"\""<<endl;
cout<<"Author: "<<Author<<endl;
cout<<"BookID#: "<< BookID<<endl;
cout<<"Genre: "<<Genre<<endl;
cout<<"Popularity Score: "<<PopularityScore<<endl;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//Prints indented data of a book
void Book::PrintBookDataFullIndent()
{
cout<<"\t"<<"Title: \""<<Title<<"\""<<endl;
cout<<"\t"<<"Author: "<<Author<<endl;
cout<<"\t"<<"BookID#: "<< BookID<<endl;
cout<<"\t"<<"Genre: "<<Genre<<endl;
cout<<"\t"<<"Popularity Score: "<<PopularityScore<<endl;
cout<<"\t"<<"Due Date: "<<TimeUntilReturn<<endl;
cout<<"\t"<<"Times renewed: "<<Renewed<<endl;
if (is_Overdue())
{
cout<<"\t"<<"OVERDUE"<<endl;
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//Returns true if a book is overdue
bool Book::is_Overdue()
{
return (TimeUntilReturn<Time::getTime());
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//Renews a book if it is not overdue or reached a max of 2 renews
void Book::renew()
{
//Adds 5 days for a max of two times to non overdue books
if(Renewed<2 and !is_Overdue())
{
TimeUntilReturn+=5;
Renewed++;
PrintBookDataFullIndent();
cout<<"\t"<<"Book successfully renewed."<<endl;
}
else
{
PrintBookDataFullIndent();
cout<<"\t"<<"Book already renewed twice"<<endl;
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//Returns a string of a book file format
string Book::outputBook()
{
string a=to_string(BookID)+"|"+Title+"|"+Author+"|"+Genre+"|"+to_string(PopularityScore);
return a;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//Returns a string of a checked out book in file format
string Book::outputCheckedoutBooks()
{
string a=to_string(BookID)+"|"+to_string(TimeUntilReturn)+"|"+to_string(Renewed)+"\n";
return a;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//Sets checkout status
void Book::setCheckOutStatus(bool checkout)
{
checkedOut=checkout;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//Sets bookID
void Book::setBookID(int num)
{
BookID=num;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//returns bookid
int Book::getBookID() const
{
return BookID;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//returns checkout status
bool Book::getCheckedOutStatus() const
{
return checkedOut;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//returns author
string Book::getAuthor() const
{
return Author;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//returns title
string Book::getTitle() const
{
return Title;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//returns popularity
int Book::getPopularity() const
{
return PopularityScore;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//returns genre
string Book::getGenre() const
{
return Genre;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#endif