Student Record Management System in C++
Student Record Management System in C++
Student Record Management System in C++
Submitted By
NAME: Tayyab Zubair
Roll NO: 20014156-012
Submitted To
NAME: Sir Bilal Mazhar
Submission Date: 07-Jul-2021
Department of Information Technology
Task 02
Input
#include "stdafx.h"
#include "iostream"
#include "string"
#include "conio.h"
#include "fstream"
using namespace std;
class Person
{
protected:
int id;
string name;
string email;
string pasword;
string address;
long phone_number;
public:
Person()
{
id = 0;
name = "No name";
email = "no email";
pasword = "1234";
address = "No address";
phone_number = 0;
}
~Person()
{
}
void SetId(int id)//setter
{
this->id = id;
}
int GetId()//getter
{
return id;
}
void datawrite()
{
ofstream out("student.txt", ios::out | ios::app);
out.write((char*)this, sizeof(*this));
out.close();
}
void dataread()
{
ifstream out("student.txt", ios::in);
out.read((char*)this, sizeof(*this));
while (!out.eof())
{
cout << GetId() << "\t" << GetRollNumber() << "\t" << GetName() <<
"\t" << GetEmail() << "\t" << GetPassword() << "\t" << GetAddress() << "\t" <<
GetPhoneNumber() << endl;
out.read((char*)this, sizeof(*this));
}
out.close();
}
void dataread(long roll)
{
ifstream out("student.txt", ios::in);
out.read((char*)this, sizeof(*this));
while (!out.eof())
{
if (this->GetRollNumber() == roll)
{
cout << GetId() << "\t" << GetRollNumber() << "\t" <<
GetName() << "\t" << GetEmail() << "\t" << GetPassword() << "\t" << GetAddress() << "\t"
<< GetPhoneNumber() << endl;
}
out.read((char*)this, sizeof(*this));
}
out.close();
}
void update(long roll)
{
bool flag = false;
int id;
string name, email, password, address;
long phone_number;
int count = 0;
fstream out("student.txt", ios::in | ios::out | ios::ate);
out.seekg(0, ios::beg);
out.read((char*)this, sizeof(*this));
while (!out.eof())
{
count++;
if (this->GetRollNumber() == roll)
{
int position = (count - 1) * sizeof(*this);
out.seekp(position);
int choice;
cout << "\n\n\t1-For ID:" << endl;
cout << "\t2-For Name:" << endl;
cout << "\t3-For Email:" << endl;
cout << "\t4-For Password:" << endl;
cout << "\t5-For Address:" << endl;
cout << "\t6-For Phone#:" << endl;
cout << "\n\tEnter your Choice :";
cin >> choice;
switch (choice)
{
case 1:
cout << "\n\tEnter New ID:\t";
cin >> id;
SetId(id);
break;
case 2:
cin.ignore();
cout << "\n\tEnter student Name:\t ";
getline(cin, name);
SetName(name);
break;
case 3:
cin.ignore();
cout << "\n\tEnter student Email:\t ";
getline(cin, email);
SetEmail(email);
break;
case 4:
cin.ignore();
cout << "\n\tEnter student PAssword:\t ";
getline(cin, password);
SetPassword(password);
break;
case 5:
cin.ignore();
cout << "\n\tEnter student Address:\t ";
getline(cin, address);
SetAddress(address);
break;
case 6:
cin.ignore();
cout << "\n\tEnter New student phone_number:\t ";
cin >> phone_number;
SetPhoneNumber(phone_number);
break;
default:
break;
}
out.write((char*)this, sizeof(*this));
flag = true;
break;
}
out.read((char*)this, sizeof(*this));
}
if (flag == true)
{
cout << " Student Record Is Updated......";
}
else
{
cout << "File Is Not Found";
}
out.close();
}
while (!in.eof())
{
if (this->GetRollNumber() == roll)
{
flag = true;
}
else
{
out.write((char*)this, sizeof(*this));
}
in.read((char*)this, sizeof(*this));
}
if (flag == true)
{
cout << "All Student Record Is Deleted..........";
}
else
{
cout << "File Is Not Found........";
}
in.close();
out.close();
remove("student.txt");
rename("temp.txt", "student.txt");
}
};
int main()
{
student s;
char ch;
int id, chi, n;
string name, email, password, address;
long phone_number, roll;
p:
system("cls");
cout << "\n\t@@@ Welecome To Student System @@@" << endl;
cout << "\n\n\t1. For Add Student";
cout << "\n\n\t2. For Check Student";
cout << "\n\n\t3. For Update Student";
cout << "\n\n\t4. For Delete Student" << endl;
cout << "\n\n\tEnter Your Choice :";
cin >> chi;
switch (chi)
{
case 1:
do{
system("cls");
cout << "Enter student id:\t ";
cin >> id;
cout << "Enter student Roll#:\t ";
cin >> roll;
cin.ignore();
cout << "Enter student Name:\t ";
getline(cin, name);
cout << "Enter student email:\t ";
getline(cin, email);
cout << "Enter student password:\t ";
getline(cin, password);
cout << "Enter student address:\t ";
getline(cin, address);
cout << "Enter student phone number:\t ";
cin >> phone_number;
s.SetId(id);
s.SetRollNumber(roll);
s.SetName(name);
s.SetEmail(email);
s.SetPassword(password);
s.SetAddress(address);
s.SetPhoneNumber(phone_number);
s.datawrite();
cout << "\n\n\tDo You Want To Enter Again Add Student Record (y/n) :
";
cin >> ch;
} while (ch == 'y' || ch == 'Y');
break;
case 2:
do{
system("cls");
cout << "\n\n\t1.For Check All Student Data" << endl;
cout << "\n\n\t2.For Check Specific Student Data" << endl;
cout << "\n\n\tEnter Your Choice :";
cin >> n;
if (n == 1)
{
cout << "\n\n Id\t Roll Not\ Name\t Email\t Password\t City\t
Phone.No " << endl;
s.dataread();
}
else if (n == 2)
{
cout << "Enter roll\t";
cin >> roll;
s.dataread(roll);
}
else
cout << "\n\n\t\tYou Enter Default Value.." << endl;
cout << "\n\n\tDo You Want To Enter Again in Student Record (y/n) :
";
cin >> ch;
} while (ch == 'y' || ch == 'Y');
break;
case 3:
do{
system("cls");
cout << "\n\t\tUpdate Student Record" << endl;
cout << "Enter Roll No:";
cin >> roll;
s.update(roll);
cout << "\n\n\tDo You Want To Enter Again in Update Student Record
(y/n) : ";
cin >> ch;
} while (ch == 'y' || ch == 'Y');
break;
case 4:
do{
system("cls");
cout << "\n\t\tDelete Student Record" << endl;
s.recorddelete(roll);
cout << "\n\n\tDo You Want To Enter Again in Delete Student Record
(y/n) : ";
cin >> ch;
} while (ch == 'y' || ch == 'Y');
break;
default:
cout << "Enter Correct Choice " << endl;
}
goto p;
_getch();
return 0;
}
Output