0% found this document useful (0 votes)
351 views10 pages

Student Record Management System in C++

The document is a C++ program that defines classes for students and people. It includes functions to set and get data members like name, ID, and phone number. There are also functions to write student data to a file, read from the file, update records, and delete records. The main function provides a menu to add new students, check student data, update records, and delete records by interacting with the class functions.

Uploaded by

Tayyab Zubair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
351 views10 pages

Student Record Management System in C++

The document is a C++ program that defines classes for students and people. It includes functions to set and get data members like name, ID, and phone number. There are also functions to write student data to a file, read from the file, update records, and delete records. The main function provides a menu to add new students, check student data, update records, and delete records by interacting with the class functions.

Uploaded by

Tayyab Zubair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

ASSIGNMENT NO :02

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 SetName(string name)//setter


{
this->name = name;
}
string GetName()//setter
{
return name;
}
void SetEmail(string email)//setter
{
this->email = email;
}
string GetEmail()//setter
{
return email;
}
void SetPassword(string pasword)//setter
{
this->pasword = pasword;
}
string GetPassword()//setter
{
return pasword;
}
void SetAddress(string address)//setter
{
this->address = address;
}
string GetAddress()//setter
{
return address;
}
void SetPhoneNumber(long phone_number)
{
this->phone_number = phone_number;
}
long GetPhoneNumber()
{
return phone_number;
}
};
class student :public Person
{
private:
long roll_number;
public:
student()
{
roll_number = 0;
}
void SetRollNumber(long roll_number)//setter
{
this->roll_number = roll_number;
}
long GetRollNumber()//getter
{
return roll_number;
}

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();
}

void recorddelete(long roll)


{
bool flag = false;
ofstream out("temp.txt", ios::out | ios::app);
ifstream in("student.txt", ios::in);
in.read((char*)this, sizeof(*this));

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

You might also like