-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomer.cpp
127 lines (113 loc) · 4.34 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
// ------------------------------------------------ Customer.cpp -------------------------------------------------------
// Jasdeep Brar, Cameron Ufland CSS343 C
// Creation Date: March 1, 2020
// Date of Last Modification: March 14, 2020
// --------------------------------------------------------------------------------------------------------------------
// This is the implementation file for the customer class.
// --------------------------------------------------------------------------------------------------------------------
//The requirements for this assignment were specified by Wooyoung Kim via class
// and canvas.
// --------------------------------------------------------------------------------------------------------------------
#include "Customer.h"
//default constructor
Customer::Customer()
{
this->firstName = "";
this->lastName = "";
this->customerID = 0;
}
//end default constructor
//constructor
Customer::Customer(int ID, string firstName, string lastName)
{
this->firstName = firstName;
this->lastName = lastName;
this->customerID = ID;
}
//end constructor
//destructor
Customer::~Customer()
{
for (int i = 0; i < transactions.size(); i++) {
delete transactions[i];
}
}
//end destructor
// -------------------------------- getCustomerID() --------------------------------
// Description
// getCustomerID(): returns an int that contains the ID number for a customer
// preconditions:valid customer object
// postconditions: int containing ID
// -----------------------------------------------------------------------------
int Customer::getCustomerID()
{
return this->customerID;
}
//end getCustomerID
// -------------------------------- addTransaction() --------------------------------
// Description
// addTransaction(): stores the transaction in the vector to all alter
// preconditions:valid transaction object
// postconditions: transaction added to transaction vector
// -----------------------------------------------------------------------------
void Customer::addTransaction(Transaction *t)
{
transactions.push_back(t);
}
//end addTransaction
// -------------------------------- showAllTransaction() --------------------------------
// Description
// showAllTransactions: displays all transactions store in the transactions vector
// preconditions:valid transaction vector
// postconditions:calls the transaction subclasses display function.
// -----------------------------------------------------------------------------
void Customer::showAllTransactions()
{
if (!this->transactions.empty())
{
for (int i = 0; i < this->transactions.size(); i++)
{
if (transactions[i]->getType() == 'R') {
transactions[i]->display();
}
else {
transactions[i]->display();
}
}
}
}
//end showAllTransactions
// -------------------------------- operator== --------------------------------
// Description
// operator== : compares whether two customer objects are equal
// preconditions:two valid customer objects
// postconditions: the equality of two customer objects has bee determined
// -----------------------------------------------------------------------------
bool Customer::operator==(const Customer& otherCustomer) const
{
return (this->customerID == otherCustomer.customerID);
}
//end operator==
// -------------------------------- operator!= --------------------------------
// Description
// operator== : compares whether two customer objects are not equal
// preconditions:two valid customer objects
// postconditions: the non-equality of the two objects has been assessed
// -----------------------------------------------------------------------------
bool Customer::operator!=(const Customer& otherCustomer) const
{
return !(this->customerID == otherCustomer.customerID);
}
//end operator !=
// -------------------------------- operator<< --------------------------------
// Description
// operator<< : outputs a formatted string with all relevant information about the customer object
// preconditions:valid output stream, valid customer object
// postconditions: formatted string appears in output
// -----------------------------------------------------------------------------
ostream& operator<<(ostream& output, Customer& otherCustomer)
{
output << "Customer Name: " << otherCustomer.firstName << " " << otherCustomer.lastName << " ID----> " << otherCustomer.customerID << endl;
return output;
}
//end operator<<