Hostel Management System (C++ code)

/*Please kindly note that there are many mistakes in this project, as no proper reservation is done into the library files, and the updates are not done on the reservation of rooms. Similar other faults are present. However if you want to look at the basic structure and basic features of the Hostel Management System (HMS), then this is a good source for you, it also uses very basic C++ and OOP concepts in it so it is easy to understand and update.*/
#include<iostream>
#include<fstream>
#include<stdio.h>
#include <string>
using namespace std;
// CLASS NO:1
class Building
{
protected:
unsigned int floor, room;
public:
Building() :floor(0), room(0) {};
void writedata();
void display();
};
// FUNC 1.1
void Building::writedata()
{
cout << "\t\tEnter the no of floors\t:" << endl;
cout << "\t\t";
cin >> floor;
cout << "\t\tEnter the no of rooms\t:" << endl;
cout << "\t\t";
cin >> room;
}
// FUNC 1.2
void Building::display()
{
cout << "\n\tCurrent Data entered in system by user :" << endl;
cout << "\tNo of floors\t:" << floor << endl;
cout << "\tNo of rooms\t:" << room << endl;
}
// CLASS NO:2
class Hostel :public Building
{
protected:
unsigned int no_Bathroom, no_Tutorroom, no_Studyhall, no_Masjid;
public:
Hostel() : no_Bathroom(0), no_Tutorroom(0), no_Studyhall(0), no_Masjid(0) {};
void setData();
void showdata();
};
// FUNC 2.1
void Hostel::setData()
{
cout << "\n\t\tEnter the number of Bedrooms\t:" << endl;
cout << "\t\t";
cin >> room;
cout << "\t\tEnter the number of Bathrooms\t:" << endl;
cout << "\t\t";
cin >> no_Bathroom;
cout << "\t\tEnter the number of Tutorrooms\t:" << endl;
cout << "\t\t";
cin >> no_Tutorroom;
cout << "\t\tEnter the number of Studyhalls\t:" << endl;
cout << "\t\t";
cin >> no_Studyhall;
cout << "\t\tEnter the number of Masjids\t:" << endl;
cout << "\t\t";
cin >> no_Masjid;
}
// FUNC 2.2
void Hostel::showdata()
{
cout << "\n\t\tBedrooms\t:" << room << endl;
cout << "\t\tBathrooms\t:" << no_Bathroom << endl;
cout << "\t\tTutorrooms\t:" << no_Tutorroom << endl;
cout << "\t\tStudyHalls\t:" << no_Studyhall << endl;
cout << "\t\tMasjids\t\t:" << no_Masjid << endl;
}
// CLASS NO:3
class Member
{
protected:
string address, name;
unsigned int number;
char gender;
Hostel h1;
public:
Member() :name(""), number(0), gender(), address("") {};
virtual void setdata() = 0;
virtual void display() = 0;
};
//CLASS NO:4
class Student :public Member
{
protected:
unsigned int roomNo, regno,compl_no;
string complainElectrician, complainPlumber;
public:
Student() :roomNo(0), complainElectrician(""),regno(0), complainPlumber(""), compl_no(0){};
void setdata();
void setcomplainelect();
void setcomplainplum();
void getcomplainelect();
void getcomplainplam();
void display();
//void displaycomplain();
unsigned int getReg_NO();
};
// FUNC 4.1
unsigned int Student::getReg_NO()
{
return regno;
}
// FUNC 4.2
void Student::setdata()
{
cout << "Enter name:";
cin.ignore();
getline(cin, name);
cout << "Enter Registration number:";
cin >> regno;
cout << "Enter room number:";
cin >> roomNo;
cout << "Enter gender:";
cin >> gender;
}
// FUNC 4.3
void Student::setcomplainplum()
{
cout << " To enter the compliant you have to must provide your details :" << endl;
cout << " Enter your name :" << endl;
cin.ignore();
getline(cin, name);
cout << " Enter your room no :" << endl;
cin >> roomNo;
cout << "Enter your complain";
cin.ignore();
getline(cin, complainPlumber);
}
// FUNC 4.4
void Student::setcomplainelect()
{
cout << " To enter the compliant you have to must provide your details :" << endl;
cout << " Enter your name :" << endl;
cin.ignore();
getline(cin, name);
cout << " Enter your room no :" << endl;
cin >> roomNo;
cout << "Enter the complain \t:";
cin.ignore();
getline(cin, complainElectrician);
}
// FUNC 4.5
void Student::getcomplainelect()
{
cout << " Name of the Student :" << name << endl;
cout << " Room No of the Student :" << roomNo << endl;
cout << "the electric complaint are:" << complainElectrician << endl;
}
// FUNC 4.6
void Student::getcomplainplam()
{
cout << " Name of the Student :" << name << endl;
cout << " Room No of the Student :" << roomNo << endl;
cout << "the pulambric complaint are:" << complainPlumber << endl;
}
// FUNC 4.7
void Student::display()
{
//cout << "\nstudent data are given below:" << endl;
//cout << "Name:" << name << endl;
//cout << "Room:" << roomNo << endl;
//cout << "Gender:" << gender << endl;
cout << "";
}
//CLASS NO:5
class Visitor : public Member
{
protected:
unsigned int CNIC;
public:
Visitor() : CNIC(0) {};
void setdata();
void display();
void check_host();
};
//FUNC 5.1
void Visitor::setdata()
{
cout << " Enter your Name :" << endl;
cin.ignore();
getline(cin, name);
cout << " Enter your CNIC :" << endl;
cin >> CNIC;
}
//FUNC 5.2
void Visitor::display()
{
cout << " Name :" << name << endl;
cout << " CNIC :" << CNIC << endl;
}
//FUNC 5.3
void Visitor::check_host()
{
cout << " Enter your Host Reg NO: " << endl;
}
//CLASS NO:6
class Employee :public Member
{
public:
virtual void display() = 0;
};
//CLASS NO:7
class Mess_employee :public Employee
{
protected:
unsigned int cook, waiter, incharge, unit;
public:
Mess_employee() :cook(0), waiter(0), incharge(0), unit(0) {};
void markAttend();
void setdata();
void display();
void showMenu();
void show_attendance();
};
// FUNC 7.1
void Mess_employee::setdata()
{
cout << "Enter cook:" << endl;
cin >> cook;
cout << "Enter waiter:" << endl;
cin >> waiter;
cout << "Enter incharge:" << endl;
cin >> incharge;
}
// FUNC 7.2
void Mess_employee::markAttend()
{
char c;
do {
cout << "enter name:";
cin.ignore();
getline(cin, name);
cout << "enter room No:";
cin >> number;
cout << "enter unit:";
cin >> unit;
cout << "do you want to add new record(y/n):";
cin >> c;
} while (c == 'y');
}
// FUNC 7.3
void Mess_employee::display()
{
cout << "Cook:" << cook << endl;
cout << "Waiter:" << waiter << endl;
cout << "incharge" << incharge << endl;
}
// FUNC 7.4
void Mess_employee::showMenu()
{
cout << "Meal in a week:" << endl;
cout << "Breakfast,Lunch,Dinner\n";
cout << "Jam malai,Sabzi,Alu-kema\n";
cout << "Alu-paratha & dahi,Rice,Murg chana\n";
cout << "paratha & Alu-anda,daal mash,Rice\n";
cout << "Naan-chana,dahleem,surprise\n";
cout << "Tosat-bread,Rice,sabzi+sweet\n";
cout << "no break-fast,chicken-jalfrazi,dal-chana\n";
cout << "no break-fast,Birayani,lal-lobia\n";
}
// FUNC 7.5
void Mess_employee::show_attendance()
{
cout << "student attendance data:" << endl;
cout << "name:" << name << endl;
cout << "room no:" << number << endl;
cout << "unit:" << unit << endl;
}
//CLASS NO:8
class Security :public Employee
{
protected:
public:
void setdata();
void checkstudent();
void display();
};
// FUNC 8.1
void Security::setdata()
{
cout << "";
}
// FUNC 8.2
void Security::checkstudent()
{
cout << "Enter Reg No. then you can check in the hostel" << endl;
}
// FUNC 8.3
void Security::display()
{
cout << " " << endl;
}
//CLASS NO:9
class Plumber : public Employee
{
protected:
public:
void setdata();
void checkcomplain();
void display();
};
// FUNC 9.1
void Plumber::setdata()
{
cout << "";
}
// FUNC 9.2
void Plumber::checkcomplain()
{
cout << " Enter Complain_NO of the Student :" << endl;
}
// FUNC 9.3
void Plumber::display()
{
cout << "";
}
//CLASS NO:10
class Electrion : public Employee
{
protected:
public:
void setdata();
void checkcomplain();
void display();
};
// FUNC 10.1
void Electrion::setdata()
{
cout << "";
}
//FUNC 10.2
void Electrion::checkcomplain()
{
cout << " Enter Complain_NO of the Student :" << endl;
}
//FUNC 10.3
void Electrion::display()
{
cout << "";
}
//CLASS NO:11
class Tutor:public Employee
{
string complain;
public:
void setdata();
void display();
};
//FUNC 11.1
void Tutor::setdata()
{
cout << "Enter complain";
cin.ignore();
getline(cin, complain);
cout << "Enter employee id:";
cin >> number;
}
//FUNC 11.2
void Tutor::display()
{
cout << "Complain is:" << endl << complain;
cout << "employee id is:" << endl << number;
}
//CLASS NO:12
class Provost :public Employee
{
protected:
unsigned int roomNo;
unsigned int employee_id;
int unit;
float unit_rate;
public:
Provost() :roomNo(0), employee_id(0),unit(0),unit_rate(0.0) {};
void setdata();
int getReg();
void display();
void setemployeedata();
int getemployee_id();
void displayemplyee();
void genratechallan();
void viewchallan();
};
// FUNC 12.1
void Provost::setdata()
{
cout << "enter student name:";
cin.ignore();
getline(cin, name);
cout << "enter student reg No:";
cin >> number;
cout << "enter room No:";
cin >> roomNo;
}
// FUNC 12.2
int Provost::getReg()
{
return number;
}
// FUNC 12.3
void Provost::display()
{
cout << "student name:" << name << endl;
cout << "student reg No:" << number << endl;
cout << "student room No:" << roomNo << endl;
}
// FUNC 12.4
void Provost::setemployeedata()
{
cout << "enter employee name:";
cin.ignore();
getline(cin, name);
cout << "enter employee_id:";
cin >> employee_id;
}
// FUNC 12.5
int Provost::getemployee_id()
{
return employee_id;
}
// FUNC 12.6
void Provost::displayemplyee()
{
cout << "employee name:" << name << endl;
cout << "employee_id:" << employee_id << endl;
}
// FUNC 12.7
void Provost::genratechallan()
{
int unit, unit_rate;
cout << "enter student name:";
cin.ignore();
getline(cin, name);
cout << "enter reg no:";
cin >> number;
cout << "enter unit of total month:";
cin >> unit;
cout << "enter enter unit rate:";
cin >> unit_rate;
}
//FUNC 12.8
void Provost::viewchallan()
{
float bill = 0;
bill = unit * unit_rate;
cout << "student name:" << name << endl;
cout << "student reg No:" << number << endl;
cout << "mess bill of the month:" << bill << endl;
}
//MAIN FUNCTION
int main()
{
int choice; //for 1,1.1 Switch started
int obj = 0, roomno = 0;
Building b1;
Hostel h1;
Student s1;
Visitor v1;
Mess_employee me;
Provost p1, p2;
Security S1;
Plumber plum;
Electrion e1;
Tutor t1;
Member *ptr3;
ptr3 = &t1;
ifstream fileread;
ofstream filewrite;
ofstream filewrite2;
ifstream fileread2;
char chee = 0; //We will use it for 3 basic operations in Do While
do
{
cout << "\tTo call the building Press 1:" << endl;
cout << "\tTo call the hostel Press 2:" << endl;
cout << "\tTo call the Member Press 3:" << endl;
cout << "\t";
cin >> choice;
char che = 0;
//1 DO WHILE LOOP STARTED
do
{
//1.1 SWITCH STARTED
switch (choice)
{
//1.1.1 CASE STARTED
case 1:
{
b1.writedata();
ofstream os("Building.dat", ios::binary);
os.write(reinterpret_cast<char*>(&b1), sizeof(Building));
os.close();
ifstream is("Building.dat", ios::binary);
is.read(reinterpret_cast<char*>(&b1), sizeof(Building));
b1.display();
is.close();
break;
//1.1.1 CASE BREAK
}
//1.1.2 CASE STARTED
case 2:
{
h1.setData();
ofstream os("Hostel.dat", ios::binary);
os.write(reinterpret_cast<char*>(&h1), sizeof(Hostel));
os.close();
ifstream is("Hostel.dat", ios::binary);
is.read(reinterpret_cast<char*>(&h1), sizeof(Hostel));
h1.showdata();
is.close();
break;
//CASE BREAK (1.1.2)
}
//1.1.3 CASE STARTED
case 3:
{
int var1; // var1 is used for switch between student,visitor and employee
cout << "Press 1 for Student Details:\t|";
cout << "\tPress 2 for Visitor Details:\t|";
cout << "\tPress 3 for Employee Details:\t|";
cout << "\n\t";
cin >> var1;
//1.1.3.1 SWITCH STARTED
switch (var1)
{
//1.1.3.1.1 CASE STARTED
case 1:
{
char var4 = 0;// var4 for DO WHILE student operations loop
do
{
int var2; // var2 is used for switch between setData, Complain or view Challan
cout << "\tPress 1 for setData:" << endl;
cout << "\tPress 2 for Complain:" << endl;
cout << "\tPress 3 for view Challan:" << endl;
cout << "\tPress 4 for view student record:" << endl;
cout << "\t";
cin >> var2;
//1.1.3.1.1.1 SWITCH STARTED
switch (var2)
{
//1.1.3.1.1.1.1 CASE 1 STARTED
case 1:
{
cout << "Enter your data:" << endl;
s1.setdata();
ofstream os("student.dat", ios::binary);
os.write(reinterpret_cast<char*>(&s1), sizeof(Student));
os.close();
ifstream is("student.dat", ios::binary);
s1.display();
is.read(reinterpret_cast<char*>(&s1), sizeof(Student));
is.close();
break;
//CASE ENDED (1.1.3.1.1.1.1)
}
//1.1.3.1.1.1.2.1 CASE 2 STARTED
case 2:
{
int var3; //var3 is used for SWITCH between electician and plumber complain
cout << "\tpress 1 for electrition complain" << endl;
cout << "\tpress 2 for plumber complain" << endl;
cin >> var3;
//1.1.3.1.1.1.2.1 SWITCH STARTED
switch (var3)
{
//1.1.3.1.1.1.2.1.1 CASE STARTED
case 1:
{
char ch = 0;
ofstream writefile;
ifstream readfile;
writefile.open("electration.dat", ios::binary);
do
{
s1.setcomplainelect();
writefile.write(reinterpret_cast<char*>(&s1), sizeof(Student));
cout << "do you want to add more complain(y/n):";
cin >> ch;
} while (ch == 'y');
writefile.close();
break;
//CASE BREAK (1.1.3.1.1.1.2.1.1)
}
//1.1.3.1.1.1.2.1.2 CASE STARTED
case 2:
{
char c = 0;
ofstream writefile;
ifstream readfile;
writefile.open("plumber.dat", ios::binary);
do
{
s1.setcomplainplum();
writefile.write(reinterpret_cast<char*>(&s1), sizeof(Student));
cout << "do you want to add more complain(y/n):";
cin >> c;
} while (c == 'y');
writefile.close();
break;
//CASE BREAK (1.1.3.1.1.1.2.1.2)
}
default:
cout << "no complaint:" << endl;
//SWITCH ENDED (1.1.3.1.1.1.2.1)
}
break;
// CASE BREAK (1.1.3.1.1.1.2.1)
}
//1.1.3.1.1.1.2.2 CASE 3 STARTED
case 3:
{
// function for view challan
fileread.open("challan", ios::binary | ios::app);
int reg;
cout << "enter reg you want to view challan:";
cin >> reg;
fileread.read(reinterpret_cast<char*>(&p1), sizeof(Provost));
if (p1.getReg() == reg)
{
p1.viewchallan();
}
else
cout << "record not found:";
break;
//CASE ENDED (1.1.3.1.1.1.2.2)
}
case 4:
{
fileread.open("StudentRecord.dat", ios::binary);
fileread.read(reinterpret_cast<char*>(&p1), sizeof(Provost));
while (!fileread.eof())
{
p1.display();
fileread.read(reinterpret_cast<char*>(&p1), sizeof(Provost));
}
break;
}
default:
cout << "You are pressing wrong button please choose again from the start" << endl;
//SWITCH ENDED (1.1.3.1.1.1)
}
} while (var4 == 'y');
// Do While ended for student operations
break;
// CASE BREAK (1.1.3.1.1)
}
//1.1.3.1.2 CASE STARTED
case 2:
{
int c; //for checking host in hostel
ifstream readfile;
ofstream writefile;
fileread.open("StudentRecord.dat", ios::binary);
fileread.read(reinterpret_cast<char*>(&p1), sizeof(Provost));
v1.check_host();
cin >> c;
if (c == p1.getReg())
{
p1.display();
}
else
cout << "no record found of host";
readfile.close();
break;
}
//1.1.3.1.3 CASE STARTED
case 3:
{
int var5 = 0; // var5 for SWITCH employee (mess,plumber, electician, Security, admin) details
cout << "\n\tPress 1 for Mess Employee:";
cout << "\n\tPress 2 for Plumber Employee:";
cout << "\n\tPress 3 for Electrician Employee:";
cout << "\n\tPress 4 for Security Employee:";
cout << "\n\tPress 5 for Admin Employ:";
cin >> var5;
//1.1.3.1.3.1 SWITCH STARTED
switch (var5)
{
//1.1.3.1.3.1.1 CASE STARTED
case 1:
{
int ch = 0;
cout << "press 1 to see menue:" << endl;
cout << "press 2 to enter mess detail:" << endl;
cout << "press 3 to mark attendance:" << endl;
cout << "press 4 to showdetail:" << endl;
cin >> ch;
switch (ch)
{
case 1:
{
char cha;
me.showMenu();
cout << "Do you want to perform any other operation?";
cin >> cha;
break;
}
case 2:
{
ofstream os("messdetail.dat", ios::binary);
me.setdata();
os.write(reinterpret_cast<char*>(&me), sizeof(Mess_employee));
os.close();
break;
}
case 3:
{
ofstream os("messdetail.dat", ios::binary);
me.markAttend();
os.write(reinterpret_cast<char*>(&me), sizeof(Mess_employee));
os.close();
break;
}
case 4:
{
ifstream is("messdetail.dat", ios::binary);
me.display();
is.read(reinterpret_cast<char*>(&me), sizeof(Mess_employee));
is.close();
break;
}
default:
cout << "invalid input !";
}
break;
//CASE ENDED (1.1.3.1.3.1.1)
}
//1.1.3.1.3.1.2 CASE STARTED
case 2:
{
ofstream writefile;
ifstream readfile;
int cNo = 0;
readfile.open("plumber.dat", ios::binary);
readfile.seekg(0, ios::end);
//cout << "Total objects in file" << readfile.tellg() / sizeof(Student);
readfile.seekg(0, ios::beg);
cout << endl;
readfile.read(reinterpret_cast<char*>(&s1), sizeof(Student));
while (!readfile.eof())
{
cout << "\nstudent details:" << endl;
s1.getcomplainplam();
readfile.read(reinterpret_cast<char*>(&s1), sizeof(Student));
}
readfile.close();
break;
//CASE ENDED (1.1.3.1.3.1.2)
}
//1.1.3.1.3.1.3 CASE STARTED
case 3:
{
ofstream writefile;
ifstream readfile;
int co = 0;
readfile.open("electration.dat", ios::binary);
readfile.seekg(0, ios::end);
//cout << "Total objects in file" << readfile.tellg() / sizeof(Student);
readfile.seekg(0, ios::beg);
cout << endl;
readfile.read(reinterpret_cast<char*>(&s1), sizeof(Student));
while (!readfile.eof())
{
s1.getcomplainelect();
readfile.read(reinterpret_cast<char*>(&s1), sizeof(Student));
cout << "\nstudent details:" << endl;
obj++;
//if (s1.getcomplain() == co)
//break;
/* {
cout << "Details:" << endl;
cout << "Issues you need to resolve:\t" << obj << endl;
s1.getcomplainelect();
}*/
}
readfile.close();
break;
//CASE ENDED (1.1.3.1.3.1.3)
}
//1.1.3.1.3.1.4 CASE STARTED
case 4:
{
int cNo=0; //for checking host in hostel
ifstream readfile;
ofstream writefile;
fileread.open("StudentRecord.dat", ios::binary);
//cout << "total no of obj:" << fileread.tellg() / sizeof(Provost) << endl;
//v1.check_host();
cout << "enter reg no you want to search:";
cin >> cNo;
fileread.read(reinterpret_cast<char*>(&p1), sizeof(Provost));
if (cNo == p1.getReg())
{
p1.display();
}
/*while (!readfile.eof())
{
readfile.read(reinterpret_cast<char*>(&p1), sizeof(Provost));
//if (readfile.eof())
//break;
cout << "\nstudent details:" << endl;
//obj++;
if (s1.getReg_NO() == cNo)
//break;
{
cout << "Details:" << endl;
cout << "Issues you need to resolve:\t" << obj << endl;
s1.getcomplainplam();
}
}*/
readfile.close();
break;
//CASE ENDED (1.1.3.1.3.1.4)
}
//1.1.3.1.3.1.5 CASE STARTED
case 5:
{
int var6 = 0; //var6 is used for switch for Admin to give choice between Tutor and Provost
cout << "\nPress 1 for Tutor:\n";
cout << "\nPress 2 for Provost:\n";
cin >> var6;
//1.1.3.1.3.1.5.1 SWITCH STARTED
switch (var6)
{
//1.1.3.1.3.1.5.1.1 CASE STARTED
case 1:
{
int choise2;
cout << "to enter compalaint of employee press 1:" << endl;
cout << "to show registerd complaint press 2:" << endl;
cin >> choise2;
switch (choise2)
{
case 1:
{
char ch;
filewrite.open("tutor.date", ios::binary | ios::app);
do {
ptr3->setdata();
filewrite.write(reinterpret_cast<char*>(&t1), sizeof(Tutor));
cout << "do you want to register anther complaint (y/n)?";
cin >> ch;
} while (ch == 'y');
filewrite.close();
break;
}
case 2:
{
fileread.open("tutor.date", ios::binary);
fileread.read(reinterpret_cast<char*>(&t1), sizeof(Tutor));
while (!fileread.eof())
{
ptr3->display();
fileread.read(reinterpret_cast<char*>(&t1), sizeof(Tutor));
}
break;
}
default:
cout << "invalid input:";
}
break;
//CASE ENDED(1.1.3.1.3.1.5.1.2)
}
//1.1.3.1.3.1.5.1.2 CASE STARTED
case 2:
{
int cho;
int obj = 0;
cout << "\tpress 1 to add new student:" << endl;
cout << "\tpress 2 to update student:" << endl;
cout << "\tpress 3 to delete student:" << endl;
cout << "\tpress 4 to display student record:" << endl;
cout << "\tpress 5 to add new employee:" << endl;
cout << "\tpress 6 to update employee:" << endl;
cout << "\tpress 7 to delete employee:" << endl;
cout << "\tpress 8 to display employee record:" << endl;
cout << "\tpress 9 to genrate challan:" << endl;
cout << "\tpress 10 to view challan:" << endl;
cout << "\tpress 11 to view tutor complaint:" << endl;
cin >> cho;
//1.1.4.1.2.1 SWITCH STARTED
switch (cho)
{
//1.1.4.1.2.1.1 CASE STARTED
case 1:
{
char ch;
filewrite.open("StudentRecord.dat", ios::binary);
//1.1.4.1.2.1.1.1 DO WHILE STARTED
do
{
p1.setdata();
filewrite.write(reinterpret_cast<char*>(&p1), sizeof(Provost));
cout << "do you want to add anther student:y/n?";
cin >> ch;
} while (ch == 'y');
//DO WHILE BREAK (1.1.4.1.2.1.1.1)
break;
//CASE BREAK (1.1.4.1.2.1.1)
}
//1.1.4.1.2.1.2 CASE STARTED
case 2:
{
cout << "Enter obj num you want to update:";
cin >> obj;
filewrite.open("StudentRecord.dat", ios::binary);
filewrite.seekp((obj - 1) * sizeof(Provost), ios::beg);
p1.setdata();
filewrite.write(reinterpret_cast<char*>(&p1), sizeof(Provost));
filewrite.close();
break;
//CASE BREAK (1.1.4.1.2.1.2)
}
//1.1.4.1.2.1.3 CASE STARTED
case 3:
{
int reg;
fileread2.open("StudentRecord.dat", ios::binary | ios::in);
filewrite2.open("StudentRecord2.dat", ios::binary | ios::out);
//1.1.4.1.2.1.3 IF STARTED
if (!fileread2 || !filewrite2)
{
cout << "alternative file not exist:";
}
else
cout << "enter reg number which you want to delete:";
cin >> reg;
//1.1.4.1.2.1.3.1 WHILE STARTED
while (!fileread2.eof())
{
fileread2.read(reinterpret_cast<char*>(&p1), sizeof(Provost));
//1.1.4.1.2.1.3.1.1 IF STARTED
if (p1.getReg() != reg)
{
filewrite2.write(reinterpret_cast<char*>(&p1), sizeof(Provost));
}
//IF BREAK (1.1.4.1.2.1.3.1.1)
}
//WHILE BREAK (1.1.4.1.2.1.3.1)
fileread2.close();
filewrite2.close();
remove( "StudentRecord.dat" );
rename( "StudentRecord2.dat", "StudentRecord.dat" );
//1.1.4.1.2.1.3 IF ENDED
break;
//CASE BREAK (1.1.4.1.2.1.3)
}
//1.1.4.1.2.1.4 CASE STARTED
case 4:
{
fileread.open("StudentRecord.dat", ios::binary);
cout << "total no of obj:" << fileread.tellg() / sizeof(Provost) << endl;
fileread.read(reinterpret_cast<char*>(&p1), sizeof(Provost));
//1.1.4.1.2.1.4.1 WHILE STARTED
while (!fileread.eof())
{
obj++;
p1.display();
fileread.read(reinterpret_cast<char*>(&p1), sizeof(Provost));
}
//WHILE BREAK (1.1.4.1.2.1.4.1)
fileread.close();
break;
//CASE BREAK (1.1.4.1.2.1.4)
}
//1.1.4.1.2.1.5 CASE STARTED
case 5:
{
char ch3;
filewrite.open("EmployeeRecord.dat", ios::binary);
//1.1.4.1.2.1.5.1 DO WHILE STARTED
do
{
p2.setemployeedata();
filewrite.write(reinterpret_cast<char*>(&p2), sizeof(Provost));
cout << "do you want to add anther employee:(y/n) :";
cin >> ch3;
} while (ch3 == 'y');
//DO WHILE END (1.1.4.1.2.1.5.1)
break;
//CASE BREAK(1.1.4.1.2.1.5)
}
//1.1.4.1.2.1.6 CASE STARTED
case 6:
{
cout << "Enter object you want to update:";
cin >> obj;
filewrite.open("EmployeeRecord.dat", ios::binary);
filewrite.seekp((obj - 1) * sizeof(Provost), ios::beg);
p2.setemployeedata();
filewrite.write(reinterpret_cast<char*>(&p2), sizeof(Provost));
filewrite.close();
break;
//CASE BREAK(1.1.4.1.2.1.6)
}
//1.1.4.1.2.1.7 CASE STARTED
case 7:
{
int EmployeeID;
fileread2.open("EmployeeRecord.dat", ios::binary | ios::in);
filewrite2.open("EmployeeRecord2.dat", ios::binary | ios::out);
//1.1.4.1.2.1.7.1 IF STARTED
if (!fileread2 || !filewrite2)
{
cout << "alternative file not exist:";
}
else
cout << "Enter Employee-ID which you want to delete:";
cin >> EmployeeID;
//1.1.4.1.2.1.7.1.1 WHILE STARTED
while (!fileread2.eof())
{
fileread2.read(reinterpret_cast<char*>(&p2), sizeof(Provost));
//1.1.4.1.2.1.7.1.1.1 IF STARTED
if (p2.getemployee_id() != EmployeeID)
{
filewrite2.write(reinterpret_cast<char*>(&p2), sizeof(Provost));
//IF ENDED (1.1.4.1.2.1.8.1.1)
}
//WHILE END (1.1.4.1.2.1.7.1.1)
}
fileread2.close();
filewrite2.close();
remove( "EmployeeRecord.dat" );
rename( "EmployeeRecord2.dat", "EmployeeRecord.dat" );
//IF ENDED (1.1.4.1.2.1.7.1)
break;
//CASE BREAK (1.1.4.1.2.1.7.1)
}
//1.1.4.1.2.1.8 CASE STARTED
case 8:
{
fileread.open("EmployeeRecord.dat", ios::binary);
cout << "total no of obj:" << fileread.tellg() / sizeof(Provost) << endl;
fileread.read(reinterpret_cast<char*>(&p2), sizeof(Provost));
//1.1.4.1.2.1.8.1 WHILE STARTED
while (!fileread.eof())
{
obj++;
p2.displayemplyee();
fileread.read(reinterpret_cast<char*>(&p2), sizeof(Provost));
//WHILE END(1.1.4.1.2.1.8.1)
}
fileread.close();
break;
//CASE BREAK (1.1.4.1.2.1.8)
}
//1.1.4.1.2.1.9 CASE STARTED
case 9:
{
char ch;
filewrite.open("challan", ios::binary);
//1.1.4.1.2.1.9.1 DO WHILE STARTED
do
{
p1.genratechallan();
filewrite.write(reinterpret_cast<char*>(&p1), sizeof(Provost));
cout << "\t do you want to genrate anther student challan (y/n):" << endl;
cin >> ch;
} while (ch == 'y');
//DO WHILE ENDED (1.1.4.1.2.1.9.1)
filewrite.close();
break;
//CASE ENDED (1.1.4.1.2.1.9)
}
//
case 10:
{
fileread.open("challan", ios::binary | ios::app);
int reg;
cout << "enter reg you want to view challan:";
cin >> reg;
fileread.read(reinterpret_cast<char*>(&p1), sizeof(Provost));
if (p1.getReg() == reg)
{
p1.viewchallan();
}
else
cout << "record not found:";
break;
}
//
case 11:
{
fileread.open("tutor.date", ios::binary);
fileread.read(reinterpret_cast<char*>(&t1), sizeof(Tutor));
while (!fileread.eof())
{
ptr3->display();
fileread.read(reinterpret_cast<char*>(&t1), sizeof(Tutor));
}
break;
}
default:
cout << "Invalid Input" << endl;
}
break;
//CASE ENDED (1.1.3.1.3.1.5.1.2)
}
default:
cout << "\nInvalid input!";
//SWITCH ENDED (1.1.3.1.3.1.5.1)
}
break;
//CASE ENDED (1.1.3.1.3.1.5)
}
default:
cout << "\tYou have entered wrong button!\n";
//SWITCH ENDED (1.1.3.1.3.1)
}
break;
}
default:
cout << "incomplete" << endl;
}
break;
}
default:
cout << "incomplete" << endl;
}
cout << "Press y";
cin >> che;
} while (che == 'y');
cout << "Press y if you want to perform 3 basic operations again!" << endl;
cin >> chee;
}
while (chee == 'y');
return 0;
}