-
Notifications
You must be signed in to change notification settings - Fork 0
/
Customer.cpp
176 lines (144 loc) · 4.42 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
/*
* Customer.cpp - Implementation of Customer class
*
* Class Description: Contains information about the type of customer event (is it Arrival or Depature),
* If Arrival Event, then has the time of the arrival and length of transaction
* If Departure Event, then has the time of the departure and length set to 0
* Class Invariant: Type is always A, D, or None. Time and Length is always >= 0.
*
* Last modified on: June 30, 2017
* Author: Jacky Tse, Vicky Lau
*/
#include <iostream>
#include <string>
#include "Customer.h"
using namespace std;
// Default Constructor
// Description: Created a customer with no type and time and length of 0
// Postcondition: Type is set to "None", the rest is set to 0.
Customer::Customer(){
type = "None";
time = 0;
length = 0;
}
// Parameterized Constructor
// Description: Created a customer with the indicated parameters
// Postcondition: If type is not A or D, set to "None"
// Time is set to theTime
// Length is set to theLength unless type is D, in which length = 0.
Customer::Customer(string theType,
unsigned int theTime,
unsigned int theLength){
if(theType == "A" || theType == "D"){
type = theType;
}
else{
type = "None";
}
time = theTime;
if(type == "D"){
length = 0;
}
else{
length = theLength;
}
}
// Description: Returns the type
string Customer::getType() const{
return(type);
}
// Description: Returns the time
unsigned int Customer::getTime() const{
return(time);
}
// Description: Returns the Length
unsigned int Customer::getLength() const{
return(length);
}
// Description: Sets type to theType
void Customer::setType(string theType){
type = theType;
}
// Description: Sets time to theTime
void Customer::setTime(unsigned int theTime){
time = theTime;
}
// Description: Sets length to theLength
void Customer::setLength(unsigned int theLength){
length = theLength;
}
// Description: Comparison operator. Compares "this" Customer object with "rhs" Customer object.
// Returns true if time of "this" Customer object is the same as the time of "rhs" Customer object.
bool Customer::operator==(const Customer & rhs){
string rhsType = rhs.getType();
unsigned int rhsTime = rhs.getTime();
if(type == rhsType && time == rhsTime){
return(true);
}
return(false);
}
// Description: Comparison operator. Compares "this" Customer object with "rhs" Customer object.
// Returns true if time of "this" Customer object is > than the time of "rhs" Customer object.
bool Customer::operator>(const Customer & rhs){
string rhsType = rhs.getType();
unsigned int rhsTime = rhs.getTime();
if(time < rhsTime){
return(true);
}
else if(time == rhsTime && type == "A" && rhsType == "D"){
return(true);
}
return(false);
}
// Description: Comparison operator. Compares "this" Customer object with "rhs" Customer object.
// Returns true if time of "this" Customer object is < than the time of "rhs" Customer object.
bool Customer::operator<(const Customer & rhs){
string rhsType = rhs.getType();
unsigned int rhsTime = rhs.getTime();
if(time > rhsTime){
return(true);
}
else if(time == rhsTime && type == "D" && rhsType == "A"){
return(true);
}
return(false);
}
// Description: Comparison operator. Compares "this" Customer object with "rhs" Customer object.
// Returns true if time of "this" Customer object is >= than the time of "rhs" Customer object.
bool Customer::operator>=(const Customer & rhs){
string rhsType = rhs.getType();
unsigned int rhsTime = rhs.getTime();
if(time < rhsTime){
return(true);
}
else if(time == rhsTime && type == "A" && rhsType == "D"){
return(true);
}
else if(type == rhsType && time == rhsTime){
return(true);
}
return(false);
}
// Description: Comparison operator. Compares "this" Customer object with "rhs" Customer object.
// Returns true if time of "this" Customer object is <= than the time of "rhs" Customer object.
bool Customer::operator<=(const Customer & rhs){
string rhsType = rhs.getType();
unsigned int rhsTime = rhs.getTime();
if(time > rhsTime){
return(true);
}
else if(time == rhsTime && type == "D" && rhsType == "A"){
return(true);
}
else if(type == rhsType && time == rhsTime){
return(true);
}
return(false);
}
// Description: Prints the content of "this".
ostream & operator<<(ostream &os, const Customer &p) {
os << "Type: " << p.getType() << ", Time: " << p.getTime() <<
", Length: " << p.getLength() << endl;
return os;
}
// End of Customer.cpp