-
Notifications
You must be signed in to change notification settings - Fork 5
/
Customer.cpp
237 lines (203 loc) · 4.66 KB
/
Customer.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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#include "Customer.h"
#include <iostream>
#include "Order.h"
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
class Order;
Customer::Customer() {
username = "";
password = "";
firstname = "";
lastname = "";
isEmployee = false;
address = "";
city = "";
zip = 0;
email = "";
r = NULL;
}
Customer::Customer(string username, string password, string firstName,
string lastName, bool isEmployee, string address, string city,
unsigned zip, string email) {
this->username = username;
this->password = password;
this->firstname = firstName;
this->lastname = lastName;
this->isEmployee = isEmployee;
this->address = address;
this->city = city;
this->zip = zip;
this->email = email;
r = NULL;
}
string Customer::getAddress() const {
return address;
}
string Customer::getCity() const {
return city;
}
unsigned Customer::getZip() const {
return zip;
}
string Customer::getEmail() const {
return email;
}
void Customer::setAddress(string address) {
this->address = address;
}
void Customer::setCity(string city) {
this->city = city;
}
void Customer::setZip(unsigned zip) {
this->zip = zip;
}
void Customer::setEmail(string email) {
this->email = email;
}
string Customer::getOrder() const {
stringstream out;
orders.displayNumberedList(out);
return out.str();
}
/*
void Customer::insertOrder() { //storing list of past order (Shipped);
if (r->isPlaced()) {
orders.insertStop(*r);
}
Order r;
r.addLaptop(p);
orders.insertStop(r);
}
*/
bool Customer::operator==(const Customer& customer) {
return (username == customer.username && password == customer.password);
}
bool Customer::operator<(const Customer& customer) {
if (firstname < customer.firstname)
return true;
else if (firstname == customer.firstname) {
if (lastname < customer.lastname)
return true;
else if (lastname == customer.lastname) {
if (username < customer.username)
return true;
else if (username == customer.username) {
if (password < customer.password)
return true;
else
return false;
} else
return false;
} else
return false;
} else
return false;
}
bool Customer::operator>(const Customer& customer) {
if (firstname > customer.firstname)
return true;
else if (firstname == customer.firstname) {
if (lastname > customer.lastname)
return true;
else if (lastname == customer.lastname) {
if (username > customer.username)
return true;
else if (username == customer.username) {
if (password > customer.password)
return true;
else
return false;
} else
return false;
} else
return false;
} else
return false;
}
void Customer::read(ifstream& in) {
string temp;
bool temp1;
unsigned temp2;
in >> temp;
username = temp;
in >> temp;
password = temp;
in >> temp;
firstname = temp;
in >> temp;
lastname = temp;
in >> temp1;
isEmployee = temp1;
getline(in, temp);
address = temp;
in >> temp;
city = temp;
in >> temp2;
zip = temp2;
in >> temp;
email = temp;
while (in.peek() == '\n')
in.get();
}
void Customer::write(ostream& out) {
out << username << '\n';
out << password << '\n';
out << firstname << '\n';
out << lastname << '\n';
out << isEmployee << '\n';
out << address << '\n';
out << city << '\n';
out << zip << '\n';
out << email << '\n';
orders.startIterator();
while (!orders.offEnd()) {
orders.getIterator()->save(out);
orders.moveIterNext();
}
out << endl;
}
ostream& operator<<(ostream& out, const Customer& customer) {
stringstream os;
customer.orders.displayNumberedList(os);
out << customer.getFirstname() << "," << customer.getLastname() << ","
<< customer.getAddress() << "," << customer.getCity() << ","
<< customer.getEmail() << "," << customer.getZip() << '\n';
out << os.str();
return out;
}
string Customer::toString() { //return a string with customer's data.
stringstream ss;
ss << firstname << "," << lastname << "," << address << "," << city << ","
<< zip << "," << email;
return ss.str();
}
string Customer::displayCustomer() {
stringstream out;
out << "\nFirst name: " << firstname << "\nLast name: " << lastname
<< "\nAddress: " << address << endl;
return out.str();
}
void Customer::activeOrder(Order *p) {
r = p; //point activeORder to the order passed in.
}
string Customer::printActive() {
stringstream out;
out << "Active Order: " << r->printDetailed();
return out.str();
}
void Customer::addToProduct(Product* p) {
r->addLaptop(p);
}
void Customer::removeProduct(int index) {
assert(!r->isPlaced());
r->removeLaptop(index);
}
void Customer::placeOrder() {
orders.insertStop(r); //add order to list
}
void Customer::insertOrder(Order* o){
orders.insertStop(o); //add order to list
}