-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
482 lines (396 loc) · 14.9 KB
/
main.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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
/*************************************************************************
* AUTHOR : Cameron Walters
* Assignment : Program Design & Arrays
* Class : CS 301
* Due Date : 2/11/14
************************************************************************/
#include "header.h"
/************************************************************************
*
* _______________________________________________________________________
*
* _______________________________________________________________________
* PRE-CONDITIONS
*
* POST-CONDITIONS
*
************************************************************************/
int main()
{
int numOfStudents = 0;
float contentAverage = 0;
float presentationAverage = 0;
Student arrayStudents[STUDENT_MAX];
float finalScore[STUDENT_MAX];
Student temp;
for(int index = 0; index < STUDENT_MAX; index++)
{
finalScore[index] = 0;
}
numOfStudents = promptUserNumStudents();
//gets students
for(int index = 0; index < numOfStudents; index++)
{
cout << "\t\nStudent # " << (index + 1);
arrayStudents[index] = PromptUserForStudent();
}
// sorts names
SortName(arrayStudents,
numOfStudents);
// averages the scores
if(numOfStudents > 2)
{
AverageWClassArray(contentAverage,
presentationAverage,
arrayStudents,
numOfStudents);
}
// //populates basic arrays for averaging
// for(int index = 0; index < numOfStudents; index++)
// {
// contentArray[index] = arrayStudents[index].ReturnContentScore();
// presentArray[index] = arrayStudents[index].ReturnPresentationScore();
// }
//
// contentAverage = AverageGeneric(contentArray,
// numOfStudents);
// presentationAverage = AverageGeneric(presentArray,
// numOfStudents);
CalFinalScore(finalScore,
arrayStudents,
numOfStudents);
// Displays Students
DisplayMenuTop();
for(int index = 0; index < numOfStudents; index++)
{
arrayStudents[index].Print();
cout << " " << fixed << setprecision(2) << setw(4) << finalScore[index] << " |";
cout << endl;
}
cout << "\t|_________________________________________"
"______________________________________|\n";
if(contentAverage == 0 || presentationAverage == 0)
{
cout << "\nAverage Content Score : Student Population too Small";
cout << "\nAverage Presentation Score : Student Population too Small";
}
else
{
cout << "\nAverage Content Score : " << contentAverage;
cout << "\nAverage Presentation Score : " << presentationAverage;
}
cout << endl << endl;
//displays a Histogram of Averaged Scores
DisplayHistogram( finalScore,
numOfStudents);
return 0;
}
/************************************************************************
* int promptUserNumStudents()
* _______________________________________________________________________
* This function outputs the menu and tracks if the user inputs an
* invaild character or number within the range that was passed.
* _______________________________________________________________________
* PRE-CONDITIONS
* MENU_FORMAT : menu format needs to be predetermined
* IN_MIN : minimum input option needs to be predetermined
* IN_MAX : maximum input option needs to be predetermined
* POST-CONDITIONS
* Returns a valid user choice (option) to the calling function
************************************************************************/
int promptUserNumStudents()
{
return NumberError("Enter Number of Students : ", 0,32);
}
/************************************************************************
* void DisplayMenuTop()
* _______________________________________________________________________
* This function outputs the menu and tracks if the user inputs an
* invaild character or number within the range that was passed.
* _______________________________________________________________________
* PRE-CONDITIONS
* MENU_FORMAT : menu format needs to be predetermined
* IN_MIN : minimum input option needs to be predetermined
* IN_MAX : maximum input option needs to be predetermined
* POST-CONDITIONS
* Returns a valid user choice (option) to the calling function
************************************************************************/
void DisplayMenuTop()
{
cout << "\n\t _______________________________________________________________________________\n";
cout << "\t| ID | Student Name | Presentation | Content | Final Score |\n";
cout << "\t|-----------|----------------------------|--------------|---------|-------------|\n";
}
/************************************************************************
*Student PromptUserForStudent()
* _______________________________________________________________________
* This function outputs the menu and tracks if the user inputs an
* invaild character or number within the range that was passed.
* _______________________________________________________________________
* PRE-CONDITIONS
* MENU_FORMAT : menu format needs to be predetermined
* IN_MIN : minimum input option needs to be predetermined
* IN_MAX : maximum input option needs to be predetermined
* POST-CONDITIONS
* Returns a valid user choice (option) to the calling function
************************************************************************/
Student PromptUserForStudent()
{
Student tempStudent;
string tempName;
int tempId;
int tempContentScore;
int tempPresentationScore;
cout << "\nEnter Student's Name : ";
getline(cin, tempName);
tempId = NumberError("Enter Student's Id Number : ", 0,100000);
tempContentScore = NumberError("Enter Content Score : ", 0,10);
tempPresentationScore = NumberError("Enter Presentation Score : ", 0,10);
tempStudent.ChangeStudentName(tempName);
tempStudent.ChangeStudentId(tempId);
tempStudent.ChangeContentScore(tempContentScore);
tempStudent.ChangePrensentationScore(tempPresentationScore);
return tempStudent;
}
/************************************************************************
* void AverageWClassArray
* _______________________________________________________________________
* This function outputs the menu and tracks if the user inputs an
* invaild character or number within the range that was passed.
* _______________________________________________________________________
* PRE-CONDITIONS
* MENU_FORMAT : menu format needs to be predetermined
* IN_MIN : minimum input option needs to be predetermined
* IN_MAX : maximum input option needs to be predetermined
* POST-CONDITIONS
* Returns a valid user choice (option) to the calling function
************************************************************************/
void AverageWClassArray(float &contentAverage,
float &presentAverage,
Student arrayStudents[],
int numOfStudents)
{
float conAverage = 0.0;
float preAverage = 0.0;
int topScoreCon = MIN_SCORE;
int topScorePre = MIN_SCORE;
int lowScoreCon = MAX_SCORE;
int lowScorePre = MAX_SCORE;
int totalCon = 0;
int totalPre = 0;
for(int index = 0; index < numOfStudents; index++)
{
if(arrayStudents[index].ReturnContentScore() > topScoreCon)
{
topScoreCon = arrayStudents[index].ReturnContentScore();
}
if(arrayStudents[index].ReturnContentScore() < lowScoreCon)
{
lowScoreCon = arrayStudents[index].ReturnContentScore();
}
totalCon = totalCon + arrayStudents[index].ReturnContentScore();
}
for(int index = 0; index < numOfStudents; index++)
{
if(arrayStudents[index].ReturnPresentationScore() > topScorePre)
{
topScorePre = arrayStudents[index].ReturnPresentationScore();
}
if(arrayStudents[index].ReturnPresentationScore() < lowScorePre)
{
lowScorePre = arrayStudents[index].ReturnPresentationScore();
}
totalPre = totalPre + arrayStudents[index].ReturnPresentationScore();
}
totalCon = totalCon - topScoreCon - lowScoreCon;
totalPre = totalPre - topScorePre - lowScorePre;
numOfStudents = numOfStudents - 2;
conAverage = totalCon / float(numOfStudents);
preAverage = totalPre / float(numOfStudents);
contentAverage = conAverage;
presentAverage = preAverage;
}
/************************************************************************
* float AverageGeneric
* _______________________________________________________________________
* This function outputs the menu and tracks if the user inputs an
* invaild character or number within the range that was passed.
* _______________________________________________________________________
* PRE-CONDITIONS
* MENU_FORMAT : menu format needs to be predetermined
* IN_MIN : minimum input option needs to be predetermined
* IN_MAX : maximum input option needs to be predetermined
* POST-CONDITIONS
* Returns a valid user choice (option) to the calling function
************************************************************************/
float AverageGeneric(int inArray[],
int numOfStudents)
{
float average = 0.0;
int topScore = MIN_SCORE;
int lowScore = MAX_SCORE;
int total = 0;
for(int index = 0; index < numOfStudents; index++)
{
if(inArray[index] > topScore)
{
topScore = inArray[index];
}
if(inArray[index] < lowScore)
{
lowScore = inArray[index];
}
total = total + inArray[index];
}
total = total - topScore - lowScore;
numOfStudents = numOfStudents - 2;
average = total / float(numOfStudents);
return average;
}
/************************************************************************
* void SortName
* _______________________________________________________________________
* This function outputs the menu and tracks if the user inputs an
* invaild character or number within the range that was passed.
* _______________________________________________________________________
* PRE-CONDITIONS
* MENU_FORMAT : menu format needs to be predetermined
* IN_MIN : minimum input option needs to be predetermined
* IN_MAX : maximum input option needs to be predetermined
* POST-CONDITIONS
* Returns a valid user choice (option) to the calling function
************************************************************************/
void SortName(Student arrayStudents[],
int numOfStudents)
{
Student temp;
int i;
int j;
//inilization
j = 0;
//Calculation
for(i= 1; i < numOfStudents; ++i)
{
//makes temp become the first int and compares
temp = arrayStudents[i];
j = i -1;
while ( j >= 0 && arrayStudents[j].ReturnLastname() > temp.ReturnLastname())
{
arrayStudents[ j + 1] = arrayStudents[j];
j = j - 1;
}
arrayStudents[j + 1] = temp;
}
}
void CalFinalScore(float finalScores[],
Student arrayStudents[],
int numOfStudents)
{
float temp = 0.0;
for(int index = 0; index < numOfStudents; index++)
{
// cout << endl << " CalFin Con" << arrayStudents[index].ReturnContentScore();
// cout << endl << " CalFin Pre" << arrayStudents[index].ReturnPresentationScore();
// cout << endl;
temp =(arrayStudents[index].ReturnContentScore() * CONTENT_WEIGHT)
+
(arrayStudents[index].ReturnPresentationScore() * PRESENT_WEIGHT);
finalScores[index] = temp;
}
}
/************************************************************************
* void DisplayHistogram
* _______________________________________________________________________
* This function outputs the menu and tracks if the user inputs an
* invaild character or number within the range that was passed.
* _______________________________________________________________________
* PRE-CONDITIONS
* MENU_FORMAT : menu format needs to be predetermined
* IN_MIN : minimum input option needs to be predetermined
* IN_MAX : maximum input option needs to be predetermined
* POST-CONDITIONS
* Returns a valid user choice (option) to the calling function
************************************************************************/
void DisplayHistogram(float finalScores[],
int numOfStudents)
{
int count = 0;
int temp;
cout << setfill('*');
for(int index1 = 0; index1 < 11; index1++)
{
for(int index2 = 0; index2 < numOfStudents; index2++)
{
temp = finalScores[index2];
if(temp == index1)
{
count = count + 1;
}
}
if(count >= 1)
{
cout << setfill(' ') << setw(2) << index1 << "-< " <<setfill('*')
<< setw(count) << "*" ;
}
else
{
cout << setfill(' ') << setw(2) << index1 << "-< " << setfill('*');
}
cout << endl;
count = 0;
}
cout << setfill(' ');
}
/************************************************************************
* int NumberError
* _______________________________________________________________________
* This function outputs the menu and tracks if the user inputs an
* invaild character or number within the range that was passed.
* _______________________________________________________________________
* PRE-CONDITIONS
* MENU_FORMAT : menu format needs to be predetermined
* IN_MIN : minimum input option needs to be predetermined
* IN_MAX : maximum input option needs to be predetermined
* POST-CONDITIONS
* Returns a valid user choice (option) to the calling function
************************************************************************/
int NumberError(const string MENU_FORMAT, // IN & OUT - output string
const int IN_MIN, // IN & OUT - minimum option
const int IN_MAX) // IN & OUT - maximum option
{
bool someBool; // PROCESSING - determines whether
// the menu is output
int option; // IN & OUT - user input choice
do
{
someBool = false;
// OUTPUT - the menu
cout << MENU_FORMAT;
/*****************************************************************
* This is a check for the user's input. It will first check
* if the user has put in a vaild number, if invaild it will
* clear the input then reoutput the menu until and do the
* check's until the user puts in a vaild entry.
*****************************************************************/
if(!(cin >> option))
{
cout << "\n**** Please input a NUMBER between " << IN_MIN
<< " and " << IN_MAX << " ****";
cin.clear();
someBool = true;
cout << endl << endl;
}
else if (option > IN_MAX || option < IN_MIN)
{
cout << endl;
cout << "**** The number " << option << " is an invalid "
"entry ****\n";
cout << "**** Please input a number between "
<< IN_MIN << " and " << IN_MAX << " ****\n";
cout << endl;
someBool = true;
}
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}while(someBool);
return option;
}