forked from tecky708/app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
harshPr2
229 lines (189 loc) · 5.59 KB
/
harshPr2
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
#include<stdio.h>
#include<iostream>
#include<fstream>
#include<string.h>
#include<time.h>
#include<string>
using namespace std;
int main(){
//system("cls");
printf("\n");
cout<<("\t\t\t\t ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
cout<<("\t\t\t\t { STUDENT RECORD MANAGEMENT SYSTEM }\n");
cout<<("\t\t\t\t ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
cout<<("\n\n\n");
cout<<("\t\t\t\t");
cout<<("REGESTRATION NUMBER: ");
cout<<(":");
cout<<(" 11804634");
cout<<("\n\n");
cout<<("\t\t\t\t");
cout<<(" Project ");
cout<<(" :");
cout<<(" Class Calander");
cout<<("\n\n");
cout<<("\t\t\t\t");
cout<<("\t\tPress Enter to continue......");
cout<<("\n\n");
getchar();
char data[15];
int n = 0, option = 0, count_n = 0;
string empty = "00";
string proctor = "";
//Name of the file in which DB is stored.
ifstream f("Example.txt");
string line;
//The following for loop counts the total number of lines in the file.
for (int i = 0; std::getline(f, line); ++i){
count_n++;}
while(option != 5){
//This prints out all the available options in the DB
cout << "\nAvailable operations: \n1. Add New Students\n2."
<< "Student Login\n3. Faculty Login\n4. Admin View\n"
<< "5. Exit\nEnter option: ";
cin >> option;
if(option == 1){
cout << "Enter the number of students: ";
cin >> n;
count_n = count_n + n;
for (int i = 0;i < n;i++){
ofstream outfile;
outfile.open("Example.txt",ios::app);
//The entire data of a single student is stored line-by-line.
cout << "Enter your registration number: ";
cin >> data;
outfile << data << "\t";
cout << "Enter your name: ";
cin >> data;
int len = strlen(data);
while (len < 15){
data[len] = ' ';
len = len + 1;
}
outfile << data << "\t";
//Inserting empty data initially into the file
outfile << empty << "\t";
outfile << empty << "\t";
cout << "Enter your proctor ID: ";
cin >> proctor;
outfile << proctor << endl;
}}
else if (option == 2){
char regno[9];
cout << "Enter your registration number: ";
cin >> regno;
ifstream infile;
int check = 0;
infile.open("Example.txt",ios::in);
while (infile >> data){
if (strcmp(data,regno) == 0){
cout << "\nRegistration Number: " << data << endl;
infile >> data;
cout << "Name: " << data << endl;
infile >> data;
cout << "CSE101 mark: " << data << endl;
infile>>data;
cout<<"CSE102 mark: "<<data<<endl;
/* infile>>data;
cout<<"Proctor ID: "<<data<<endl;
*/
infile.close();
check = 1;}
}
if (check == 0){
cout<<"No such registration number found!"<<endl;}
}
//This loop is used to view and add marks to the database of a student.
else if (option == 3){
char subcode[7];
cout << "Enter your subject code: ";
cin >> subcode;
string code1 = "CSE101", code2 = "CSE102",mark = "";
ifstream infile;
int check = 0;
cout << "\nAvailable operations: \n1. Add data about marks\n"
<< "2. View data\nEnter option: ";
cin >> option;
if (option == 1){
cout << "Warning! You would need to add mark"
<< "details for all the students!" << endl;
for(int i = 0;i < count_n;i++){
fstream file("Example.txt");
//The seek in file has been done according to the length
//of the data being inserted. It needs to adjusted accordingly
//for diffferent lengths of data.
if(strcmp(subcode,code1.c_str()) == 0){
file.seekp(26+37*i,std::ios_base::beg);
cout << "Enter the mark of student#" << (i+1) << " : ";
cin >> mark;
file.write(mark.c_str(),2);}
if(strcmp(subcode,code2.c_str()) == 0){
file.seekp(29+37*i,std::ios_base::beg);
cout << "Enter the mark of student#" << (i+1) << " : ";
cin >> mark;
file.write(mark.c_str(),2);}
}
}
//This loop is used to view marks of a student.
//The extra infile commands have been used to get a specific mark
//only since the data has been seperated by a tabspace.
else if(option == 2){
infile.open("Example.txt",ios::in);
if (strcmp(subcode,code1.c_str()) == 0){
cout << "Registration number - Marks\n" << endl;
while(infile >> data){
cout << data;
infile >> data;
infile >> data;
cout << " - " << data << endl;
infile >> data;
infile >> data;
check = 1;
}
}
infile.close();
infile.open("Example.txt",ios::in);
if(strcmp(subcode,code2.c_str()) == 0){
cout << "Registration number - Marks\n" << endl;
while(infile >> data){
cout << data;
infile >> data;
infile >> data;
infile >> data;
cout << " - " << data << endl;
infile >> data;
check = 1;
}
}}
infile.close();
if (check == 0){
cout << "No such subject code found!" << endl;
}
}
//This loop acts as an admin view to see all the data in the file.
else if(option == 4){
char password[25];
cout << "Enter the admin password: ";
cin >> password;
//This variable value can be changed according to your requirement
//of the administrator password.
string admin_pass = "adminguru";
if (strcmp(password,admin_pass.c_str()) == 0){
cout << "Reg No. \t Name \tCSE101\t CSE102" << endl;
ifstream infile;
infile.open("Example.txt",ios::in);
char data[20];
while(infile >> data){
cout << data << "\t";
infile >> data;
cout << data << "\t";
infile >> data;
cout << data << "\t";
infile >> data;
cout << data << "\t";
infile >> data;
cout << data << endl;
}
}
}
}}