-
Notifications
You must be signed in to change notification settings - Fork 31
/
structDynamicArray.cpp
458 lines (358 loc) · 15.1 KB
/
structDynamicArray.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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
//*****************************************************************************************************
// Speaker Management System
//
// This program is a speaker bureau system that allows users to dynamically allocate memory for a
// specified number of speakers, up to a limit of 5000, and allows users to input, update, and
// display information on speakers, as well as search for speakers by topic.
//
//*****************************************************************************************************
#include <cctype>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
//*****************************************************************************************************
struct Speaker {
string name;
string phoneNum;
string topic;
double fee;
};
void inputSpeakers(Speaker members[], int size, int &numSpeakers);
void updateSpeaker(Speaker members[], int numSpeakers, const string &speakerName);
void displayOneSpeakerInfo(Speaker members[], int numSpeakers, const string &speakerName);
void displayTopicSpeakers(Speaker members[], int numSpeakers, const string &topic);
void displayAllSpeakerInfo(Speaker members[], int numSpeakers);
bool isEmpty(const string &str);
bool testName(Speaker members[], int numSpeakers, const string &speakerName);
bool testTopic(Speaker members[], int numSpeakers, const string &topic);
//*****************************************************************************************************
int main() {
int size;
int numSpeakers = 0;
string speakerName,
topic;
bool nameTest,
topicTest;
char topicEntry;
cout << "\n---------------------------------------------------------------\n"
<< " Enter the number of speakers at the Speakers' Bureau\n"
<< "---------------------------------------------------------------" << endl;
do {
cout << "Number: ";
cin >> size;
cin.ignore();
if (size <= 0 || size >= 5000)
cerr << "\nNumber must be greater than 0 and smaller than 5000\n";
} while (size <= 0 || size >= 5000);
Speaker *members = new Speaker[size];
inputSpeakers(members, size, numSpeakers);
do {
cout << "\n---------------------------------------------------------------\n"
<< " Enter the name of the speaker you would like to update\n"
<< "---------------------------------------------------------------\n"
<< "Name: ";
getline(cin, speakerName);
nameTest = testName(members, numSpeakers, speakerName);
if (nameTest == false)
cerr << "\nSorry but the name does not exist\n";
} while (nameTest == false);
updateSpeaker(members, numSpeakers, speakerName);
do {
cout << "\n---------------------------------------------------------------\n"
<< " Enter the name of the speaker you would like to display\n"
<< "---------------------------------------------------------------\n"
<< "Name: ";
getline(cin, speakerName);
nameTest = testName(members, numSpeakers, speakerName);
if (nameTest == false)
cerr << "\nSorry but the name does not exist\n";
} while (nameTest == false);
displayOneSpeakerInfo(members, numSpeakers, speakerName);
do {
cout << "\n---------------------------------------------------------------\n"
<< " Enter the topic you would like to display names for\n"
<< "---------------------------------------------------------------\n"
<< "Topic: ";
getline(cin, topic);
topicTest = testTopic(members, numSpeakers, topic);
if (topicTest == false) {
cerr << "\nSorry but nobody is speaking about this topic\n\n";
cout << "Do you have another topic? (Y/N)" << endl;
cin >> topicEntry;
topicEntry = toupper(topicEntry);
if (topicEntry == 'N')
break;
cin.ignore();
}
} while (topicTest == false);
displayTopicSpeakers(members, numSpeakers, topic);
cout << "\n\n-------------------------------------------------------------\n"
<< "\t\tSpeakers' Bureau Information\n"
<< "-------------------------------------------------------------" << endl;
displayAllSpeakerInfo(members, numSpeakers);
delete[] members;
members = nullptr;
return 0;
}
//*****************************************************************************************************
void inputSpeakers(Speaker members[], int size, int &numSpeakers) {
char entry;
for (int i = 0; i < size; ++i) {
numSpeakers++;
cout << "\n---------------------------------------------------------------\n"
<< "\tEnter the following information of speaker " << i + 1 << ".\n"
<< "---------------------------------------------------------------" << endl;
cout << "Name: ";
getline(cin, members[i].name);
while (isEmpty(members[i].name)) {
cerr << "\nSorry but the name could not be empty\n";
cout << "\nName: ";
getline(cin, members[i].name);
}
cout << "Telephone Number: ";
getline(cin, members[i].phoneNum);
while (isEmpty(members[i].phoneNum)) {
cerr << "\nSorry but the telephone number could not be empty\n";
cout << "\nTelephone Number: ";
getline(cin, members[i].phoneNum);
}
cout << "Topic: ";
getline(cin, members[i].topic);
while (isEmpty(members[i].topic)) {
cerr << "\nSorry but the topic could not be empty\n";
cout << "\nTopic: ";
getline(cin, members[i].topic);
}
cout << "Fee: ";
cin >> members[i].fee;
while (members[i].fee < 0) {
cerr << "\nSorry but the fees could not be negative\n";
cout << "\nFee: ";
cin >> members[i].fee;
}
cout << "Do you have another entry? (Y/N): " << endl;
cin >> entry;
entry = toupper(entry);
if (entry == 'N') {
cin.ignore();
break;
}
cin.ignore();
}
}
//*****************************************************************************************************
void updateSpeaker(Speaker members[], int numSpeakers, const string &speakerName) {
cout << "\n---------------------------------------------------------------\n"
<< "\tPlease enter the speaker's updated information\n"
<< "---------------------------------------------------------------" << endl;
for (int i = 0; i < numSpeakers; ++i) {
if (speakerName == members[i].name) {
cout << "Name: ";
getline(cin, members[i].name);
while (isEmpty(members[i].name)) {
cerr << "\nSorry but the name could not be empty\n";
cout << "\nName: ";
getline(cin, members[i].name);
}
cout << "Telephone Number: ";
getline(cin, members[i].phoneNum);
while (isEmpty(members[i].phoneNum)) {
cerr << "\nSorry but the telephone number could not be empty\n";
cout << "\nTelephone Number: ";
getline(cin, members[i].phoneNum);
}
cout << "Topic: ";
getline(cin, members[i].topic);
while (isEmpty(members[i].topic)) {
cerr << "\nSorry but the topic could not be empty\n";
cout << "\nTopic: ";
getline(cin, members[i].topic);
}
cout << "Fee: ";
cin >> members[i].fee;
while (members[i].fee < 0) {
cerr << "\nSorry but the fees could not be negative\n";
cout << "\nFee: ";
cin >> members[i].fee;
}
cin.ignore();
}
}
}
//*****************************************************************************************************
void displayOneSpeakerInfo(Speaker members[], int numSpeakers, const string &speakerName) {
for (int i = 0; i < numSpeakers; ++i)
if (speakerName == members[i].name)
cout << "\nSpeaker " << i + 1
<< "\n\t" << setfill('.') << setw(30) << left << "Name "
<< " " << members[i].name
<< "\n\t" << setw(30) << "Telephone Number "
<< " " << members[i].phoneNum
<< "\n\t" << setw(30) << "Topic "
<< " " << members[i].topic
<< "\n\t" << setw(30) << "Fee "
<< " " << members[i].fee << endl;
}
//*****************************************************************************************************
void displayTopicSpeakers(Speaker members[], int numSpeakers, const string &topic) {
for (int i = 0; i < numSpeakers; ++i)
if (topic == members[i].topic)
cout << "\nSpeaker " << i + 1
<< "\n\t" << setfill('.') << setw(30) << left << "Name "
<< " " << members[i].name
<< "\n\t" << setw(30) << "Telephone Number "
<< " " << members[i].phoneNum
<< "\n\t" << setw(30) << "Topic "
<< " " << members[i].topic
<< "\n\t" << setw(30) << "Fee "
<< " " << members[i].fee << endl;
}
//*****************************************************************************************************
void displayAllSpeakerInfo(Speaker members[], int numSpeakers) {
for (int i = 0; i < numSpeakers; ++i)
cout << "\nSpeaker " << i + 1
<< "\n\t" << setfill('.') << setw(30) << left << "Name "
<< " " << members[i].name
<< "\n\t" << setw(30) << "Telephone Number "
<< " " << members[i].phoneNum
<< "\n\t" << setw(30) << "Topic "
<< " " << members[i].topic
<< "\n\t" << setw(30) << "Fee "
<< " " << members[i].fee << endl;
}
//*****************************************************************************************************
bool isEmpty(const string &str) {
bool success = false;
if (str.empty())
success = true;
return success;
}
//*****************************************************************************************************
bool testName(Speaker members[], int numSpeakers, const string &speakerName) {
bool nameFound = false;
for (int i = 0; i < numSpeakers; ++i) {
if (speakerName == members[i].name) {
nameFound = true;
break;
}
}
return nameFound;
}
//*****************************************************************************************************
bool testTopic(Speaker members[], int numSpeakers, const string &topic) {
bool topicFound = false;
for (int i = 0; i < numSpeakers; ++i) {
if (topic == members[i].topic) {
topicFound = true;
break;
}
}
return topicFound;
}
//*****************************************************************************************************
/*
---------------------------------------------------------------
Enter the number of speakers at the Speakers' Bureau
---------------------------------------------------------------
Number: -10
Number must be greater than 0 and smaller than 5000
Number: 0
Number must be greater than 0 and smaller than 5000
Number: 5000
Number must be greater than 0 and smaller than 5000
Number: 4
---------------------------------------------------------------
Enter the following information of speaker 1.
---------------------------------------------------------------
Name: Nicholas Ragland
Telephone Number: 314-219-9992
Topic: Art
Fee: 30.45
Do you have another entry? (Y/N):
Y
---------------------------------------------------------------
Enter the following information of speaker 2.
---------------------------------------------------------------
Name: Olivia Davisson
Telephone Number: 314-299-9999
Topic: Computer Science
Fee: 25.50
Do you have another entry? (Y/N):
Y
---------------------------------------------------------------
Enter the following information of speaker 3.
---------------------------------------------------------------
Name: John Smith
Telephone Number: 314-238-8455
Topic: History
Fee: 32
Do you have another entry? (Y/N):
Y
---------------------------------------------------------------
Enter the following information of speaker 4.
---------------------------------------------------------------
Name: Sam Smith
Telephone Number: 314-883-5462
Topic: Poetry
Fee: 10
Do you have another entry? (Y/N):
N
---------------------------------------------------------------
Enter the name of the speaker you would like to update
---------------------------------------------------------------
Name: Nicholas Ragland
---------------------------------------------------------------
Please enter the speaker's updated information
---------------------------------------------------------------
Name: Nicholas Smith
Telephone Number: 314-219-9993
Topic: Computer Science
Fee: 12.75
---------------------------------------------------------------
Enter the name of the speaker you would like to display
---------------------------------------------------------------
Name: Nicholas Smith
Speaker 1
Name ......................... Nicholas Smith
Telephone Number ............. 314-219-9993
Topic ........................ Computer Science
Fee .......................... 12.75
---------------------------------------------------------------
Enter the topic you would like to display names for
---------------------------------------------------------------
Topic: Computer Science
Speaker 1
Name ......................... Nicholas Smith
Telephone Number ............. 314-219-9993
Topic ........................ Computer Science
Fee .......................... 12.75
Speaker 2
Name ......................... Olivia Davisson
Telephone Number ............. 314-299-9999
Topic ........................ Computer Science
Fee .......................... 25.5
-------------------------------------------------------------
Speakers' Bureau Information
-------------------------------------------------------------
Speaker 1
Name ......................... Nicholas Smith
Telephone Number ............. 314-219-9993
Topic ........................ Computer Science
Fee .......................... 12.75
Speaker 2
Name ......................... Olivia Davisson
Telephone Number ............. 314-299-9999
Topic ........................ Computer Science
Fee .......................... 25.5
Speaker 3
Name ......................... John Smith
Telephone Number ............. 314-238-8455
Topic ........................ History
Fee .......................... 32
Speaker 4
Name ......................... Sam Smith
Telephone Number ............. 314-883-5462
Topic ........................ Poetry
Fee .......................... 10
*/