-
Notifications
You must be signed in to change notification settings - Fork 0
/
CashDesk.cpp
141 lines (118 loc) · 3.49 KB
/
CashDesk.cpp
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
//
// PROIekt - symulacja supermarketu
//
// Created by Ksawery Chodyniecki and Paweł Müller.
//
#include "CashDesk.hpp"
CashDesk::CashDesk(unsigned short argID, unsigned int cashIn) {
/// CashDesk object constructor
ID = argID;
isOpen = false;
cashAmount = cashIn;
assignee = nullptr;
itemsScaned = 0;
}
unsigned short CashDesk::getID() {
/// returns the ID of CashDesk object
return ID;
}
bool CashDesk::operator ==(unsigned short secondID) {
/// comparison operator overload comparing IDs of CashDesk object and a unsigned short
if (getID() == secondID)
return true;
else
return false;
}
bool CashDesk::operator !=(unsigned short secondID) {
/// comparison operator overload comparing ID of CashDesk object and a unsigned short
return !(getID() == secondID);
}
bool CashDesk::operator ==(CashDesk cash2) {
/// comparison operator overload comparing IDs of CashDesk objects
if (getID() == cash2.getID())
return true;
else
return false;
}
bool CashDesk::operator !=(CashDesk cash2) {
/// comparison operator overload comparing IDs of CashDesk objects
return !(getID() != cash2.getID());
}
void CashDesk::open(Employee* assigned) {
/// sets this CashDesk status to open
isOpen = true;
assigned -> setBusy();
assignee = assigned;
}
bool CashDesk::getState() {
/// return status of this CashDesk
return isOpen;
}
Employee* CashDesk::close() {
/// sets this CashDesk status to closed
isOpen = false;
assignee -> setFree();
return assignee;
}
unsigned int CashDesk::getCash() {
return cashAmount;
}
void CashDesk::addCash(unsigned int n) {
cashAmount += n;
}
void CashDesk::operator +=(unsigned int n) {
addCash(n);
}
void CashDesk::setCash(unsigned int n) {
cashAmount = n;
}
void CashDesk::operator =(unsigned int n) {
setCash(n);
}
void CashDesk::takeCash(unsigned int n) {
cashAmount -= n;
}
void CashDesk::operator -=(unsigned int n) {
takeCash(n);
}
Employee* CashDesk::assign(Employee* assigned) {
/// assigns an Employee to the cash register and returns the previously assigned Employee, if there was any
Employee* temp = assignee;
assignee = assigned;
assigned -> setBusy();
if (temp)
temp -> setFree();
return temp;
}
void CashDesk::push(Customer* shopper) {
/// assigns a Customer to the CashDesk queue (checking whether Customer is already in a queue will be done via methods and attributes of the Customer class)
customerQueue.push(shopper);
}
unsigned long CashDesk::size() {
/// returns the amount of Customers standind in queue of that Cash Register
return customerQueue.size();
}
Customer* CashDesk::pop() {
/// removes first Customer from the queue
Customer* result = customerQueue.front();
customerQueue.pop();
return result;
}
Customer* CashDesk::scan() {
/// basic functionality, scans through next items in the first's Customer's basket until it's fully scaned, only then it returns a pointer to Customer object instead of a nullptr
itemsScaned += (assignee->getScanSpeed());
if (customerQueue.front() -> getBasketSize() < itemsScaned) {
itemsScaned = 0;
return pop();
}
return nullptr;
}
unsigned int CashDesk::checkout(Customer *customer) {
unsigned int summedValue = 0;
for (auto productPair : customer -> getBasket()) {
Product* product = productPair.first;
summedValue += product -> getPrice() * product -> getQuantity();
}
this -> addCash(summedValue);
return summedValue;
}