-
Notifications
You must be signed in to change notification settings - Fork 0
/
university.cpp
295 lines (240 loc) · 9.04 KB
/
university.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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/***************************************************************************************************
** Author: Michael Johnson
** Date: 7/19/2017
** Description: Definitions of University class functions
***************************************************************************************************/
#include "University.h"
/*******************************************************************************************************
** University Constructor
** Constructs the object with the university name
*******************************************************************************************************/
University::University()
{
universityName = "Oregon State University";
/*build1 = new Buildings("Cordley Hall", 235805, "2701 SW Campus Way, Corvallis, OR 97331");
build2 = new Buildings("Physical Plant - Vehicle Shed B", 679, "572 SW 15th St., Corvallis, OR 97331");
addToBuildVector(build1);
addToBuildVector(build2);
stud1 = new Student("Michael Johnson", 31, 3.5);
inst1 = new Instructor("Edward Francis", 25, 5.0);
addToPeopVector(stud1);
addToPeopVector(inst1);*/
}
/*******************************************************************************************************
** University Destructor
** Destructs the object with the university name
*******************************************************************************************************/
University::~University()
{
for (int i = 0; i < peopleVect.size(); i++)
{
delete peopleVect[i];
}
peopleVect.clear();
for (int i = 0; i < buildingVect.size(); i++)
{
delete buildingVect[i];
}
buildingVect.clear();
delete tempS;
delete tempI;
delete tempB;
}
/*******************************************************************************************************
** menu function
** Runs the program. Calls functions based on menu choice and user input
*******************************************************************************************************/
void University::menu()
{
while (menu1.getChoice() != 6 ) // 6 represents exiting the program
{
// Provides menu and choice
menu1.displayMenu();
menu1.setChoice();
// User chooses to add a person
if (menu1.getChoice() == 1)
{
cout << "Are you adding a student or an instructor?" << endl;
cout << "Enter 's' for student and 'i' for instructor" << endl;
char pInput = inputVal1.isChar();
if (pInput != 's' && pInput != 'i')
{
cout << "Enter 's' for student and 'i' for instructor" << endl;
char pInput = inputVal1.isChar();
}
else
{
// User wants to input a student
if (pInput == 's')
{
cout << "Enter student's name" << endl;
tempName = inputVal1.isString();
cout << endl;
cout << "Enter student's age" << endl;
cout << "between 17 and 85" << endl;
tempAge = inputVal1.isPosInteger();
// Checks to make sure age is in range
while (tempAge < 17 || tempAge > 85)
{
cout << "Please enter an age between 17 and 85" << endl;
tempAge = inputVal1.isPosInteger();
}
cout << endl;
cout << "Enter student's GPA" << endl;
cout << "between 0.0 and 4.0" << endl;
tempScore = inputVal1.isFloat();
// Checks to make sure GPA is in range
while (tempScore < 0.0 || tempScore > 4.0)
{
cout << "Please enter a GPA between 0.0 and 4.0" << endl;
tempScore = inputVal1.isFloat();
}
// Creates a pointer to People object for student
tempS = new Student(tempName, tempAge, tempScore);
addToPeopVector(tempS);
//delete[] tempS;
}
// User wants to add an instructor
else if (pInput == 'i')
{
cout << "Enter instructor's name" << endl;
tempName = inputVal1.isString();
cout << endl;
cout << "Enter instructor's age" << endl;
cout << "between 25 and 90" << endl;
tempAge = inputVal1.isPosInteger();
while (tempAge < 25 || tempAge > 90)
{
cout << "Please enter an age between 25 and 90" << endl;
tempAge = inputVal1.isPosInteger();
}
cout << endl;
cout << "Enter instructor's rating" << endl;
cout << "between 0.0 and 5.0" << endl;
tempScore = inputVal1.isFloat();
while (tempScore < 0.0 || tempScore > 5.0)
{
cout << "Please enter an instructor rating between 0.0 and 5.0" << endl;
tempScore = inputVal1.isFloat();
}
// Creates a pointer to People object for student
tempI = new Instructor(tempName, tempAge, tempScore);
addToPeopVector(tempI);
//delete[] tempI;
}
}
}
// User wants to add a building
else if (menu1.getChoice() == 2)
{
cout << "Enter building's name" << endl;
tempName = inputVal1.isString();
cout << endl;
cout << "Enter size of building in square feet" << endl;
cout << "between 0 and 500,000" << endl;
tempSize = inputVal1.isPosInteger();
while (tempSize < 0 || tempSize > 500000)
{
cout << "Please enter an age between 0 and 500,000" << endl;
tempAge = inputVal1.isPosInteger();
}
cout << endl;
cout << "Enter building's address" << endl;
getline(cin, tempAddress);
// Creates a pointer to Building object
tempB = new Buildings(tempName, tempSize, tempAddress);
addToBuildVector(tempB);
//delete[] tempB;
}
// User wants to print a list of buildings
else if (menu1.getChoice() == 3)
{
printBuildings();
}
// User wants to print a list of people
else if (menu1.getChoice() == 4)
{
printPeople();
}
// User wants to make a person do work
else if (menu1.getChoice() == 5)
{
// Prints a list of people's name
for (size_t i = 0; i < peopleVect.size(); i++)
{
cout << peopleVect[i]->getName() << endl;
}
cout << endl;
cout << "Enter the name of the person that you would like to do work" << endl;
tempName = inputVal1.isString();
cout << endl;
// Loops through the people vector
for (size_t i = 0; i < peopleVect.size(); i++)
{
// and searches for the name that the user input
if (tempName == peopleVect[i]->getName())
{
cout << "What is the maximum number of hours you want them to work?" << endl;
cout << "We don't work overtime, so choose a number between 1 and 40" << endl;
tempHours = inputVal1.isPosInteger();
cout << endl;
while (tempHours < 1 || tempHours > 40)
{
cout << "Enter a number between 1 and 40" << endl;
tempHours = inputVal1.isPosInteger();
}
// Passes the maximum number of hours a person will work to the do_work function
peopleVect[i]->do_work(tempHours);
}
}
}
}
}
/*******************************************************************************************************
** addToBuildVector function
** Adds a building object to the building vector and changes the number of buildings to the new size
*******************************************************************************************************/
void University::addToBuildVector(Buildings *b)
{
buildingVect.push_back(b);
numOfBuildings = buildingVect.size();
}
/*******************************************************************************************************
** addToPeopVector function
** Adds a People object to the people vector and changes the number of people to the new size
*******************************************************************************************************/
void University::addToPeopVector(People *p)
{
peopleVect.push_back(p);
numOfPeople = peopleVect.size();
}
/*******************************************************************************************************
** printBuildings function
** Prints the values of each building object in the vector along with number of buildings and university name
*******************************************************************************************************/
void University::printBuildings()
{
cout << "There are " << numOfBuildings << " buildings at " << universityName << endl;
for (int i = 0; i < numOfBuildings; i++)
{
cout << buildingVect[i]->getName() << endl;
cout << buildingVect[i]->getSize() << endl;
cout << buildingVect[i]->getAddress() << endl;
cout << endl;
}
}
/*******************************************************************************************************
** printPeople function
** Prints the values of each People object in the vector along with number of people and university name
*******************************************************************************************************/
void University::printPeople()
{
cout << "There are " << numOfPeople << " people at " << universityName << endl;
for (size_t i = 0; i < peopleVect.size(); i++)
{
cout << peopleVect[i]->getName() << endl;
cout << peopleVect[i]->getAge() << endl;
cout << peopleVect[i]->getScore() << endl;
cout << endl;
}
}