This repository was archived by the owner on Dec 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.cpp
More file actions
98 lines (92 loc) · 2.67 KB
/
Book.cpp
File metadata and controls
98 lines (92 loc) · 2.67 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
#ifndef BOOK_CPP
#define BOOK_CPP
#include "Time.h"
#include "Book.h"
//Precondition: vector is at least 4
//If vector size is 4
//Book was added from the command line
//Otherwise book added from File
Book::Book(vector<string> vect){
if (vect.size()==4){
title = vect[0];
author = vect[1];
genre = vect[2];
id = stoi(vect[3]);
popScore = 0;
}
else{
id = stoi(vect[0]);
title = vect[1];
author = vect[2];
genre = vect[3];
popScore = stoi(vect[4]);
}
//Upon creation all User dependent info
//is initialized
available = true;
dueDate = -1;
borrowID = -1;
}
//Prints single book with all of its information
//Prints on many lines
void Book::PrintBook() const{
cout << "Title: \"" << getTitle() << "\"" << endl;
cout << "Author: " << getAuthor() << endl;
cout << "BookID#: " << getID() << endl;
cout << "Genre: " << getGenre() << endl;
cout << "Popularity Score: " << getScore() << endl;
if (getAvailability()){
cout << "Available" << endl;
}
else{
cout << "Borrower AccountID#: " << getAccountID() << endl;
cout << "Due Date: " << dueDate << endl;
cout << "Times renewed: " << numTimeRenewed << endl;
if (dueDate < Time::getTime()){
cout << "OVERDUE" << endl;
}
}
}
//Prints the Books details indented and each
//detail gets its own line
void Book::PrintBookFromUser() const{
cout << "\tTitle: \"" << getTitle() << "\"" << endl;
cout << "\tAuthor: " << getAuthor() << endl;
cout << "\tBookID#: " << getID() << endl;
cout << "\tGenre: " << getGenre() << endl;
cout << "\tPopularity Score: " << getScore() << endl;
cout << "\tDue Date: " << getDueDate() << endl;
cout << "\tTimes Renewed: " << getRenewCount() << endl;
}
//Prints one book per line
//Allowing for ALL books to be printed in
//a relatively short window
void Book::PrintBookFromBrowse() const{
cout << "\"" << title << "\" by " << author << " (BookID# " << id << " [" << genre << "]. ";
if (available == true){
cout << "AVAILABLE.\n";
}
else{
cout << "CHECKED OUT (AccountID# " << borrowID << ").\n";
}
}
//Vector contains at least 4 pieces of information
//Order is guaranteed to be: borrowID, bookID, dueDate, numTimeRenewed
//Sets the different variables accordingly when a book is borrowed
void Book::changeBookStatus(vector<int> bookInfo){
borrowID = bookInfo[0];
dueDate = bookInfo[2];
numTimeRenewed = bookInfo[3];
available = false;
}
//Resets the status of the book
//Most important is AVAILABLE
//The rest are irrelevant while AVAILABLE
//and will be changed when a User checkouts the book
void Book::returnBook(){
borrowID = -1;
dueDate = -1;
numTimeRenewed = 0;
available = true;
}
#endif