-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsrms.cc
More file actions
281 lines (242 loc) · 6.21 KB
/
Copy pathsrms.cc
File metadata and controls
281 lines (242 loc) · 6.21 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
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
// the class that stores data
class student
{
int rollno;
char name[50];
int eng_marks, math_marks, sci_marks, lang2_marks, cs_marks;
double average;
char grade;
public:
void getdata();
void showdata() const;
void calculate();
int retrollno() const;
};
//class ends here
void student::calculate()
{
average=(eng_marks+math_marks+sci_marks+lang2_marks+cs_marks)/5.0;
if(average>=90)
grade='A';
else if(average>=75)
grade='B';
else if(average>=50)
grade='C';
else
grade='F';
}
void student::getdata()
{
cout<<"Enter student's roll number: ";
cin>>rollno;
cout<<"Enter student's name: ";
cin.ignore();
cin.getline(name,50);
cout<<"\n\nEnter Student's Marks"<<endl;
cout<<"All marks should be out of 100";
cout<<"\n\nEnter marks in English: ";
cin>>eng_marks;
cout<<"Enter marks in Math: ";
cin>>math_marks;
cout<<"Enter marks in Science: ";
cin>>sci_marks;
cout<<"Enter marks in Second language: ";
cin>>lang2_marks;
cout<<"Enter marks in Computer science: ";
cin>>cs_marks;
calculate();
}
void student::showdata() const
{
cout<<"\nRoll number of student : "<<rollno;
cout<<"\nName of student : "<<name;
cout<<"\nEnglish : "<<eng_marks;
cout<<"\nMaths : "<<math_marks;
cout<<"\nScience : "<<sci_marks;
cout<<"\nSecond Language : "<<lang2_marks;
cout<<"\nComputer Science :"<<cs_marks;
cout<<"\nAverage Marks :"<<average;
cout<<"\nGrade of student is :"<<grade;
}
int student::retrollno() const
{
return rollno;
}
//function declaration
void create_student();
void display_sp(int);//display particular record
void display_all(); // display all records
void delete_student(int);//delete particular record
void change_student(int);//edit particular record
//Main Function
int main()
{
char ch;
cout<<setprecision(2);
do
{
char ch;
int num;
system("cls");
cout<<"Welcome to Student Registration Management System"<<endl;
cout<<"\nMENU"<<endl;
cout<<"\n1. Create a newstudent record"<<endl;
cout<<"2. Search student record"<<endl;
cout<<"3. Display all students records"<<endl;
cout<<"4. Delete student record"<<endl;
cout<<"5. Modify student record"<<endl;
cout<<"6. Exit"<<endl;
cout<<"\nEnter your choice"<<endl;
cin>>ch;
system("cls");
switch(ch)
{
case '1': create_student(); break;
case '2': cout<<"\n\n\tEnter The roll number: ";
cin>>num;
display_sp(num); break;
case '3': display_all(); break;
case '4': cout<<"\n\n\tEnter The roll number: ";
cin>>num;
delete_student(num);break;
case '5': cout<<"\n\n\tEnter The roll number: "; cin>>num;
change_student(num);break;
case '6': cout<<"Exiting, Thank you!";exit(0);
}
}while(ch!='6');
return 0;
}
//Write Student Details to File
void create_student()
{
student stud;
ofstream oFile;
oFile.open("student.dat",ios::binary|ios::app);
stud.getdata();
oFile.write(reinterpret_cast<char *> (&stud), sizeof(student));
oFile.close();
cout<<"\nStudent's record has been created ";
cin.ignore();
cin.get();
}
// Read File Records
void display_all()
{
student stud;
ifstream inFile;
inFile.open("student.dat",ios::binary);
if(!inFile)
{
cout<<"File could not be opened !! Press any Key to exit";
cin.ignore();
cin.get();
return;
}
cout<<"\n\n\n\t\tDISPLAYING ALL RECORDS\n\n";
while(inFile.read(reinterpret_cast<char *> (&stud), sizeof(student)))
{
stud.showdata();
cout<<"\n\n====================================\n";
}
inFile.close();
cin.ignore();
cin.get();
}
//Read Specific Record Based on Roll Number
void display_sp(int n)
{
student stud;
ifstream iFile;
iFile.open("student.dat",ios::binary);
if(!iFile)
{
cout<<"File could not be opened... Press any Key to exit";
cin.ignore();
cin.get();
return;
}
bool flag=false;
while(iFile.read(reinterpret_cast<char *> (&stud), sizeof(student)))
{
if(stud.retrollno()==n)
{
stud.showdata();
flag=true;
}
}
iFile.close();
if(flag==false)
cout<<"\n\nrecord does not exist";
cin.ignore();
cin.get();
}
// Modify Record for Specified Roll Number
void change_student(int n)
{
bool found=false;
student stud;
fstream fl;
fl.open("student.dat",ios::binary|ios::in|ios::out);
if(!fl)
{
cout<<"File could not be opened. Press any Key to exit...";
cin.ignore();
cin.get();
return;
}
while(!fl.eof() && found==false)
{
fl.read(reinterpret_cast<char *> (&stud), sizeof(student));
if(stud.retrollno()==n)
{
stud.showdata();
cout<<"\nEnter new student details:"<<endl;
stud.getdata();
int pos=(-1)*static_cast<int>(sizeof(stud));
fl.seekp(pos,ios::cur);
fl.write(reinterpret_cast<char *> (&stud), sizeof(student));
cout<<"\n\n\t Record Updated";
found=true;
}
}
fl.close();
if(found==false)
cout<<"\n\n Record Not Found ";
cin.ignore();
cin.get();
}
//Delete Record with Particular Roll Number
void delete_student(int n)
{
student stud;
ifstream iFile;
iFile.open("student.dat",ios::binary);
if(!iFile)
{
cout<<"File could not be opened... Press any Key to exit...";
cin.ignore();
cin.get();
return;
}
ofstream oFile;
oFile.open("Temp.dat",ios::out);
iFile.seekg(0,ios::beg);
while(iFile.read(reinterpret_cast<char *> (&stud), sizeof(student)))
{
if(stud.retrollno()!=n)
{
oFile.write(reinterpret_cast<char *> (&stud), sizeof(student));
}
}
oFile.close();
iFile.close();
remove("student.dat");
rename("Temp.dat","student.dat");
cout<<"\n\n\tRecord Deleted ..";
cin.ignore();
cin.get();
}