-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarks_manager.cpp
More file actions
425 lines (362 loc) · 11.1 KB
/
marks_manager.cpp
File metadata and controls
425 lines (362 loc) · 11.1 KB
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
/* Made by L21-5695 && L21-6225 */
#include<iostream>
#include<iomanip>
#include<fstream>
#include <windows.h>
using namespace std;
const int BLACK = 0;
const int BLUE = 1;
const int GREEN = 2;
const int CYAN = 3;
const int RED = 4;
const int MAGENTA = 5;
const int YELLOW = 6;
const int LIGHTGRAY = 7;
const int DARKGRAY = 8;
const int LIGHTBLUE = 9;
const int LIGHTGREEN = 10;
const int LIGHTCYAN = 11;
const int LIGHTRED = 12;
const int LIGHTMAGENTA = 13;
const int LIGHTYELLOW = 14;
const int WHITE = 15;
void setColor(int color) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, color);
}
int TotalStudents;
bool isLoaded;
int MagicNo, Evaluation_Count, MGN, Weightage, space_count;
int ID[100];
double Marks[100][11], TotalMarks[100], Weight[100], Sorted[100][11];
double Statistics[10][11];
void LoadWarn(){
setColor(4);
cout << endl << "Please Load the files first!" << endl
<< "Press any key to continue further..." << endl;
setColor(7);
cin.get();
cin.get();
}
void SwapElem(double A[][11], int row1, int row2, int col1, int col2){
int M;
M = A[row1][col1];
A[row1][col1] = A[row2][col2];
A[row2][col2] = M;
}
int presentMenu()
{
int Choice = 0;
do {
setColor(3);
cout << "\t Marks Manager" << endl << endl;
setColor(14);
cout << "1. Load Data" << endl
<< "2. Save" << endl
<< "3. Add" << endl
<< "4. Delete" << endl
<< "5. Sort" << endl
<< "6. View All" << endl
<< "7. Search" << endl;
setColor(4);
cout << "8. Exit" << endl;
setColor(10);
cout << endl << "Enter Your Choice (1-8) ";
if (Choice < 0 || Choice > 8)
setColor(4);
cout << endl << "Please enter a valid choice between 1 and 8 " << endl;
setColor(7);
cin >> Choice;
} while (Choice < 1 || Choice > 8);
return Choice;
}
void CalStat(){
for(int r=0; r<=TotalStudents; r++){ // Reseting Total + Weight
TotalMarks[r] = 0;
Weight[r] = 0;
}
for(int r=0; r<=TotalStudents; r++) // Calculating Total
{
for(int c=0; c<=Evaluation_Count; c++)
{
TotalMarks[r] = TotalMarks[r] + Marks[r][c];
}
}
for(int r=1, c; r<=TotalStudents; r++) // Calculating Weightage
{
for(c=0; c<=Evaluation_Count; c++)
{
Weight[r] = Weight[r] + (Marks[r][c]*Weightage);
}
Weight[r] = Weight[r] / (Evaluation_Count*Weightage);
}
for(int r=1, c=0, i=0; r<=TotalStudents; r++){ // Storing ID in Statistics
Statistics[r][c] = ID[i];
i++;
}
for(int r=0; r<=TotalStudents; r++) // Storing Marks in Statistics
{
for(int c=1,i=0; c<=Evaluation_Count; c++){
Statistics[r][c] = Marks[r][i];
i++;
}
}
for(int r=0; r<=TotalStudents; r++) // Storing Total Marks and Weightage in Statistics
{
Statistics[r][Evaluation_Count+1] = TotalMarks[r];
Statistics[r][Evaluation_Count+2] = Weight[r];
}
}
void LoadData(){
if(isLoaded){
setColor(2);
cout << endl << "Data already Loaded!" << endl
<< "Press any key to continue.." << endl;
setColor(7);
cin.get(); cin.get();
return;
}
ifstream ReadStudent, ReadMarks;
ReadStudent.open("STUDENT.DAT");
ReadMarks.open("MARKS.DAT");
ReadStudent >> MagicNo >> TotalStudents;
for(int i=0; i<TotalStudents; i++) // ID Fetch
ReadStudent >> ID[i];
ReadMarks >> MGN >> Weightage >> Evaluation_Count;
for(int r=0; r<=TotalStudents; r++){ // Evaluations Fetch
for(int c=0; c<Evaluation_Count; c++)
ReadMarks >> Marks[r][c];
}
ReadStudent.close();
ReadMarks.close();
setColor(10);
cout<<"----------------------------------";
cout << " \nData Loaded Successfully! \n";
cout << "Magic No: " << MagicNo << endl;
cout << "Total Students: " << TotalStudents << endl << endl;
setColor(7);
isLoaded = true;
CalStat();
}
void Add(){
if(!isLoaded){
LoadWarn();
return;
}
cout << endl << "Enter the maximum marks of the component: "<<endl;
for(int r=0; r<=TotalStudents; r++){ // Adding Marks
if(r!=0){
cout << "Enter the marks of Roll No. " << ID[r-1] << "\t";
do{
if(Marks[r][Evaluation_Count] > Marks[0][Evaluation_Count])
cout << "Please enter valid marks within the maximum range: ";
cin >> Marks[r][Evaluation_Count];
}while(Marks[r][Evaluation_Count] > Marks[0][Evaluation_Count]);
}
else
cin >> Marks[r][Evaluation_Count];
}
Evaluation_Count++;
space_count = space_count+4;
CalStat();
}
void Save(){
if(!isLoaded){
LoadWarn();
return;
}
ofstream WriteMarks;
WriteMarks.open("MARKS.DAT");
WriteMarks << MGN << endl
<< Weightage << endl
<< Evaluation_Count << endl;
for(int r=0; r<=10; r++) // Writing Data into files
{
for(int c=0; c<10; c++){
if(Marks[r][c]!=0)
WriteMarks << Marks[r][c] << "\t";
}
if(Marks[r][0]!=0)
WriteMarks << endl;
}
WriteMarks.close();
setColor(2);
cout << endl << endl << "Data saved to files successfully." << endl;
setColor(7);
}
void Delete(){
if(!isLoaded){
LoadWarn();
return;
}
setColor(4);
cout << endl << "Enter a component to delete the marks [0 ---- so on....]: "<<endl;
setColor(7);
int del_comp;
cin >> del_comp;
for(int r=0; r<=TotalStudents; r++) // Deleting column component
Marks[r][del_comp] = 0;
Evaluation_Count--;
space_count--;
CalStat();
}
void Sort(){
if(!isLoaded){
LoadWarn();
return;
}
int choice;
do{
cout << "\n\t How do you want to sort the data? \n\n"
<< "1. Roll No (Ascending) \n"
<< "2. Roll No (Descending) \n"
<< "3. Total(Ascending)\n"
<< "4. Total (Descending)"
<< endl << endl
<< "\t Please enter a valid choice [1-2] \n";
cin >> choice;
if(choice < 1 || choice > 4)
cout << endl << "Please enter a valid choice!" << endl << endl;
}while(choice < 1 || choice > 4);
int Statistics_count = Evaluation_Count+2;
if(choice == 1){
for(int s=1; s<=TotalStudents; s++)
{ for(int j=s+1; j<=TotalStudents; j++)
if(Statistics[s][0] > Statistics[j][0]){
for(int c=0; c<=Statistics_count; c++)
SwapElem(Statistics, s, j, c, c);
}
}
}
if(choice == 2){
for(int s=1; s<=TotalStudents; s++)
{ for(int j=s+1; j<=TotalStudents; j++)
if(Statistics[s][0] < Statistics[j][0]){
for(int c=0; c<=Statistics_count; c++)
SwapElem(Statistics, s, j, c, c);
}
}
}
if(choice == 3){
for(int s=1; s<=TotalStudents; s++)
{ for(int j=s+1; j<=TotalStudents; j++)
if(Statistics[s][Evaluation_Count+1]>Statistics[j][Evaluation_Count+1]){
for(int c=0; c<=Statistics_count; c++)
SwapElem(Statistics, s, j, c, c);
}
}
}
if(choice == 4){
for(int s=1; s<=TotalStudents; s++)
{ for(int j=s+1; j<=TotalStudents; j++)
if(Statistics[s][Evaluation_Count+1] < Statistics[j][Evaluation_Count+1]){
for(int c=0; c<=Statistics_count; c++)
SwapElem(Statistics, s, j, c, c);
}
}
}
setColor(2);
cout << endl << "\tThe record have been sorted successfully!" << endl
<< "\tUse ViewAll(6) to view the sorted record." << endl << endl;
setColor(7);
}
void ViewAll(){
if(!isLoaded){
LoadWarn();
return;
}
cout << setprecision(4);
if(Evaluation_Count==0){
setColor(13);
cout << left << setw(4) << "----" << right << setw(18) << "-------------" << setw(17) << "-----\n"<<endl;
cout << left << setw(4) << " ID" << right << setw(18) << "Maximum Marks" << setw(17) << "Total\n"<<endl;
cout << left << setw(4) << "----" << right << setw(18) << "-------------" << setw(17) << "-----\n"<<endl;
setColor(7);
}
else{
setColor(13);
cout << left << setw(4) << "----" << right << setw(8+space_count) << "-----------" << setw(12) << "-----\n"<<endl;
cout << left << setw(4) << " ID" << right << setw(8+space_count) << "Maximum Marks" << setw(12) << "Total\n"<<endl;
cout << left << setw(4) << "----" << right << setw(8+space_count) << "-----------" << setw(12) << "-----\n"<<endl;
setColor(7);
}
for(int r=0; r<=TotalStudents; r++) // Viewing ID + Marks
{
for(int c = 0; c<=Evaluation_Count+2; c++){
if(c==0){
if(Statistics[r][c] !=0)
cout << left << setw(8) << Statistics[r][c];
else
cout << left << setw(8) << " ";
}
else if(c == Evaluation_Count+1 && Statistics[r][c] !=0) { // Total
cout << setw(11) << Statistics[r][c];
}
else if(c == Evaluation_Count+2 && Statistics[r][c] !=0){ // Weightage
cout << setfill('-') << setw(7) << Statistics[r][c] << setfill(' ');
}
else if(Statistics[r][c] !=0){ // Marks
cout << right << setw(5) << Statistics[r][c];
}
}
if((Statistics[r][0] !=0) || (r==0))
cout << endl;
if(r==0)
cout << endl;
}
cout << endl;
}
void specific_Record_show(){
if(!isLoaded){
LoadWarn();
return;
}
cout << endl << "Enter the roll no. of the student to show record: ";
int record, Statistics_count, rec;
cin >> record;
Statistics_count = Evaluation_Count+2;
for(int i=0; i<=TotalStudents; i++)
{
if(Statistics[i][0]== record)
rec = i;
}
cout << endl << "\t The record of the student specified is: " << endl << endl;
for(int c=0; c<=Statistics_count; c++)
{
if(Statistics[rec][c] !=0)
cout << Statistics[rec][c] << "\t";
}
cout << endl << endl;
}
int main()
{
int Selection = 0;
do {
Selection = presentMenu();
if (Selection == 1) {
setColor(10);
cout << endl << "Loading Data: " << endl;
setColor(7);
LoadData();
}
else if (Selection == 2) {
Save();
}
else if (Selection == 3) {
Add();
}
else if (Selection == 4) {
Delete();
}
else if (Selection == 5) {
Sort();
}
else if (Selection == 6) {
ViewAll();
}
else if (Selection == 7) {
specific_Record_show();
}
} while (Selection != 8);
return 0;
}