-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadminFunction.h
551 lines (432 loc) · 13.3 KB
/
adminFunction.h
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
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
#include <fstream>
#include <string.h>
#include <bits/stdc++.h>
#include <string>
#include <Windows.h>
#include <stdlib.h>
using namespace std;
void addData(void);
void viewData(void);
void mainMenu(void);
//void updateData(void);
void deleteData(void);
void adminVerification(void);
void studentFunction(void);
void adminFunction()
{
system("cls");
cout << "\n\n\t\t\t\t\t | Logged In as Admin |\n";
cout << "\n\n\t\t\t\t\t 1. Add Students Detail";
cout << "\n\n\t\t\t\t\t 2. Delete Students";
//cout << "\n\n\t\t\t\t\t 3. update Record";
cout << "\n\n\t\t\t\t\t 4. View Table ";
cout << "\n\n\t\t\t\t\t 5. Main Menu ";
cout << "\n\n\t\t\t\t\t 6. Exit";
int option;
cout << "\n\n\t\t\t\t\tEnter choice : ";
do
{
cin >> option;
{
switch (option)
{
case 1:
addData();
break;
case 2:
deleteData();
break;
case 3:
cout << "this option is not available"; //updateData();
break;
case 4:
viewData();
break;
case 5:
mainMenu();
break;
case 6:
system("cls");
cout << "\t\t\n\n\n\n\n\n\n\t\t\t\t\tQuitting The Program";
for (int i = 0; i < 4; i++)
{
Sleep(1000);
cout << ".";
}
exit(0);
break;
default:
system("cls");
cout << "\n\n\t\t\t\t\t Logged In as Admin";
cout << "\n\n\t\t\t\t\t 1. Add Students Record";
cout << "\n\n\t\t\t\t\t 2. Delete Record";
// cout << "\n\n\t\t\t\t\t 3. update Record";
cout << "\n\n\t\t\t\t\t 4. View Table ";
cout << "\n\n\t\t\t\t\t 5. Main Menu ";
cout << "\n\n\t\t\t\t\t 6. Exit";
cout << "\n\n\t\t\t\t\t invalid input!";
cout << "\n\n\t\t\t\t\t Enter choice : ";
}
}
} while (option != '6');
}
void mainMenu()
{
system("cls");
cout << "\n\n\n\n\t\t\t\t\t Login As : ";
cout << "\n\n\n\t\t\t\t\t 1. Admin ";
cout << "\n\n\t\t\t\t\t 2. Student";
cout << "\n\n\t\t\t\t\t 3. Exit";
cout << "\n\n\n\t\t\t\t\t Enter your choice : ";
int choice;
cin >> choice;
switch (choice)
{
case 1:
adminVerification();
break;
case 2:
system("cls");
cout << "Welcom as Student";
studentFunction();
break;
case 3:
system("cls");
cout << "\t\t\n\n\n\n\n\n\n\t\t\t\t\tQuitting The Program";
for (int i = 0; i < 4; i++)
{
Sleep(1000);
cout << ".";
}
exit(0);
break;
default:
cout << "invalid input";
}
system("pause");
}
// all Functions for Admin below
void deleteData()
{
system("cls");
// Open FIle pointers
fstream fin, fout;
// Open the existing file
fin.open("data.csv", ios::in);
// Create a new file to store the non-deleted data
fout.open("datanew.csv", ios::out);
int rollnum, roll1, marks, count = 0, i;
char sub;
int index, new_marks;
string line, word;
vector<string> row;
// Get the roll number
// to decide the data to be deleted
cout << "Enter the roll number "
<< "of the record to be deleted: ";
cin >> rollnum;
// Check if this record exists
// If exists, leave it and
// add all other data to the new file
while (!fin.eof())
{
row.clear();
getline(fin, line);
stringstream s(line);
while (getline(s, word, ','))
{
row.push_back(word);
}
int row_size = row.size();
roll1 = stoi(row[0]);
// writing all records,
// except the record to be deleted,
// into the new file 'reportcardnew.csv'
// using fout pointer
if (roll1 != rollnum)
{
if (!fin.eof())
{
for (i = 0; i < row_size - 1; i++)
{
fout << row[i] << ",";
}
fout << row[row_size - 1] << "\n";
}
}
else
{
count = 1;
}
if (fin.eof())
break;
}
if (count == 1)
cout << "Record deleted\n";
else
cout << "Record not found\n";
// Close the pointers
fin.close();
fout.close();
// removing the existing file
remove("data.csv");
// renaming the new file with the existing file name
rename("datanew.csv", "data.csv");
Sleep(2000);
adminFunction();
}
/*
void updateData()
{
system("cls");
cout << "in update function\n";
// File pointer
fstream fin, fout;
// Open an existing record
fin.open("data.csv", ios::in);
// Create a new file to store updated data
fout.open("datanew.csv", ios::out);
int rollnum, roll1, marks, count = 0, i;
char sub;
int index;
string new_marks;
string line, word;
vector<string> row;
// Get the roll number from the user
cout << "Enter the roll number "
<< "of the record to be updated: ";
cin >> rollnum;
// Get the data to be updated
cout << "Enter the first letter fo the Fields (Eg. b for branch & G for college)"
<< "to be updated(N/G/B/A/P/C/M): ";
cin >> sub;
// Determine the index of the subject
// where Maths has index 7,
// Physics has index 6, and so on
if (sub == 'n' || 'N')
index = 1;
else if (sub == 'g' || sub == 'G')
index = 2;
else if (sub == 'b' || sub == 'B')
index = 3;
else if (sub == 'a' || sub == 'A')
index = 4;
else if (sub == 'p' || sub == 'P')
index = 5;
else if (sub == 'c' || sub == 'C')
index = 6;
else if (sub == 'm' || sub == 'M')
index = 7;
else
{
cout << "Wrong choice.Enter again\n";
updateData();
}
// Get the new marks
cout << "Enter new Detail: ";
cin >> new_marks;
// Traverse the file
while (!fin.eof())
{
row.clear();
getline(fin, line);
stringstream s(line);
while (getline(s, word, ','))
{
row.push_back(word);
}
roll1 = stoi(row[0]);
int row_size = row.size();
if (roll1 == rollnum)
{
count = 1;
stringstream convert;
// sending a number as a stream into output string
convert << new_marks;
// the str() converts number into string
row[index] = convert.str();
if (!fin.eof())
{
for (i = 0; i < row_size - 1; i++)
{
// write the updated data
// into a new file 'reportcardnew.csv'
// using fout
fout << row[i] << ", ";
}
fout << row[row_size - 1] << "\n";
}
}
else
{
if (!fin.eof())
{
for (i = 0; i < row_size - 1; i++)
{
// writing other existing records
// into the new file using fout.
fout << row[i] << ", ";
}
// the last column data ends with a '\n'
fout << row[row_size - 1] << "\n";
}
}
if (fin.eof())
break;
}
if (count == 0)
cout << "Record not found\n";
fin.close();
fout.close();
// removing the existing file
remove("data.csv");
// renaming the updated file with the existing file name
rename("datadnew.csv", "data.csv");
}
*/
void addData()
{
system("cls");
fstream file("data.csv", ios::out | ios::app);
if (!file)
{
cout << "\nFailed to open data.csv / data.csv file not found!";
}
else
cout << "\t|Enter Data|" << endl
<< endl;
string rollNumber, name, college, branch, attendance, physics, chemistry, maths;
string moreData;
cout << "\nEnter Student's roll Number : ";
cin >> rollNumber;
file << "\n"
<< rollNumber << ", ";
cout << "\nEnter Studnet's Name : ";
cin >> name;
file << name << ", ";
cout << "\nEnter College : ";
cin >> college;
file << college << ", ";
cout << "\nEnter Branch : ";
cin >> branch;
file << branch << ", ";
cout << "\nEnter Attendance : ";
cin >> attendance;
file << attendance << ", ";
cout << "\nEnter Physic's Marks : ";
cin >> physics;
file << physics << ", ";
cout << "\nEnter Chemistry Marks : ";
cin >> chemistry;
file << chemistry << ", ";
cout << "\nEnter Maths Marks : ";
cin >> maths;
file << maths;
file.close();
cout << "\nAdd more Record? (Y / N) : ";
cin >> moreData;
if (moreData == "y" || moreData == "Y" || moreData == "yes" || moreData == "Yes")
{
addData();
}
else if (moreData == "n" || moreData == "N" || moreData == "no" || moreData == "No")
adminFunction();
else
cout << "\nEnter a valid option";
adminFunction();
}
void viewData()
{
system("cls");
fstream file("data.csv");
if (!file)
{
cout << "fail in opening the file";
}
cout << "\n\t\t\t\t\t\t|Students Record| \n\n";
cout << "\n-----------------------------------------------------------------------------------------------------------------------\n"
<< endl
<< endl;
cout << "Roll \t Name \t\t\t College \t branch \t Attendance \t Physics \t Chemistry \t Maths" << endl
<< endl;
string rollNumber, name, college, branch, attendance, physics, chemistry, maths;
while (!file.eof()) // file.eof() = detects as how long the f
{
getline(file, rollNumber, ',');
getline(file, name, ',');
getline(file, college, ',');
getline(file, branch, ',');
getline(file, attendance, ',');
getline(file, physics, ',');
getline(file, chemistry, ',');
getline(file, maths, '\n');
cout << rollNumber << " \t " << name << "\t\t\t" << college << " \t\t" << branch << " \t\t" << attendance << " \t\t" << physics << " \t\t" << chemistry << " \t\t" << maths << endl;
cout << endl;
}
cout << "\n-----------------------------------------------------------------------------------------------------------------------" << endl;
file.close();
cout << "\n\n 1. Add Record\n";
cout << " 2. Delete Record\n";
cout << " 3. Update Record\n";
cout << " 5. Main Menu\n";
cout << " 6. Exit\n";
cout << "\nEnter choice : ";
// adminFunction();
}
void adminVerification()
{
system("cls");
string password;
cout << "\n\n\n\n\n\t\t\t\t\t";
cout << "\n\n\n\t\t\t\t\tEnter Password : ";
do
{
cin >> password;
if (password != "password")
{
system("cls");
cout << "\n\n\n\n\n\t\t"
<< "wrong password!, try again or type 'menu' to Navigate to Main Menu";
cout << "\n\n\n\t\t\t\t\tEnter Password : ";
}
if (password == "Menu" || password == "menu" || password == "MENU")
{
mainMenu();
}
}
while (password != "password");
adminFunction(); // main menu function is in the Header File adminFunction.h
}
void studentFunction()
{
system("cls");
fstream file("data.csv");
if (!file)
{
cout << "fail in opening the file";
}
cout << "\n\t\t\t\t\t\t|Students Record| \n\n";
cout << "\n-----------------------------------------------------------------------------------------------------------------------\n"
<< endl
<< endl;
cout << "Roll \t Name \t\t\t College \t branch \t Attendance \t Physics \t Chemistry \t Maths" << endl
<< endl;
string rollNumber, name, college, branch, attendance, physics, chemistry, maths;
while (!file.eof()) // file.eof() = detects as how long the f
{
getline(file, rollNumber, ',');
getline(file, name, ',');
getline(file, college, ',');
getline(file, branch, ',');
getline(file, attendance, ',');
getline(file, physics, ',');
getline(file, chemistry, ',');
getline(file, maths, '\n');
cout << rollNumber << " \t " << name << "\t\t\t" << college << " \t\t" << branch << " \t\t" << attendance << " \t\t" << physics << " \t\t" << chemistry << " \t\t" << maths << endl;
cout << endl;
}
cout << "\n-----------------------------------------------------------------------------------------------------------------------" << endl;
file.close();
system("pause");
mainMenu();
}