-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.cpp
More file actions
377 lines (351 loc) · 8.76 KB
/
project.cpp
File metadata and controls
377 lines (351 loc) · 8.76 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
/* BY SIMRAN KATHURIA */
#include<fstream>
#include<conio.h>
#include<stdio.h>
#include<iomanip>
#include<iostream>
#include<stdlib.h>
#include<stdlib.h>
using namespace std;
void createfile(); //CREATE THE RECORD FILE
void display(); //READ ALL THE RECORDS
void displaybyroll(); //ACCEPT ROLL NUMBER AND READ RECORD
void displaybyrecno(); //ACCEPT RECORD NUMBER AND READ RECORD
void modifybyroll(); //ACCEPT RECORD AND MODIFY RECORD
void modifybyrecno(); //ACCEPT RECORD NUMBER AND MODIFY RECORD
void appendfile(); //ADD MORE RECORDS
void deletefile(); //DELETE RECORD
void intro(); //DISPLAY WELCOME SCREEN
void entry_menu(); //DISPLAY ENTRY MENU ON SCREEN
void result(); //DISPLAY RESULT MENU
void class_result(); //DISPLAY ALL RECORDS IN TABULAR FORMATE
class student
{
int rollno;
char name[50];
int phy_marks,chem_marks,maths_marks,eng_marks,cs_marks;
float per;
char grade;
void calculate();
public:
void getdata();
void showdata();
void show_table();
int retroll();
};
void student :: getdata()
{
cout<<"Enter the name of the student\n";
cin>>name;
cout<<"Enter the roll number of the student\n";
cin>>rollno;
cout<<"Enter the marks in physics\n";
cin>>phy_marks;
cout<<"Enter the marks in chemistry\n";
cin>>chem_marks;
cout<<"Enter the marks in maths\n";
cin>>maths_marks;
cout<<"Enter the marks in english\n";
cin>>eng_marks;
cout<<"Enter the marks in computer science\n";
cin>>cs_marks;
calculate();
}
void student :: showdata()
{
cout<<"\nSTUDENT NAME:"<<name;
cout<<"\nROLL NUMBER:"<<rollno;
cout<<"\nMARKS IN PHYSICS:"<<phy_marks;
cout<<"\nMARKS IN CHEMISTRY:"<<chem_marks;
cout<<"\nMARKS IN MATHS:"<<maths_marks;
cout<<"\nMARKS IN ENGLISH:"<<eng_marks;
cout<<"\nMARKS IN COMPUTER SCIENCE:"<<cs_marks;
cout<<"\nGRADE OF STUDENT:"<<grade;
}
void student :: calculate()
{
per=(phy_marks+chem_marks+eng_marks+maths_marks+cs_marks)/5;
if(per>=90)
grade='A+';
else if(per>=80)
grade='A';
else if(per>=70)
grade='B+';
else if(per>=60)
grade='B';
else if(per>=50)
grade='C+';
else if(per>=40)
grade='C';
else
grade='F';
}
void student :: show_table()
{
cout<<"\t"<<rollno<<setw(14)<<name<<setw(8)<<phy_marks<<setw(6)<<chem_marks<<setw(5)<<maths_marks<<setw(5)<<eng_marks<<setw(5)<<cs_marks<<setw(6)<<per<<setw(6)<<" "<<grade<<endl;
}
int student :: retroll()
{
return rollno;
}
//FUNCTION TO CREATE FILE
void createfile ()
{
fstream file;
char ch;
student s;
int num=1;
file.open("student.dat",ios::out|ios::binary);
do
{
cout<<"Enter the details for student "<<num<<endl<<endl;
s.getdata();
file.write((char*)&s,sizeof(s));
num++;
cout<<"Want more records.....\n";
cin>>ch;
cout<<"\n\nStudents Records Has Been Created\n";
system("cls");
}
while(ch=='y'|| ch=='Y');
file.close();
}
//FUNCTION TO DISPLAY ALL THE RECORDS
void display()
{
fstream file;
student s;
file.open("student.dat",ios::in|ios::binary);
cout<<"Displaying all the records\n\n";
while(file.read((char*)&s,sizeof(s)))
{
s.showdata();
cout<<"\n\n-----------------------------------------------\n";
}
file.close();
}
//FUNCTION TO DISPLAY SPECIFIC RECORD (BY ROLL NUMBER)
void displaybyroll()
{
fstream file;
student s;
int roll,flag=0;
cout<<"\nEnter the roll number of the student you want to search for\n";
cin>>roll;
file.open("student.dat",ios::in|ios::binary);
while(file.read((char*)&s,sizeof(s)))
{
if(roll==s.retroll())
{
s.showdata();
flag=1;
break;
}
}
file.close();
if(flag==0)
cout<<"Record not found\n";
}
//FUNCTION TO MODIFY THE RECORD (BY ROLL NUMBER)
void modifybyroll()
{
fstream file;
student s;
int roll,flag=0;
cout<<"Enter the roll number of the student to want to edit\n";
cin>>roll;
file.open("student.dat",ios::in|ios::out|ios::binary);
while(file.read((char*)&s,sizeof(s)))
{
if(s.retroll()==roll)
{
file.seekp(file.tellg()-sizeof(s),ios::beg);
s.getdata();
file.write((char*)&s,sizeof(s));
flag=1;
cout<<"\n\nRecord Updated\n";
}
}
file.close();
if(flag==0)
cout<<"Record not found\n";
}
//FUNCTION TO MODIFY THE RECORD (BY RECORD NUMBER)
void modifybyrecno()
{
fstream file;
student s;
int recno;
cout<<"Enter the record number you want to modify\n";
cin>>recno;
file.open("student.dat",ios::out|ios::in|ios::binary);
file.seekg(sizeof(s)*(recno-1),ios::beg);
s.getdata();
file.write((char*)&s,sizeof(s));
file.close();
cout<<"\n\nRecord Updated....\n";
}
//FUNCTION TO ADD MORE RECORDS
void appendfile()
{
fstream file;
student s;
char ch;
file.open("student.dat",ios::app|ios::binary);
do
{
s.getdata();
file.write((char*)&s,sizeof(s));
cout<<"Want more records\n";
cin>>ch;
system("cls");
}
while(ch=='y'|| ch=='Y') ;
file.close();
cout<<"\n\nRecord Has Been Added\n";
}
//FUNCTION TO DELETE THE RECORD
void deletefile()
{
fstream file1,file2;
student s;
int rno;
cout<<"Enter the roll number\n";
cin>>rno;
file1.open("student.dat",ios::in|ios::binary);
file2.open("temp.dat",ios::out|ios::binary);
while(file1.read((char*)&s,sizeof(s)))
{
if(s.retroll()!=rno)
file2.write((char*)&s,sizeof(s));
}
file1.close();
file2.close();
file1.open("student.dat",ios::out|ios::binary);
file2.open("temp.dat",ios::in|ios::binary);
while(file2.read((char*)&s,sizeof(s)))
{
file1.write((char*)&s,sizeof(s));
}
file1.close();
file2.close();
cout<<"\n\nRecord Deleted....\n";
}
//FUNCTION TO DISPLAY THE SPECIFIC RECORD (BY RECORD NUMBER)
void displaybyrecno()
{
fstream file;
student s;
int recno,flag=0;
cout<<"Enter the record number you want to search for\n";
cin>>recno;
file.open("student.dat",ios::in|ios::binary);
file.seekg(sizeof(s)*(recno-1),ios::beg);
if(file.read((char*)&s,sizeof(s)))
{
s.showdata();
flag=1;
}
if(flag==0)
cout<<"Record not found\n";
file.close();
}
//THE MAIN FUNCTION OF THE PROGRAM
int main()
{
system("cls");
int ch;
intro();
do
{
cout<<"\n========================MENU===========================\n";
cout<<"1.RESULT MENU\n";
cout<<"2.ENTRY/EDIT MENU\n";
cout<<"3.EXIT\n";
cout<<"\nplease select your option\n";
cin>>ch;
switch(ch)
{
case 1 : result();break;
case 2 : entry_menu();break;
case 3 : break;
default : cout<<"\a";
}
}while(ch!=3);
return 0;
}
//FUNCTION TO DISPLAY RESULT MENU
void result()
{
system("cls");
int ch;
cout<<"\n========================RESULT MENU=========================\n";
cout<<"1.CLASS RESULT\n";
cout<<"2.STUDENT REPORT CARD\n";
cout<<"3.BACK TO MAIN MENU\n";
cout<<"\nplease enter your option\n";
cin>>ch;
system("cls");
switch(ch)
{
case 1 : class_result();break;
case 2 : displaybyroll();break;
case 3 : break;
default : cout<<"\a";result();
}
}
//FUNCTION TO DISPLAY THE CLASS RESULT
void class_result()
{
student s;
fstream file;
file.open("student.dat",ios::in|ios::binary);
cout<<"\n\t------------------------__CLASS RESULT__---------------------------\n";
cout<<"\t==============================================================\n";
cout<<"\tR.no NAME P C M E CS %age Grade"<<endl;
cout<<"\t==============================================================\n";
while(file.read((char*)&s,sizeof(s)))
{
s.show_table();
}
file.close();
}
//INTRODUCTION FUNCTION
void intro()
{
cout<<"\t\t\t\tSTUDENT REPORT CARD";
cout<<"\n\n\t\t\t\t PROJECT";
cout<<"\n\n\n\t\t\t MADE BY:SIMRAN KATHURIA";
cout<<"\n\n\t\t\t SCHOOL : HANS RAJ MODEL SCHOOL\n\n";
}
//FUNCTION TO DISPLAY ENTRY/EDIT MENU
void entry_menu()
{
int ch;
system("cls");
cout<<"\n=============================EDIT MENU==============================\n";
cout<<"1.CREATE STUDENT RECORD\n";
cout<<"2.DISPLAY ALL THE RECORDS\n";
cout<<"3.MODIFY THE RECORD BY ROLL NUMBER\n";
cout<<"4.MODIFY THE RECORD BY RECORD NUMBER\n";
cout<<"5.ADD MORE RECORD\n";
cout<<"6.DELETE THE RECORD\n";
cout<<"7.DISPLAY RECORDS BY RECORD NUMBER\n";
cout<<"8.BACK TO MAIN MENU\n";
cout<<"\nplease enter your option\n";
cin>>ch;
system("cls");
switch(ch)
{
case 1 : createfile();break;
case 2 : display();break;
case 3 : modifybyroll();break;
case 4 : modifybyrecno();break;
case 5 : appendfile();break;
case 6 : deletefile();break;
case 7 : displaybyrecno();break;
case 8 : break;
default : cout<<"\a";
entry_menu();
}
}