forked from noahc66260/C-PrimerPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemp.cpp
273 lines (219 loc) · 5.24 KB
/
emp.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
// emp.cpp -- implementation file for abstr_emp class and children
// This is exercise 5 of chapter 14 in C++ Primer Plus 5e by Stephen Prata
#include<iostream>
#include"emp.h"
// abstr_emp class methods
/*
std::string fname;
std::string lname;
std::string job;
*/
abstr_emp::abstr_emp() : fname(""), lname(""), job("")
{
}
abstr_emp::abstr_emp(const std::string & fn, const std::string & ln,
const std::string & j) : fname(fn), lname(ln), job(j)
{
}
// labels and shows all data
void abstr_emp::ShowAll() const
{
using std::cout;
using std::endl;
cout << "First name: " << fname << endl;
cout << "Last name: " << lname << endl;
cout << "Job: " << job << endl;
}
// prompts user for values
void abstr_emp::SetAll()
{
using std::cout;
using std::endl;
using std::cin;
cout << "Enter first name: ";
cin >> fname;
while (cin.get() != '\n')
continue;
cout << "Enter last name: ";
cin >> lname;
while (cin.get() != '\n')
continue;
cout << "Enter the job: ";
getline(cin, job);
}
// just displays first and last name
std::ostream & operator<<(std::ostream & os, const abstr_emp & e)
{
os << e.lname << ", " << e.fname;
return os;
}
abstr_emp::~abstr_emp()
{
}
// employee class methods (inherits abstr_emp class publically)
employee::employee() : abstr_emp()
{
}
employee::employee(const std::string & fn, const std::string & ln,
const std::string & j) : abstr_emp(fn, ln, j)
{
}
void employee::ShowAll() const
{
using std::cout;
using std::endl;
cout << "Status: Employee" << endl;
abstr_emp::ShowAll();
}
void employee::SetAll()
{
abstr_emp::SetAll();
}
// manager class methods (inherits abstr_emp publically and virtually)
/*
int inchargeof; // number of abstr_emps managed
*/
manager::manager() : abstr_emp()
{
inchargeof = 0;
}
manager::manager(const std::string & fn, const std::string & ln,
const std::string & j, int ico) : abstr_emp(fn, ln, j)
{
using std::cout;
using std::endl;
inchargeof = ico;
if (inchargeof < 0)
{
cout << "Error, cannot be in charge of negative people." << endl;
cout << "Setting inchargeof to 0" << endl;
inchargeof = 0;
}
}
manager::manager(const abstr_emp & e, int ico) : abstr_emp(e)
{
using std::cout;
using std::endl;
inchargeof = ico;
if (inchargeof < 0)
{
cout << "Error, cannot be in charge of negative people." << endl;
cout << "Setting inchargeof to 0" << endl;
inchargeof = 0;
}
}
manager::manager(const manager & m) : abstr_emp(m)
{
inchargeof = m.inchargeof;
}
void manager::ShowAll() const
{
using std::cout;
using std::endl;
cout << "Status: Manager" << endl;
abstr_emp::ShowAll();
cout << "In charge of " << inchargeof << " people" << endl;
}
void manager::SetAll()
{
using std::cout;
using std::cin;
using std::endl;
abstr_emp::SetAll();
cout << "Enter the number of people the manager is in charge of: ";
cin >> inchargeof;
if (inchargeof < 0)
{
cout << "Error, cannot be in charge of negative people." << endl;
cout << "Setting inchargeof to 0" << endl;
inchargeof = 0;
}
}
// fink class methods (inherits abstr_emp publically and virtually)
/*
std::string reportsto; // to whom fink reports
*/
fink::fink() : abstr_emp(), reportsto("")
{
}
fink::fink(const std::string & fn, const std::string & ln,
const std::string & j, const std::string & rpo)
: abstr_emp(fn, ln, j), reportsto(rpo)
{
}
fink::fink(const abstr_emp & e, const std::string & rpo)
: abstr_emp(e), reportsto(rpo)
{
}
fink::fink(const fink & e) : abstr_emp(e)
{
reportsto = e.reportsto;
}
void fink::ShowAll() const
{
using std::cout;
using std::endl;
cout << "Status: fink" << endl;
abstr_emp::ShowAll();
cout << "Reports to " << reportsto << endl;
}
void fink::SetAll()
{
using std::cout;
using std::endl;
using std::cin;
abstr_emp::SetAll();
cout << "Enter whomever is reported to: ";
getline(cin, reportsto);
}
// highfink class methods (inherits manager and fink classes publically)
highfink::highfink() : abstr_emp(), manager(), fink()
{
}
highfink::highfink(const std::string & fn, const std::string & ln,
const std::string & j, const std::string & rpo, int ico)
: abstr_emp(fn, ln, j), manager(fn, ln, j, ico), fink(fn, ln, j, rpo)
{
}
highfink::highfink(const abstr_emp & e, const std::string & rpo, int ico)
: abstr_emp(e), manager(e, ico), fink(e, rpo)
{
}
highfink::highfink(const fink & f, int ico)
: abstr_emp(f), manager(f, ico), fink()
{
}
highfink::highfink(const manager & m, const std::string & rpo)
: abstr_emp(m), manager(m), fink(m, rpo)
{
}
highfink::highfink(const highfink & h) : abstr_emp(h), manager(h), fink(h)
{
}
void highfink::ShowAll() const
{
using std::cout;
using std::endl;
cout << "Status: Highfink" << endl;
abstr_emp::ShowAll();
cout << "In charge of " << InChargeOf() << " people" << endl;
cout << "Reports to " << ReportsTo() << endl;
}
void highfink::SetAll()
{
using std::cout;
using std::endl;
using std::cin;
abstr_emp::SetAll();
cout << "Enter the number of people managed: ";
cin >> InChargeOf();
if (InChargeOf() < 0)
{
cout << "Error, cannot be in charge of negative people." << endl;
cout << "Setting inchargeof to 0" << endl;
InChargeOf() = 0;
}
cin.get(); // remove newline character
cout << "Enter whomever is reported to: ";
getline(cin, ReportsTo());
}