-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSTUDENTR.CPP
350 lines (349 loc) · 6.74 KB
/
STUDENTR.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
#include<fstream.h>
#include<iomanip.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
class student
{
int rollno;
char name[50];
int p_marks,c_marks,m_marks,cs_marks,e_marks;
float per;
char grade;
void calculate();
public:
void getdata();
void showdata();
void show_tabular();
int retrollno();
};
void student::calculate()
{
per=(p_marks+c_marks+m_marks+cs_marks+e_marks)/5;
if(per>=89.99)
grade='A1';
else if(per>=79.99)
grade='A2';
else if(per>=69.99)
grade='B1';
else if(per>=59.99)
grade='B2';
else if(per>=49.99)
grade='C1';
else if(per>=39.99)
grade='C2';
else if(per>=31.99)
grade='D';
else if(per>=19.99)
grade='E1';
else if(per>=0)
grade='E2';
}
void student::getdata()
{
cout<<"\n Enter the Roll Number of the Student: \t";
cin>>rollno;
cout<<"\n Enter the Name of the Student: \t";
gets(name);
cout<<"\n\n\t\t All the Marks are out of 100.";
cout<<"\n Enter the Marks in Physics: \t";
cin>>p_marks;
cout<<"\n Enter the Marks in Chemistry: \t";
cin>>c_marks;
cout<<"\n Enter the Marks in Mathematics: \t";
cin>>m_marks;
cout<<"\n Enter the Marks in Computer Science : \t";
cin>>cs_marks;
cout<<"\n Enter the Marks in English: \t";
cin>>e_marks;
calculate();
}
void student::showdata()
{
cout<<"\n Roll Number of Student: \t"<<rollno;
cout<<"\n Name of Student: \t"<<name;
cout<<"\n Marks in Physics: \t"<<p_marks;
cout<<"\n Marks in Chemistry: \t"<<c_marks;
cout<<"\n Marks in Mathematics: \t"<<m_marks;
cout<<"\n Marks in Computer Science: \t"<<cs_marks;
cout<<"\n Marks in English: \t"<<e_marks;
cout<<"\n Percentage of Student: \t"<<per;
cout<<"\n Grade of Student: \t"<<grade;
}
void student::show_tabular()
{
cout<<rollno<<setw(6)<<"\t"<<name<<setw(10)<<p_marks<<setw(4)<<c_marks<<setw(4)<<m_marks<<setw(4)<<cs_marks<<setw(4)<<e_marks<<setw(6)<<per<<setw(6)<<"\t"<<grade<<endl;
}
int student::retrollno()
{
return rollno;
}
void write_student();
void display_all();
void display_sp(int);
void modify_student(int);
void delete_student(int);
void class_result();
void result();
void intro();
void entry_menu();
int main()
{
char ch;
cout.setf(ios::fixed|ios::showpoint);
cout<<setprecision(2);
clrscr();
intro();
do
{
clrscr();
cout<<"\n\n\t\t\ MAIN MENU";
cout<<"\n\t 1. RESULT MENU";
cout<<"\n\t 2. ENTRY/EDIT MENU";
cout<<"\n\t 3. EXIT";
cout<<"\n\t Please Select your Option: \t";
cin>>ch;
clrscr();
switch(ch)
{
case '1':
result();
break;
case '2':
entry_menu();
break;
case '3':
exit(0);
break;
default:
cout<<"\a";
}
}
while(ch!='3');
return 0;
}
void write_student()
{
student st;
ofstream f1;
f1.open("student.dat",ios::binary|ios::app);
st.getdata();
f1.write((char*)&st,sizeof(student));
f1.close();
cout<<"\n Student Record has been Created.";
cin.ignore();
getch();
}
void display_all()
{
student st;
ifstream f2;
f2.open("student.dat",ios::binary);
if(!f2)
{
cout<<"\n File does not EXIST..!!!";
cout<<"\n Press any key to continue.";
getch();
return;
}
cout<<"\n\n\t\t DISPLAY ALL RECORDS !!! \n\n";
while(f2.read((char*)&st,sizeof(student)))
{
st.showdata();
cout<<"\n\n==================\n";
}
f2.close();
getch();
}
void display_sp(int n)
{
student st;
ifstream f2;
f2.open("student.dat",ios::binary);
if(!f2)
{
cout<<"\n File does not EXIST..!!!";
cout<<"\n Press any key to continue.";
getch();
return;
}
int flag=0;
while(f2.read((char*)&st,sizeof(student)))
{
if(st.retrollno()==n)
{
st.showdata();
flag=1;
}
}
f2.close();
if(flag==0)
cout<<"\n File does not EXIST..!!!";
cout<<"\n Press any key to continue.";
getch();
}
void modify_student(int n)
{
int found=0;
student st;
fstream f;
f.open("student.dat",ios::binary|ios::in|ios::out);
if(!f)
{
cout<<"\n File does not EXIST..!!!";
cout<<"\n Press any key to continue.";
getch();
return ;
}
while(f.read((char*)&st,sizeof(student))&&found==0)
{
if(st.retrollno()==n)
{
st.showdata();
cout<<"\n Please Enter the New Details of the Student:"<<endl;
st.getdata();
int pos=(-1)*sizeof(st);
f.seekp(pos,ios::cur);
f.write((char*)&st,sizeof(student));
cout<<"\n\t RECORD UPDATED !!!";
found=1;
}
}
f.close();
if(found==0)
cout<<"\n Record does not EXIST..!!!";
cout<<"\n Press any key to continue.";
getch();
}
void delete_student(int n)
{
student st;
ifstream f2;
f2.open("student.dat",ios::binary);
if(!f2)
{
cout<<"\n File does not EXIST..!!!";
cout<<"\n Press any key to continue.";
getch();
return;
}
ofstream f1;
f1.open("Temp.dat",ios::out);
f2.seekg(0,ios::beg);
while(f2.read((char*)&st,sizeof(student)))
{
if(st.retrollno()!=n)
{
f1.write((char*)&st,sizeof(student));
}
}
f1.close();
f2.close();
remove("student.dat");
rename("Temp.dat","student.dat");
cout<<"\n RECORD DELETED !!!";
getch();
}
void class_result()
{
student st;
ifstream f2;
f2.open("student.dat",ios::binary);
if(!f2)
{
cout<<"\n File does not EXIST..!!!";
cout<<"\n Press any key to continue.";
getch();
return;
}
cout<<"\n\n\t\t ALL STUDENTS' RESULTS !!!";
cout<<"===================================================\n";
cout<<"R.No. Name P C M CS E Percentage Grade"<endl;
cout<<"===================================================\n";
while(f2.read((char*)&st,sizeof(student)))
{
st.show_tabular();
}
getch();
f2.close();
}
void result()
{
char ch;
int rno;
cout<<"\n\n\t\t RESULT MENU";
cout<<"\n\t 1. CLASS RESULT";
cout<<"\n\t 2. STUDENT REPORT CARD";
cout<<"\n\t 3. BACK TO MAIN MENU";
cout<<"\n\t Enter your Choice \t";
cin>>ch;
switch(ch)
{
case '1':
class_result();
break;
case '2':
cout<<"\n Enter the Roll Number of the Student: \t";
cin>>rno;
display_sp(rno);
break;
case '3':
exit(0);
break;
default:
cout<<"\a";
}
}
void intro()
{
cout<<"\n\t STUDENT REPORT CARD AND DATA MANAGEMENT OF STUDENT DETAILS";
cout<<"\n Name: Santosh";
cout<<"\n Std/Div: XII/A";
cout<<"\n School: Kola Perumal Chetty Vaishnav Senior Secondary School";
getch();
}
void entry_menu()
{
char ch;
int num;
clrscr();
cout<<"\n\n\t\t ENTRY MENU";
cout<<"\n\t 1. CREATE STUDENT RECORD";
cout<<"\n\t 2. DISPLAY ALL STUDENTS' RECORDS";
cout<<"\n\t 3. SEARCH STUDENT RECORD";
cout<<"\n\t 4. MODIFY STUDENT RECORD";
cout<<"\n\t 5. DELETE STUDENT RECORD";
cout<<"\n\t 6. BACK TO MAIN MENU";
cout<<"\n\t Please Enter your Choice: \t";
cin>>ch;
switch(ch)
{
case '1':
write_student();
break;
case '2':
display_all();
break;
case '3':
cout<<"\n Enter the Roll Number of the Student: \t";
cin>>num;
display_sp(num);
break;
case '4':
cout<<"\n Enter the Roll Number of the Student: \t";
cin>>num;
modify_student(num);
break;
case '5':
cout<<"\n Enter the Roll Number of the Student: \t";
cin>>num;
delete_student(num);
break;
case '6':
exit(0);
break;
default:
cout<<"\a";
entry_menu();
}
}