-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomer.cpp
More file actions
86 lines (72 loc) · 2.31 KB
/
customer.cpp
File metadata and controls
86 lines (72 loc) · 2.31 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
#include <iostream>
#include <string>
#include <sstream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <ostream>
#include "customer.h"
Customer::Customer(string name, string surname, unsigned int cardId, double money) : Person(name, surname, cardId) {
this->money = money;
}
string Customer::to_string() const {
stringstream ss;
ss << "Customer\nname:" << name << "\nsurname: " << surname << "\ncardId: " << cardId << "\nmoney: " << money
<< " zl" << endl << preferences_to_string() << endl << basket << endl << ordered_books << endl;
return ss.str();
}
Customer &Customer::operator=(const Customer &c) {
if (this != &c) {
name = c.name;
surname = c.surname;
cardId = c.cardId;
money = c.money;
basket = c.basket;
ordered_books = c.ordered_books;
preferences = c.preferences;
}
return *this;
}
bool operator==(const Customer &c1, const Customer &c2) {
return ((c1.name == c2.name) && (c1.surname == c2.surname) && (c1.cardId == c2.cardId) && (c1.money == c2.money));
}
bool operator!=(const Customer &c1, const Customer &c2) {
return ((c1.name != c2.name) || (c1.surname != c2.surname) || (c1.cardId != c2.cardId) || (c1.money != c2.money));
}
ostream &operator<<(ostream &os, const Customer &c) {
os << c.to_string();
return os;
}
void Customer::add_to_basket(Book &book) {
basket.add_book(book);
}
void Customer::remove_from_basket(int book_id) {
basket.delete_book(book_id);
}
void Customer::add_to_ordered_books(Book &book) {
ordered_books.add_book(book);
}
void Customer::remove_from_ordered_books(int book_id) {
ordered_books.delete_book(book_id);
}
void Customer::add_preference(string preference) {
preferences.push_back(preference);
}
bool Customer::remove_preference(string preference) {
vector<string>::iterator it = find(preferences.begin(), preferences.end(), preference);
if (it == preferences.end()) {
cout << "This preference does not exist" << endl;
return false;
} else {
preferences.erase(it);
return true;
}
}
string Customer::preferences_to_string() const {
stringstream ss;
ss << "Preferences: " << endl;
for (int i = 0; i < preferences.size(); i++) {
ss << preferences[i] << endl;
}
return ss.str();
}