The document describes an online student management system implemented using C++ that allows storing student data in a text file database. The system provides different views of the data for users like students, faculty, proctors and administrators. It allows adding, editing and viewing student details like registration number, name, marks in subjects and proctor ID. The source code implements the various user interfaces and file handling for performing CRUD operations on the text file database according to the user type.
1. ONLINE STUDENT
MANAGEMENT SYSTEM
SUBJECT: ADVANCE DATA STRUCTURES
SUBMITTED TO: MR. MAGETO VICTOR SIR
SUBMITTED BY: PURSHOTTAM VERMA
SID: 57920 (B.tech CSE Vth Sem.)
2. OVERVIEW
Databases are being used in every aspect of our lives right now. Trillions of bytes of
data are being stored in servers around the world. SQL is one of the most basic
methods to use such a database. But have you ever thought about using C++ to
maintain such a database. In this post, we will talk about implementing different views
on a text file according to the type of user and edit accordingly.
The data stored using this code are:
1) Registration number
2) Name
3) Marks in CSE1001
4) Marks in CSE1002
5) Proctor ID
4. //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 != 6){
//This prints out all the available options in the DB
cout << "nAvailable operations: n1. Add New Studentsn2."
<< "Student Loginn3. Faculty Loginn4. Proctor Loginn5. Admin Viewn"
<< "6. ExitnEnter 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);
5. //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;
}}
6. 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);
//This loop prints out the data according to the registration number specified.
while (infile >> data){
if (strcmp(data,regno) == 0){
cout << "nRegistration Number: " << data << endl;
infile >> data;
cout << "Name: " << data << endl;
infile >> data;
cout << "CSE1001 mark: " << data << endl;
infile>>data;
cout<<"CSE1002 mark: "<<data<<endl;
7. 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 = "CSE1001", code2 = "CSE1002",mark = "";
ifstream infile;
int check = 0;
8. cout << "nAvailable operations: n1. Add data about marksn"
<< "2. View datanEnter 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);}
9. 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 - Marksn" << endl;
while(infile >> data){
cout << data;
infile >> data;
infile >> data;
11. infile >> data;
check = 1;
}
}}
infile.close();
if (check == 0){
cout << "No such subject code found!" << endl;
}
}
//This loop displays all the details of students under the same proctor ID.
else if (option == 4){
char procid[7];
cout << "Enter your proctor ID: ";
cin >> procid;
13. if (check == 0){
cout << "No such proctor ID found!" << endl;
}}
//This loop acts as an admin view to see all the data in the file.
else if(option == 5){
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 = "admin";
if (strcmp(password,admin_pass.c_str()) == 0){
cout << "Reg No. tNametCSE1001tCSE1002tProctor ID" << endl;
ifstream infile;