-
Notifications
You must be signed in to change notification settings - Fork 2
/
StudentMS.cpp
323 lines (317 loc) · 10.4 KB
/
StudentMS.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
// Student Management System With File Handing In C++
/*
Created By- Sagar Developer
*/
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <fstream>
#include <stdlib.h>
#include <cstdlib>
#include <string>
#include <string_view>
#include <regex>
using namespace std;
// Email Vaildation Pattern
bool Emailcheck(string email)
{
const regex pattern("(\\w+)(\\.|_)?(\\w*)@(\\w+)(\\.(\\w+))+");
return regex_match(email, pattern);
}
class student
{
private:
string name, roll_no, course, address, email_id;
long long int contact_no;
public:
void menu();
void insert();
void display();
void modify();
void search();
void deleted();
};
// Project Menu
void student::menu()
{
menustart:
int choice;
char x;
system("cls");
cout << "\t\t\t-----------------------------" << endl;
cout << "\t\t\t| STUDENT MANAGEMENT SYSTEM |" << endl;
cout << "\t\t\t-----------------------------" << endl;
cout << "\t\t\t 1. Enter New Record" << endl;
cout << "\t\t\t 2. Display Record" << endl;
cout << "\t\t\t 3. Modify Record" << endl;
cout << "\t\t\t 4. Search Record" << endl;
cout << "\t\t\t 5. Delete Record" << endl;
cout << "\t\t\t 6. Exit\n"
<< endl;
cout << "\t\t\t............................" << endl;
cout << "\t\t\tChoose Options:[1/2/3/4/5/6]" << endl;
cout << "\t\t\t............................" << endl;
cout << " Enter Your Choose: ";
cin >> choice;
switch (choice)
{
case 1:
do
{
insert();
cout << "\n\n\t\t\t Add Another Student Record (Y, N) : ";
cin >> x;
} while (x == 'y' || x == 'Y');
break;
case 2:
display();
break;
case 3:
modify();
break;
case 4:
search();
break;
case 5:
deleted();
break;
case 6:
cout << "\n\t\t\t Program Is Exit";
exit(0);
default:
cout << "\n\n\t\t\t Invalid Choice... Please Try Again...";
}
getch();
goto menustart;
}
void student::insert() // Add student details
{
system("cls");
fstream file;
cout << "\n-------------------------------------------------------------------------------------------------------" << endl;
cout << "------------------------------------- Add Student Details ---------------------------------------------" << endl;
cout << "\t\t\tEnter Name: ";
cin >> name;
cout << "\t\t\tEnter Roll No.: ";
cin >> roll_no;
cout << "\t\t\tEnter Course: ";
cin >> course;
email:
cout << "\t\t\tEnter Email Id(name@gmail.com): ";
cin >> email_id;
if (Emailcheck(email_id))
{
cout << "\t\t\t Your Email-Id is Valid" << endl;
}
else
{
cout << "\t\t\t Your Email-Id is InValid" << endl;
goto email;
}
contact:
cout << "\t\t\tEnter Contact No(9639xxxxxx): ";
cin >> contact_no;
if (contact_no < 1000000000 || contact_no > 9999999999)
{
cout << "\t\t\t Please Enter Only 10 Digits..." << endl;
goto contact;
}
cout << "\t\t\tEnter Address: ";
cin >> address;
file.open("studentRecord.txt", ios::app | ios::out);
file << " " << name << " " << roll_no << " " << course << " " << email_id << " " << contact_no << " " << address << "\n";
file.close();
}
void student::display() // Display data of student
{
system("cls");
fstream file;
int total = 1;
cout << "\n-------------------------------------------------------------------------------------------------------" << endl;
cout << "------------------------------------- Student Record Table --------------------------------------------" << endl;
file.open("studentRecord.txt", ios::in);
if (!file)
{
cout << "\n\t\t\tNo Data is Present... ";
file.close();
}
else
{
file >> name >> roll_no >> course >> email_id >> contact_no >> address;
while (!file.eof())
{
cout << "\n\n\t\t\tStudent No.: " << total++ << endl;
cout << "\t\t\tName: " << name << "\n";
cout << "\t\t\tRoll No.: " << roll_no << "\n";
cout << "\t\t\tCourse: " << course << "\n";
cout << "\t\t\tEmail Id: " << email_id << "\n";
cout << "\t\t\tContact No.: " << contact_no << "\n";
cout << "\t\t\tAddress: " << address << "\n";
file >> name >> roll_no >> course >> email_id >> contact_no >> address;
}
if (total == 0)
{
cout << "\n\t\t\tNo Data is Present..." << endl;
}
}
file.close();
}
void student::modify() // Modify details of student
{
system("cls");
fstream file, file1;
string rollno;
int found = 0;
cout << "\n-------------------------------------------------------------------------------------------------------" << endl;
cout << "------------------------------------- Student Modify Details ------------------------------------------" << endl;
file.open("studentRecord.txt", ios::in);
if (!file)
{
cout << "\n\t\t\tNo Data is Present..";
file.close();
}
else
{
cout << "\nEnter Roll No. of Student which you want to Modify: ";
cin >> rollno;
file1.open("record.txt", ios::app | ios::out);
file >> name >> roll_no >> course >> email_id >> contact_no >> address;
while (!file.eof())
{
if (rollno != roll_no)
file1 << " " << name << " " << roll_no << " " << course << " " << email_id << " " << contact_no << " " << address << "\n";
else
{
cout << "\n\t\t\tEnter Name: ";
cin >> name;
cout << "\t\t\tEnter Roll No.: ";
cin >> roll_no;
cout << "\t\t\tEnter Course: ";
cin >> course;
email:
cout << "\t\t\tEnter Email Id(name@gmail.com): ";
cin >> email_id;
if (Emailcheck(email_id))
{
cout << "\t\t\t Your Email-Id is Valid" << endl;
}
else
{
cout << "\t\t\t Your Email-Id is InValid" << endl;
goto email;
}
contact:
cout << "\t\t\tEnter Contact No(9639xxxxxx): ";
cin >> contact_no;
if (contact_no < 1000000000 || contact_no > 9999999999)
{
cout << "\t\t\t Please Enter Only 10 Digits..." << endl;
goto contact;
}
cout << "\t\t\tEnter Address: ";
cin >> address;
file1 << " " << name << " " << roll_no << " " << course << " " << email_id << " " << contact_no << " " << address << "\n";
found++;
}
file >> name >> roll_no >> course >> email_id >> contact_no >> address;
}
if (found == 0)
{
cout << "\n\n\t\t\t Student Roll No. Not Found....";
}
file1.close();
file.close();
remove("studentRecord.txt");
rename("record.txt", "studentRecord.txt");
}
}
void student::search() // search data of student
{
system("cls");
fstream file;
int found = 0;
file.open("studentRecord.txt", ios::in);
if (!file)
{
cout << "\n-------------------------------------------------------------------------------------------------------" << endl;
cout << "------------------------------------- Student Search Data --------------------------------------------" << endl;
cout << "\n\t\t\tNo Data is Present... " << endl;
}
else
{
string rollno;
cout << "\n-------------------------------------------------------------------------------------------------------" << endl;
cout << "------------------------------------- Student Search Table --------------------------------------------" << endl;
cout << "\nEnter Roll No. of Student which you want to search: ";
cin >> rollno;
file >> name >> roll_no >> course >> email_id >> contact_no >> address;
while (!file.eof())
{
if (rollno == roll_no)
{
cout << "\n\n\t\t\tName: " << name << "\n";
cout << "\t\t\tRoll No.: " << roll_no << "\n";
cout << "\t\t\tCourse: " << course << "\n";
cout << "\t\t\tEmail Id: " << email_id << "\n";
cout << "\t\t\tContact No.: " << contact_no << "\n";
cout << "\t\t\tAddress: " << address << "\n";
found++;
}
file >> name >> roll_no >> course >> email_id >> contact_no >> address;
if (found == 0)
{
cout << "\n\t\t\t Student Roll NO. Not Found....";
}
}
file.close();
}
}
void student::deleted() // ddeleted data of student
{
system("cls");
fstream file, file1;
int found = 0;
string roll;
cout << "\n-------------------------------------------------------------------------------------------------------" << endl;
cout << "------------------------------------- Delete Student Details ------------------------------------------" << endl;
file.open("studentRecord.txt", ios::in);
if (!file)
{
cout << "\n\t\t\tNo Data is Present..";
file.close();
}
else
{
cout << "\nEnter Roll No. of Student which you want Delete Data: ";
cin >> roll;
file1.open("record.txt", ios::app | ios::out);
file >> name >> roll_no >> course >> email_id >> contact_no >> address;
while (!file.eof())
{
if (roll != roll_no)
{
file1 << " " << name << " " << roll_no << " " << course << " " << email_id << " " << contact_no << " " << address << "\n";
}
else
{
found++;
cout << "\n\t\t\tSuccessfully Delete Data";
}
file >> name >> roll_no >> course >> email_id >> contact_no >> address;
}
if (found == 0)
{
cout << "\n\t\t\t Student Roll NO. Not Found....";
}
file1.close();
file.close();
remove("studentRecord.txt");
rename("record.txt", "studentRecord.txt");
}
}
int main()
{
student project; // object
project.menu(); //object calling
return 0;
}