-
Notifications
You must be signed in to change notification settings - Fork 4
/
ass1.cpp
500 lines (464 loc) · 12.7 KB
/
ass1.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
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
//Assingment-1 First part
//Submitted by Shubham Agrawal
// 19UCS073
#include<bits/stdc++.h>
using namespace std;
struct student
{
int id;
string name;
string branch;
};
struct marks
{
int id;
double dbms,ds,c,total;
double percent;
};
map<int,student>mp;
map<int,marks>mk;
map<int,student>::iterator itr;
student newenrty();
student modifyname(student input);
student modifybranch(student input);
void search_branchwise(string s);
void search_namewise(string s);
student newentry()
{
student input;
int i;
string n,b;
cout<<"Enter student id::";
cin>>i;
while(mp.find(i)!=mp.end())
{
cout<<"\nEntry is already present try whith a new one"<<endl;
cout<<"Enter student id::";
cin>>i;
}
cout<<"\nEnter name of student::";
cin>>n;
cout<<"\nEnter branch of student::";
cin>>b;
cout<<endl;
input.id=i;
input.name=n;
input.branch=b;
return input;
}
student modifyname(student input)
{
cout<<"Enter name to be updated::";
string s;
cin>>s;
cout<<"\n"<<input.name<<" is changed to "<<s;
input.name=s;
return input;
//fwrite(&input,sizeof(student),1,out);
}
student modifybranch(student input)
{
cout<<"Enter branch to be updated::";
string s;
cin>>s;
cout<<"\n"<<input.branch<<" is changed to"<<s;
input.branch=s;
//fwrite(&input,sizeof(student),1,out);
return input;
}
void search_branchwise(string s)
{
int flag=0;
for(auto i:mp)
{
if(i.second.branch==s)
{
if(!flag)
{
cout<<"STUDENT DETAILS::"<<endl;
cout<<"ID\t\tNAME\t\tBRANCH"<<endl;
flag=1;
}
cout<<i.second.id<<"\t\t"<<i.second.name<<"\t\t"<<i.second.branch<<endl;
}
}
}
void search_namewise(string s)
{
int flag=0;
for(auto i:mp)
{
if(i.second.name==s)
{
if(!flag)
{
cout<<"STUDENT DETAILS::"<<endl;
cout<<"ID\t\tNAME\t\tBRANCH"<<endl;
flag=1;
}
cout<<i.second.id<<"\t\t"<<i.second.name<<"\t\t"<<i.second.branch<<endl;
}
}
}
void updatemarks(int id)
{
cout<<"Enter subject of which marks to be updated(all letters in small case)::";
string s;
cin>>s;
int f=0;
if(s=="dbms")
{
f=1;
int marks;
cout<<"\nEnter new marks in DBMS::";
cin>>marks;
while(marks>100)
{
cout<<"\nMarks cannot exceed 100 enter marks again"<<endl;
cin>>marks;
}
mk[id].dbms=marks;
cout<<"\nMarks updated"<<endl;
}
else if(s=="ds")
{
f=1;
int marks;
cout<<"\nEnter new marks in DS::";
cin>>marks;
while(marks>100)
{
cout<<"\nMarks cannot exceed 100 enter marks again"<<endl;
cin>>marks;
}
mk[id].ds=marks;
cout<<"\nMarks updated"<<endl;
}
else if(s=="c")
{
f=1;
int marks;
cout<<"\nEnter new marks in C::";
cin>>marks;
while(marks>100)
{
cout<<"\nMarks cannot exceed 100 enter marks again"<<endl;
cin>>marks;
}
mk[id].c=marks;
cout<<"\nMarks updated"<<endl;
}
mk[id].total=mk[id].c+mk[id].dbms+mk[id].ds;
mk[id].percent=mk[id].total/3;
if(f==0)
{
cout<<"\nEnter correct subject"<<endl;
updatemarks(id);
return;
}
}
int main()
{
//FILE *out;
//out=fopen("data.txt","w");
ifstream indata;
indata.open("students.txt");
if(!indata)
{
cout<<"FILE cannot be opend"<<endl;
return 0;
}
int x;
while(indata>>x)
{
student ind;
ind.id=x;
indata>>ind.name;
indata>>ind.branch;
mp[x]=ind;
}
indata.close();
ofstream outdata;
outdata.open("students.txt");
if(!outdata)
{
cout<<"Students FILE cannot be opend"<<endl;
return 0;
}
int choice;
do
{
cout<<endl;
cout<<"-----------------Entry MENU-----------------\n";
cout<<"For a new entry press 1"<<endl<<"For modification of Name press 2"<<endl;
cout<<"For modification in Branch press 3"<<endl;
cout<<"Delete student data press 4"<<endl;
cout<<"Search branchwise press 5"<<endl;
cout<<"Search by name press 6"<<endl;
cout<<"To Enter marks of given entries press 7\n"<<endl;
cout<<"Enter your choice:: ";
cin>>choice;
cout<<endl;
student input;
student *in;
in=NULL;
switch (choice)
{
case 1:
{
input=newentry();
mp[input.id]=input;
//fwrite(&input,sizeof(student),1,out);
break;
}
case 2:
{
cout<<"Enter student id whose name to be modify::";
int id;
cin>>id;
if(mp.find(id)==mp.end())
{
cout<<"No such id found"<<endl;
break;
}
else
{
input=mp[id];
mp[id]=modifyname(input);
}
break;
}
case 3:
{
cout<<"Enter student id whose branch to be modify::";
int id;
cin>>id;
if(mp.find(id)==mp.end())
{
cout<<"No such id found"<<endl;
break;
}
else
{
input=mp[id];
mp[id]=modifybranch(input);
}
break;
}
case 4:
{
int id;
cout<<"Enter id which has to be deleted::";
cin>>id;
if(mp.find(id)==mp.end())
{
cout<<"No such id found"<<endl;
break;
}
else
{
mp.erase(id);
cout<<"Student id::"<<id<<" has been deleted"<<endl;
}
break;
}
case 5:
{
string s;
cout<<"Enter branch to be searched"<<endl;
cin>>s;
search_branchwise(s);
break;
}
case 6:
{
string s;
cout<<"Enter name to be searched"<<endl;
cin>>s;
search_namewise(s);
break;
}
case 7:
break;
default:
{
cout<<"Incorrect option selected"<<endl;
break;
}
}
}while (choice!=7);
//outdata<<"ID\t\tNAME\t\tBRANCH"<<endl;
for(auto i:mp)
{
outdata<<i.second.id<<"\t\t"<<i.second.name<<"\t\t"<<i.second.branch<<endl;
}
//outdata.close();
ofstream out;
out.open("marks.txt");
if(!out)
{
cout<<" Marks FILE cannot be opend"<<endl;
return 0;
}
cout<<"Insert marks of all students"<<endl;
for(auto i:mp)
{
marks temp;
cout<<"Enter marks of student id:: "<<i.first<<" "<<i.second.name<<endl;
cout<<"Marks in DBMS::";
cin>>temp.dbms;
while(temp.dbms>100)
{
cout<<"\nMarks cannot exceed 100 Please re-enter marks in DBMS::";
cin>>temp.dbms;
}
cout<<"\nMarks in DS::";
cin>>temp.ds;
while(temp.ds>100)
{
cout<<"\nMarks cannot exceed 100 Please re-enter marks in DS::";
cin>>temp.ds;
}
cout<<"\nMarks in C::";
cin>>temp.c;
while(temp.c>100)
{
cout<<"\nMarks cannot exceed 100 Please re-enter marks in C::";
cin>>temp.c;
}
temp.total=temp.dbms+temp.ds+temp.c;
temp.percent=(temp.total*100)/300;
cout<<"Total marks obtained:: "<<temp.total<<" out of 300 \t\tPercentage:: "<<temp.percent*1.0<<"%\n"<<endl;
mk[i.first]=temp;
}
int ch;
do
{
double h;
cout<<"\n----------------Marks MENU----------------\n";
cout<<"Press 1 for upate marks in one of the subject of student"<<endl;
cout<<"Press 2 to delete student record from data\n";
cout<<"Press 3 for list of marks by student ID\n";
cout<<"Press 4 to search the student with above percentage threshold"<<endl;
cout<<"Press 5 to search the students of a particular BRANCH with PERCENTAGE above a threshold"<<endl;
cout<<"Press 6 to exit from program\n";
cout<<"ENTER YOUR OPTION::";
cin>>ch;
cout<<endl;
switch (ch)
{
case 1:
{
int id;
cout<<"Enter student ID of which marks to be updated:: ";
cin>>id;
if(mk.find(id)==mk.end())
{
cout<<"\nNO such ID found\n";
break;
}
updatemarks(id);
break;
}
case 2:
{
cout<<"\nEnter student ID to be deleted::";
int id;
cin>>id;
if(mk.find(id)==mk.end())
{
cout<<"\nNO such ID found\n";
break;
}
mk.erase(id);
mp.erase(id);
cout<<"\nID deleted\n";
break;
}
case 3:
{
cout<<"Enter student ID"<<endl;
int id;
cin>>id;
if(mk.find(id)==mk.end())
{
cout<<"\nNO such ID found\n";
break;
}
cout<<"MARKS OF ::"<<mp[id].name<<endl;
cout<<"DBMS\t\tDS\t\tC\t\tTOTAL\t\tPERCENTAGE"<<endl;
cout<<mk[id].dbms<<"\t\t"<<mk[id].ds<<"\t\t"<<mk[id].c<<"\t\t"<<mk[id].total<<"\t\t"<<mk[id].percent*1.0<<endl;
break;
}
case 4:
{
cout<<"Set a threshold percentage::";
cin>>h;
int f=1;
for(auto i:mk)
{
if(i.second.percent>h)
{
if(f==1)
{
f=0;
cout<<"\nID\t\tNAME\t\tBRANCH\t\tPERCENTAGE"<<endl;
}
cout<<i.first<<"\t\t"<<mp[i.first].name<<"\t\t"<<mp[i.first].branch<<"\t\t"<<i.second.percent<<endl;
}
}
if(f==1)
{
cout<<"\nNo such student found\n";
}
break;
}
case 5:
{
cout<<"Enter branch::";
string s;
cin>>s;
cout<<endl;
cout<<"Set a threshold percentage::";
cin>>h;
int f=1;
for(auto i:mk)
{
int id=i.first;
if(i.second.percent>h&&mp[i.first].branch==s)
{
if(f==1)
{
f=0;
cout<<"\nID\t\tNAME\t\tBRANCH\t\tPERCENTAGE"<<endl;
}
cout<<i.first<<"\t\t"<<mp[id].name<<"\t\t"<<mp[id].branch<<"\t\t"<<i.second.percent*1.0<<"%"<<endl;
}
}
if(f==1)
{
cout<<"\nNo such student found\n";
}
break;
}
case 6:
{
break;
}
default:
cout<<"Choose correct option from menu\n";
break;
}
} while (ch!=6);
for(auto i:mp)
{
outdata<<i.second.id<<"\t\t"<<i.second.name<<"\t\t"<<i.second.branch<<endl;
}
out<<"ID\t\tMARKS IN DBMS\t\tMARKS IN DS\t\tMARKS IN C\t\tTOTAL MARKS\t\tPERCENTAGE\n";
for(auto i:mk)
{
out<<i.first<<"\t\t"<<i.second.dbms<<"\t\t"<<i.second.ds<<"\t\t"<<i.second.c<<"\t\t"<<i.second.total<<"\t\t"<<i.second.percent*1.00<<"%\n";
}
cout<<endl;
return 0;
}