-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudent_grader.cpp
executable file
·327 lines (313 loc) · 9.1 KB
/
student_grader.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
// studentGrader2.cpp
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
struct Stdnt
{
string name;
short grd1, grd2, grd3;
float avg;
};
void ListAllInfo1(Stdnt [], short);
void ReturnAvg2(Stdnt [], short);
void ShowAbove3(Stdnt [], short);
void ShowBelow4(Stdnt [], short);
void ShowReceiving5(Stdnt [], short);
void SortByName6(Stdnt [], short);
void SortByAvg7(Stdnt [], short);
void Continue();
void TitlePrinter(string);
int main()
{
system("cls");
TitlePrinter("Student Grader Program");
cout << "This program will perform various operations on a\n"
<< "list of fifty students. Each student has three\n"
<< "recorded test grades, as well as their own ID\n"
<< "number. The operations available will be shown\n"
<< "in the following menu, but first a file containing\n"
<< "all of the relevant student data is needed.\n"
<< "--------------------------------------------------\n";
string filename;
ifstream inFile;
do
{
inFile.clear();
cout << "Input the filename: ";
cin >> filename;
inFile.open(filename.c_str());
if (!inFile)
{
cout << "*** File not found, retry or hit Ctrl-C to quit. ***\n\n";
}
} while (!inFile);
Stdnt sData[50];
short sCount = 0;
while (!inFile.eof())
{
inFile >> sData[sCount].name;
inFile >> sData[sCount].grd1;
inFile >> sData[sCount].grd2;
inFile >> sData[sCount].grd3;
sData[sCount].avg = (float)(sData[sCount].grd1 + sData[sCount].grd2 + sData[sCount].grd3) / 3;
if (!inFile.eof())
{
sCount++;
}
}
inFile.close();
bool finished = false;
short menu;
while (!finished)
{
do
{
system("cls");
TitlePrinter("Student Grade Operations");
cout << "1. List all ids, test grades, and averages\n"
<< "2. Return the class average\n"
<< "3. Show students receiving above a certain number\n"
<< "4. Show students receiving below a certain number\n"
<< "5. Show all students receiving the higest average\n"
<< "6. Sort the data table by student name\n"
<< "7. Sort the data table by average grade\n"
<< "8. Exit\n"
<< "--------------------------------------------------\n\n"
<< "Select: ";
cin >> menu;
} while (menu < 1 || menu > 8);
system("cls");
switch(menu)
{
default:
break;
case 1:
ListAllInfo1(sData, sCount);
break;
case 2:
ReturnAvg2(sData, sCount);
break;
case 3:
ShowAbove3(sData, sCount);
break;
case 4:
ShowBelow4(sData, sCount);
break;
case 5:
ShowReceiving5(sData, sCount);
break;
case 6:
SortByName6(sData, sCount);
break;
case 7:
SortByAvg7(sData, sCount);
break;
case 8:
finished = true;
break;
}
}
return 0;
}
void ListAllInfo1(Stdnt sData[], short fsCount)
{
short pageNum = 1;
short tillNewPage = 0;
bool allDone = false;
do
{
system("cls");
TitlePrinter("Current Class Information");
cout << setw(28) << "Page: " << pageNum << endl << endl
<< setw(47) << "Student ID: Test Scores: Average:"
<< endl << endl;
for (short count = tillNewPage; count < tillNewPage + 10; count++)
{
cout << setw(11) << sData[count].name
<< setw(13) << sData[count].grd1 << setw(4) << sData[count].grd2 << setw(4) << sData[count].grd3
<< setw(12) << fixed << setprecision(1) << sData[count].avg << endl;
if (count >= fsCount - 1)
{
count = 50;
}
}
cout << endl;
if (tillNewPage + 10 >= fsCount)
{
allDone = true;
}
else
{
pageNum++;
tillNewPage += 10;
cout << "\nPress <enter> to print the next page...";
cout << endl;
Continue();
}
} while (!allDone);
cout << "\nPress <enter> to return to the main menu...\n\n";
Continue();
}
void ReturnAvg2(Stdnt sData[], short fsCount)
{
system("cls");
float classAvg = 0;
for (short count = 0; count < fsCount; count++)
{
classAvg += sData[count].avg;
}
classAvg /= fsCount;
cout << "The class average of all " << fsCount << " students is " << setprecision(1) << fixed << classAvg << " percent.\n\n"
<< "Press <enter> to return to the main menu...";
Continue();
}
void ShowAbove3(Stdnt sData[], short fsCount)
{
system("cls");
short toCheck;
do
{
cout << "Choose a grade to list the students whos average is above that number.\n"
<< "Input: ";
cin >> toCheck;
} while (toCheck < 0 || toCheck > 1000);
system("cls");
short tillNewLine = 0;
TitlePrinter("Higher Ranking Students");
cout << setw(27) << "Average: " << toCheck << "%\n\n"
<< " ";
for (short count = 0; count < fsCount; count++)
{
if (sData[count].avg > toCheck)
{
cout << " " << sData[count].name;
tillNewLine++;
}
if (tillNewLine == 4)
{
cout << "\n\n ";
tillNewLine = 0;
}
}
cout << "\n\n\nPress <enter> to return to the main menu...";
Continue();
}
void ShowBelow4(Stdnt sData[], short fsCount)
{
system("cls");
unsigned int toCheck;
do
{
cout << "Choose a grade to list the students whos average is below that number.\n"
<< "Input: ";
cin >> toCheck;
} while (toCheck < 0 || toCheck > 1000);
system("cls");
short tillNewLine = 0;
TitlePrinter("Lower Ranking Students");
cout << setw(27) << "Average: " << toCheck << "%\n\n"
<< " ";
for (short count = 0; count < fsCount; count++)
{
if (sData[count].avg < toCheck)
{
cout << " " << sData[count].name;
tillNewLine++;
}
if (tillNewLine == 4)
{
cout << "\n\n ";
tillNewLine = 0;
}
}
cout << "\n\n\nPress <enter> to return to the main menu...";
Continue();
}
void ShowReceiving5(Stdnt sData[], short fsCount)
{
system("cls");
short highestAvg;
for (short count = 0; count < fsCount; count++)
{
if (highestAvg < sData[count].avg)
{
highestAvg = sData[count].avg;
}
}
short tillNewLine = 0;
TitlePrinter("Highest Averaging Students");
cout << setw(27) << "Average: " << highestAvg << "%\n\n"
<< " ";
for (short count = 0; count < fsCount; count++)
{
if (sData[count].avg == highestAvg)
{
cout << " " << sData[count].name;
tillNewLine++;
}
if (tillNewLine == 4)
{
cout << "\n\n ";
tillNewLine = 0;
}
}
cout << "\n\nPress <enter> to return to the main menu...";
Continue();
}
void SortByName6(Stdnt sData[], short fsCount)
{
system("cls");
Stdnt temp;
for (short p = 0; p < fsCount - 1; p++)
{
for (short elem = 0; elem < fsCount - 1; elem++)
{
if (sData[elem].name > sData[elem + 1].name)
{
temp = sData[elem];
sData[elem] = sData[elem + 1];
sData[elem + 1] = temp;
}
}
}
cout << "The student data table has been sorted by ID number.\n"
<< "All operations performed from the menu will reflect this.\n\n"
<< "Press <enter> to return to the main menu...";
Continue();
}
void SortByAvg7(Stdnt sData[], short fsCount)
{
system("cls");
Stdnt temp;
for (short p = 0; p < fsCount - 1; p++)
{
for (short elem = 0; elem < fsCount - 1; elem++)
{
if (sData[elem].avg < sData[elem + 1].avg)
{
temp = sData[elem];
sData[elem] = sData[elem + 1];
sData[elem + 1] = temp;
}
}
}
cout << "The student data table has been sorted by average grade.\n"
<< "All operations performed from the menu will reflect this.\n\n"
<< "Press <enter> to return to the main menu...";
Continue();
}
void Continue()
{
cin.ignore(cin.rdbuf() -> in_avail() + 1);
cin.get();
}
void TitlePrinter(string ftitle)
{
string spcLen(((48 - ftitle.length()) / 2), ' ');
ftitle.insert(0, spcLen + '(');
cout << "--------------------------------------------------\n"
<< ftitle << ")\n"
<< "--------------------------------------------------\n";
}