-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItemsInLibrary.cpp
More file actions
104 lines (95 loc) · 3.19 KB
/
Copy pathItemsInLibrary.cpp
File metadata and controls
104 lines (95 loc) · 3.19 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
#include "ItemsInLibrary.h"
#include <iostream>
using namespace std;
ItemsInLibrary::ItemsInLibrary(int itemUniqueID,string itemTitle, string itemAuthor, string itemPublicationYear,
bool itemAvailability, string itemType){
this->itemUniqueID = itemUniqueID;
this->itemTitle = itemTitle;
this->itemAuthor = itemAuthor;
this->itemPublicationYear = itemPublicationYear;
this->itemAvailability = itemAvailability;
this->itemType = itemType;
}
//Accessors - Setters
void ItemsInLibrary::setItemUniqueID(int newID) {
itemUniqueID = newID;
}
void ItemsInLibrary::setItemTitle(const string& newTitle) {
itemTitle = newTitle;
}
void ItemsInLibrary::setItemAuthor(const string& newAuthor) {
itemAuthor = newAuthor;
}
void ItemsInLibrary::setItemPublicationYear(const string& newPublicationYear) {
itemPublicationYear = newPublicationYear;
}
void ItemsInLibrary::setItemType(const string& newType) {
itemType = newType;
}
//Mutators - Getters
int ItemsInLibrary::getItemUniqueID()const{
return itemUniqueID;
}
string ItemsInLibrary::getItemTitle()const{
return itemTitle;
}
string ItemsInLibrary::getItemAuthor()const{
return itemAuthor;
}
string ItemsInLibrary::getItemPublicationYear()const{
return itemPublicationYear;
}
string ItemsInLibrary::getItemType() const {
return itemType;
}
bool ItemsInLibrary::isCheckedOut(){
return !itemAvailability;
}
bool ItemsInLibrary::searchItem(const string& searchQuery) const{
return(itemTitle == searchQuery || itemAuthor == searchQuery || itemType == searchQuery);
}
void ItemsInLibrary::checkOut(){
if (itemReturnDueDate ==0){
itemReturnDueDate = 5;
itemAvailability = true;
}else{
itemAvailability = false;
}
}
void ItemsInLibrary::returnItem(){
if (itemReturnDueDate != 0)
itemAvailability = false;
}
// Sorting algorithm (Bubble Sort) to sort items based on itemUniqueID
void ItemsInLibrary::bubbleSort(ItemsInLibrary items[], int size) {
for (int i = 0; i < size - 1; ++i) {
for (int j = 0; j < size - i - 1; ++j) {
if (items[j].getItemUniqueID() > items[j + 1].getItemUniqueID()) {
// Swap items
ItemsInLibrary temp = items[j];
items[j] = items[j + 1];
items[j + 1] = temp;
}
}
}
}
// Searching algorithm (Binary Search) to find an item by itemUniqueID
int ItemsInLibrary::binarySearch(ItemsInLibrary items[], int left, int right, int targetID) {
if (right >= left) {
int mid = left + (right - left) / 2;
if (items[mid].getItemUniqueID() == targetID)
return mid;
if (items[mid].getItemUniqueID() > targetID)
return binarySearch(items, left, mid - 1, targetID);
return binarySearch(items, mid + 1, right, targetID);
}
// Item not found
return -1;
}
void ItemsInLibrary::displayInfo(){
cout << "Item ID: " << itemUniqueID << endl;
cout << "Title: " << itemTitle << endl;
cout << "Author: " << itemAuthor << endl;
cout << "Publication Year: " << itemPublicationYear << endl;
cout << "Availability: " << (itemAvailability ? "Available" : "Checked Out") << endl;
}