-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomerList.cpp
109 lines (85 loc) · 2.06 KB
/
CustomerList.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
#include "CustomerList.h"
#include "linkedList.h"
using namespace std;
ostream& operator<<(ostream& osObject, const CustomerList& customerList)
{
nodeType<Customer>* current = customerList.first;
while (current != nullptr)
{
osObject << "**********************************************" << endl;
osObject << current->info;
current = current->link;
osObject << "**********************************************" << endl;
}
return osObject;
}
void CustomerList::AddCustomer(Customer& newCustomer)
{
bool found = false;
SearchCustomerByName(newCustomer.getCustomerName());
if (found)
cout << "Customer already in CustomerList." << endl;
else
{
this->insertLast(newCustomer);
}
}
bool CustomerList::SearchCustomerByName(string customerName) const
{
nodeType<Customer>* current;
bool found = false;
current = first;
while (current != nullptr && !found)
{
if (current->info.getCustomerName() == customerName)
found = true;
else
current = current->link;
}
return found;
}
Customer& CustomerList::getCustomerByName(string customerName) const
{
nodeType<Customer>* current;
bool found = false;
current = first;
while (current != nullptr && !found)
{
if (current->info.getCustomerName() == customerName)
found = true;
else
current = current->link;
}
return current->info;
}
void CustomerList::UpdateCustomer(Customer& newCustomer)
{
bool found = false;
nodeType<Customer>* current;
current = first;
while (current != nullptr && !found)
{
if (current->info.getCustomerName() == newCustomer.getCustomerName())
found = true;
else
current = current->link;
}
if (found)
{
current->info = newCustomer;
}
else
cout << "Customer not found." << endl;
}
void CustomerList::UpdateDataFile(ofstream& outFile)
{
nodeType<Customer>* current = first;
while (current != nullptr)
{
outFile << "%" << current->info.getCustomerName() << endl;
outFile << current->info.getAddress() << endl;
outFile << current->info.getEmail() << endl;
current->info.getOrders().UpdateDataFile(outFile);
current = current->link;
}
}