Im having problem with saving register staff detail. After typing all the detail, and i choose to view the staff detail - it say "Data for Staff Number that have been entered is Empty."
here's my full coding:
admin.h
#pragma once
#ifndef ADMIN_H
#define ADMIN_H
#include<iostream>
#include<string>
#include "Staff.h"
using namespace std;
class Admin
{
public:
void AD_Menu();
void register_All(fstream &);
void add_staff();
void edit_staff(fstream &);
void search_staff(fstream &);
void Delete_staff(fstream &);
void CreateFile();
};
#endif;
HumanResource.h
#pragma once
#ifndef HUMANRESOURCE_H
#define HUMANRESOURCE_H
#include<iostream>
#include<string>
#include "Staff.h"
#include "Admin.h"
using namespace std;
class HumanResource
{
public:
void HR_Menu();
void register_staff(fstream &);
};
#endif;
login.h
#pragma once
#ifndef LOGIN_H
#define LOGIN_H
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
class Login
{
public:
void Log_Menu();
void Def_User();
void getAccess();
};
#endif;
staff.h
#include<iostream>
#ifndef STAFF_H
#define STAFF_H
#include<string>
using namespace std;
class Staff
{
public:
Staff(int=0 , string=" " , long=0 , string=" ", string=" ", string=" ", int=0, string=" ", string=" ", int=0, string=" ", string=" ", string=" ", string=" " );
void setstaffNum(int);
int getstaffNum() const;
void setstaffName(string);
string getstaffName() const;
void setIC_num(long);
long getIC_num() const;
void setgender(string);
string getgender() const;
void setdesignation(string);
string getdesignation() const;
void setdepartment(string);
string getdepartment() const;
void setjoinDate(int);
int getjoinDate() const;
void setnationality(string);
string getnationality() const;
void setreligion(string);
string getreligion() const;
void setdate_of_birth(int);
int getdate_of_birth() const;
void setmaritalStatus(string);
string getmaritalStatus() const;
void setusername(string);
string getusername() const;
void setpassword(string);
string getpassword() const;
void setlogintype(string);
string getlogintype() const;
//void Staff_menu();
//void view_staff();
private:
int staff_num;
string staff_name;
long int IC_num;
string gender;
string designation;
string department;
int joinDate;
string nationality;
string religion;
int date_of_birth;
string maritalStatus;
string username;
string password;
string logintype;
};
#endif;
adminmenu.cpp
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <limits>
using namespace std;
using std::ofstream;
using std::ostream;
using std::fstream;
#include "Admin.h"
#include "HumanResource.h"
#include "Login.h"
#include "Staff.h"
Admin ADM;
void Admin::AD_Menu()
{
int input;
system("cls");
cout<<"\t\t==================================================="<<endl;
cout<<"\t\t Admin Menu "<<endl;
cout<<"\t\t==================================================="<<endl;
cout<<"\t\t 1 - Register "<<endl;
cout<<"\t\t 2 - Search "<<endl;
cout<<"\t\t 3 - Edit "<<endl;
cout<<"\t\t 4 - Delete "<<endl;
cout<<"\t\t 0 - Exit "<<endl;
cout<<"\t\t==================================================="<<endl;
cout<<"\t\t Enter Your Choice: "; cin>>input;
if(input==1)
{
fstream FILE("Save.txt", ios::ate | ios::in |ios::out | ios::binary);
if(!FILE)
{
cerr<<"Save File could not be Open....."<<endl; //The program will exit if the fstream cannot open
system("pause");
exit(1);
}
ADM.register_All(FILE);
FILE.flush();
FILE.close();
}
else if(input==2)
{
fstream FILE("Save.txt", ios::ate | ios::in |ios::out | ios::binary);
if(!FILE)
{
cerr<<"Save File could not be Open....."<<endl; //The program will exit if the fstream cannot open
system("pause");
exit(1);
}
ADM.search_staff(FILE);
FILE.flush();
FILE.close();
}
else if(input==3)
{
fstream FILE("Save.txt", ios::ate | ios::in |ios::out | ios::binary);
if(!FILE)
{
cerr<<"Save File could not be Open...."<<endl; //The program will exit if the fstream cannot open
system("pause");
exit(1);
}
ADM.edit_staff(FILE);
FILE.flush();
FILE.close();
}
else if(input==4)
{
fstream FILE("Save.txt", ios::ate | ios::in |ios::out | ios::binary);
if(!FILE)
{
cerr<<"Save File could not be Open...."<<endl; //The program will exit if the fstream cannot open
system("pause");
exit(1);
}
ADM.Delete_staff(FILE);
FILE.flush();
FILE.close();
}
else if(input==0)
{
exit(1);
}
system("pause");
}
createfile.cpp
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <string>
using namespace std;
#include "Admin.h"
#include "HumanResource.h"
#include "Login.h"
#include "Staff.h"
void Admin::CreateFile()
{
ofstream FILE("Save.txt", ios::app | ios::out | ios::binary);
if(!FILE)
{
cerr<<" Save File could not be Open...."<<endl;
system("pause");
exit(1);
}
FILE.flush();
FILE.close();
}
delete.cpp
#include <iostream>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::ios;
using std::left;
using std::right;
using std::showpoint;
#include <fstream>
using std::ofstream;
using std::ostream;
using std::fstream;
#include <iomanip>
using std::setw;
using std::setprecision;
#include <cstdlib>
using std::exit;
#include "Admin.h"
#include "Login.h"
#include "Staff.h"
void Admin::Delete_staff(fstream &deleteFile)
{
Staff Staff1;
Admin Admin1;
int number;
system("cls");
cout<<"\t\t================================================="<<endl;
cout<<"\t\t Delete Record "<<endl;
cout<<"\t\t================================================="<<endl;
cout<<"\t\t 00 - Back to Menu "<<endl;
cout<<"\t\t Enter Staff Number: ";cin>>number;
deleteFile.seekg((number-1)* sizeof(Staff)); // move file-position pointer to correct record in file
deleteFile.read(reinterpret_cast< char *>(&Staff1),sizeof (Staff)); // The record will be read from this file.
if(Staff1.getstaffNum()!= 0 )
{
Staff Staff0;
deleteFile.seekp(( number - 1) * sizeof (Staff) );
deleteFile.write(reinterpret_cast< const char * >( &Staff0), sizeof(Staff));
cout<<"Staff Number "<< number << " has been deleted....\n";
system("pause");
}
else
{
cerr<<"Staff Number " << number <<" DETAILS IS EMPTY.\n";
system("pause");
}
deleteFile.flush();
deleteFile.close();
Admin1.AD_Menu();
}
edit.cpp
#include <iostream>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::ios;
using std::left;
using std::right;
using std::showpoint;
#include <fstream>
using std::ofstream;
using std::ostream;
using std::fstream;
#include <iomanip>
using std::setw;
using std::setprecision;
#include <cstdlib>
using std::exit;
#include "Admin.h"
#include "Login.h"
#include "Staff.h"
void Admin::edit_staff(fstream &editFile)
{
Staff Staff1;
Admin Admin1;
int input1;
int input2;
char g;
int design;
int depart;
int input3;
string input4;
string input5;
string input6;
string input7;
string input8;
string input9;
string input10;
long icnum;
system("cls");
cout<<"\t\t================================================="<<endl;
cout<<"\t\t EDIT Record "<<endl;
cout<<"\t\t================================================="<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t 00 - MAIN MENU "<<endl;
cout<<"\t\t Enter Staff Number: "; cin>>input1;
if(input1==0)
{
Admin1.AD_Menu();
}
else
{
editFile.seekg((input1-1)*sizeof(Staff));
editFile.read(reinterpret_cast< char *>(&Staff1),sizeof (Staff));
int i=0;
while(!editFile.eof())
{
if(input1 == Staff1.getstaffNum())
{
system("cls");
cout<<"\t\t================================================="<<endl;
cout<<"\t\t Edit Record "<<endl;
cout<<"\t\t================================================="<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t 1 - Name "<<endl;
cout<<"\t\t 2 - IC Number "<<endl;
cout<<"\t\t 3 - Gender "<<endl;
cout<<"\t\t 4 - Designation "<<endl;
cout<<"\t\t 5 - Department "<<endl;
cout<<"\t\t 6 - Date Join "<<endl;
cout<<"\t\t 7 - Nationality "<<endl;
cout<<"\t\t 8 - Religion "<<endl;
cout<<"\t\t 9 - DoB "<<endl;
cout<<"\t\t 10 - Martial Status "<<endl;
cout<<"\t\t 11 - UserName "<<endl;
cout<<"\t\t 12 - Password "<<endl;
cout<<"\t\t 0 - Exit "<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t================================================="<<endl;
cout<<"\t\t Enter Your Choice: "; cin>>input2;
if(input2==1)
{
system("cls");
cout<<" Enter Staff Number: ";cin>>input10;
Staff1.setstaffName(input10);
editFile.seekp((input1 - 1)* sizeof (Staff)); //File position pointer will be moved to the correct file.
editFile.write(reinterpret_cast< const char * >( &Staff1), sizeof(Staff));
// The file will be re-write by replacing the old record with the new record.
editFile.flush();
editFile.close();
Admin1.edit_staff(editFile);
}
else
if(input2==2)
{
system("cls");
cout<<" Enter IC Number: ";cin>>icnum;
Staff1.setIC_num(icnum);
editFile.seekp((input1 - 1)* sizeof (Staff)); //File position pointer will be moved to the correct file.
editFile.write(reinterpret_cast< const char * >( &Staff1), sizeof(Staff));
// The file will be re-write by replacing the old record with the new record.
editFile.flush();
editFile.close();
Admin1.edit_staff(editFile);
}
else
if(input2==3)
{
while(true)
{
system("cls");
cout<<" Enter Gender [F/M] : "; cin>>g;
if(g == 'M' || g == 'm')
{
input10 = "Male";
break;
}
else
if(g == 'F' || g == 'f')
{
input10 = "Female";
break;
}
else
{
cout<<"You have entered an invalid Gender. Please Enter[F]emale or [M]ale"<<endl;
}
}
Staff1.setgender(input10);
editFile.seekp((input1 - 1)* sizeof (Staff)); //File position pointer will be moved to the correct file.
editFile.write(reinterpret_cast< const char * >( &Staff1), sizeof(Staff));
// The file will be re-write by replacing the old record with the new record.
editFile.flush();
editFile.close();
Admin1.edit_staff(editFile);
}
else
if(input2==4)
{
system("cls");
cout<<" Enter Your Designation : "<<endl;
while(true)
{
cout<<endl<<"\t\t======================================="<<endl;
cout<<endl<<"\t\t Degignation "<<endl;
cout <<"\t\t======================================="<<endl;
cout <<"\t\t "<<endl;
cout <<"\t\t 1 - Managing Director "<<endl;
cout <<"\t\t 2 - Senior Manager "<<endl;
cout <<"\t\t 3 - Manager "<<endl;
cout <<"\t\t 4 - Senior Executive "<<endl;
cout <<"\t\t 5 - Executive "<<endl;
cout <<"\t\t 6 - Junior Executive "<<endl;
cout <<"\t\t "<<endl;
cout <<"\t\t======================================="<<endl;
cout <<"\t\t Enter Your Designation : ";cin>>design;
if(design==1)
{
input10 ="ManagingDirector";
break;
}
else
if(design==2)
{
input10="SeniorManager";
break;
}
else
if(design==3)
{
input10="Manager";
break;
}
else
if(design==4)
{
input10="SeniorExecutive";
break;
}
else
if(design==5)
{
input10="Executive ";
break;
}
else
if(design==6)
{
input10="JuniorExecutive";
break;
}
else
{
cout<<"Unknown Number. Please Enter the Correct Number!"<<endl;
}
}
Staff1.setdesignation(input10);
//File position pointer will be moved to the correct file.
editFile.seekp((input1 - 1)* sizeof (Staff));
editFile.write(reinterpret_cast< const char * >( &Staff1), sizeof(Staff));
editFile.flush();
editFile.close();
Admin1.edit_staff(editFile);
}
else
if(input2==5)
{
system("cls");
cout<<" Enter Department : "<<endl;
while(true)
{
cout<<endl<<"\t\t======================================="<<endl;
cout<<endl<<"\t\t Department "<<endl;
cout <<"\t\t======================================="<<endl;
cout <<"\t\t "<<endl;
cout <<"\t\t 1 - Administrator "<<endl;
cout <<"\t\t 2 - Human Resource "<<endl;
cout <<"\t\t 3 - Staff "<<endl;
cout <<"\t\t "<<endl;
cout <<"\t\t======================================="<<endl;
cout <<"\t\t Enter Department : ";cin>>depart;
if(depart==1)
{
input10="Administrator";
break;
}
else
if(depart==2)
{
input10="HumanResource";
break;
}
else
if(depart==3)
{
input10="Staff";
break;
}
else
{
cout<<"Unknown Number. Please Enter the Correct Number!"<<endl;
}
}
Staff1.setdepartment(input10);
Staff1.setlogintype(input10);
editFile.seekp((input1 - 1)* sizeof (Staff));
editFile.write(reinterpret_cast< const char * >( &Staff1), sizeof(Staff));
editFile.flush();
editFile.close();
Admin1.edit_staff(editFile);
}
else
if(input2==6)
{
system("cls");
cout<<" Enter Date of Join: "; cin>>input3;
Staff1.setjoinDate(input3);
editFile.seekp((input1 - 1)* sizeof (Staff));
editFile.write(reinterpret_cast< const char * >( &Staff1), sizeof(Staff));
editFile.flush();
editFile.close();
Admin1.edit_staff(editFile);
}
else
if(input2==7)
{
system("cls");
cout<<" Enter Nationality: ";cin>>input9;
Staff1.setnationality(input9);
editFile.seekp((input1 - 1)* sizeof (Staff));
editFile.write(reinterpret_cast< const char * >( &Staff1), sizeof(Staff));
editFile.flush();
editFile.close();
Admin1.edit_staff(editFile);
}
else
if(input2==8)
{
system("cls");
cout<<" Enter Religion: ";cin>>input8;
Staff1.setreligion(input8);
editFile.seekp((input1 - 1)* sizeof (Staff));
editFile.write(reinterpret_cast< const char * >( &Staff1), sizeof(Staff));
editFile.flush();
editFile.close();
Admin1.edit_staff(editFile);
}
else
if(input2==9)
{
system("cls");
cout<<" Enter DoB (Date of Birth): ";cin>>input3;
Staff1.setdate_of_birth(input3);
editFile.seekp((input1 - 1)* sizeof (Staff));
editFile.write(reinterpret_cast< const char * >( &Staff1), sizeof(Staff));
editFile.flush();
editFile.close();
Admin1.edit_staff(editFile);
}
else
if(input2==10)
{
system("cls");
cout<<" Enter Martial Status: ";cin>>input5;
Staff1.setmaritalStatus(input5);
editFile.seekp((input1 - 1)* sizeof (Staff));
editFile.write(reinterpret_cast< const char * >( &Staff1), sizeof(Staff));
editFile.flush();
editFile.close();
Admin1.edit_staff(editFile);
}
else
if(input2==11)
{
cout<<" Enter UserName: ";cin>>input6;
Staff1.setusername(input6);
editFile.seekp((input1 - 1)* sizeof (Staff));
editFile.write(reinterpret_cast< const char * >( &Staff1), sizeof(Staff));
editFile.flush();
editFile.close();
Admin1.edit_staff(editFile);
}
else
if(input2==12)
{
system("cls");
cout<<" Enter Password : ";cin>>input7;
Staff1.setpassword(input7);
editFile.seekp((input1 - 1)* sizeof (Staff));
editFile.write(reinterpret_cast< const char * >( &Staff1), sizeof(Staff));
editFile.flush();
editFile.close();
Admin1.edit_staff(editFile);
}
else
if(input2==00)
{
exit(1);
}
else
{
cout<<" Unknown Staff Number. Please Enter The Correct Staff Number..."<<endl;
system("pause");
Admin1.edit_staff(editFile);
}
editFile.seekp((input1 - 1)* sizeof (Staff));
editFile.write(reinterpret_cast< const char * >( &Staff1), sizeof(Staff));
}
else
{
cout<<" Data for the Staff Number that has been Entered is Empty...."<<endl;
system("pause");
Admin1.edit_staff(editFile);
}
}
}
editFile.flush();
editFile.close();
}
hrmenu.cpp
#include <string>
#include <iomanip>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <limits>
using namespace std;
#include "Admin.h"
#include "HumanResource.h"
#include "Login.h"
#include "Staff.h"
HumanResource HR1;
Admin admin2;
void HumanResource::HR_Menu()
{
int input;
system("cls");
cout<<"\t\t==========================================================="<<endl;
cout<<"\t\t Human Resource Menu "<<endl;
cout<<"\t\t==========================================================="<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t 1 - Register "<<endl;
cout<<"\t\t 2 - Search "<<endl;
cout<<"\t\t 3 - Edit "<<endl;
cout<<"\t\t 4 - Delete "<<endl;
cout<<"\t\t 0 - Exit "<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t==========================================================="<<endl;
cout<<"\t\t Enter Your Choice: ";cin>>input;
if(input==1)
{
fstream FILE("Save.txt", ios::ate | ios::in |ios::out | ios::binary);
if(!FILE)//The program will exit if fstream cannot open
{
cerr<<"Save File Could not be Open....."<<endl;
system("pause");
exit(1);
}
HR1.register_staff(FILE);
FILE.flush();
FILE.close();
}
else if(input==2)
{
fstream FILE("Save.txt", ios::ate | ios::in |ios::out | ios::binary);
if(!FILE)
{
cerr<<"Save File Could not be Open....."<<endl;
system("pause");
exit(1);
}
admin2.search_staff(FILE);
FILE.flush();
FILE.close();
}
else if(input==3)
{
fstream FILE("Save.txt", ios::ate | ios::in |ios::out | ios::binary);
if(!FILE)
{
cerr<<"Save File Could not be Open....."<<endl;
system("pause");
exit(1);
}
admin2.edit_staff(FILE);
FILE.flush();
FILE.close();
}
else if(input==4)
{
fstream FILE("Save.txt", ios::ate | ios::in |ios::out | ios::binary);
if(!FILE)
{
cerr<<"Save File Could not be Open....."<<endl;
system("pause");
exit(1);
}
admin2.Delete_staff(FILE);
FILE.flush();
FILE.close();
}
else if(input==0)
{
exit(1);
}
system("pause");
}
loginmenu.cpp
#include <string>
#include <iomanip>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <limits>
using namespace std;
#include "Admin.h"
#include "HumanResource.h"
#include "Login.h"
#include "Staff.h"
string departA="Administrator";
string departC="Staff";
string departB="HumanResource";
Login login1;
Admin admin3;
HumanResource HR2;
Staff staff9;
void Login::Log_Menu()
{
int num;
cout<<"\t\t==================================================="<<endl;
cout<<"\t\t Welcome To "<<endl;
cout<<"\t\t Staff Personnel System "<<endl;
cout<<"\t\t==================================================="<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t 1- Staff "<<endl;
cout<<"\t\t 2- Human Resource "<<endl;
cout<<"\t\t 3- Administrator "<<endl;
cout<<"\t\t 0- Quit "<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t==================================================="<<endl;
cout<<"\t\t Choose Your Login: ";cin>>num;
if (num == 1 || num == 2 || num == 3 )
{
login1.getAccess();
}
else
if (num == 0 )
exit(1);
else
cout<< "Invalid input. Please Enter the correct Input";
}
void Login::getAccess()
{
fstream LogIn("Save.txt" ,ios::in | ios::out);
string user_input, password_input;
system("cls");
cout<<"\t\t==================================================="<<endl;
cout<<"\t\t Staff Personnel System "<<endl;
cout<<"\t\t==================================================="<<endl;
cout<<"\t UserName: "; cin>>user_input;
int i=0;
while(!LogIn.eof())
{
LogIn.seekg(i*sizeof(Staff));
LogIn.read(reinterpret_cast< char *>(&staff9),sizeof (Staff));
i+=1;
if (user_input=="Ad" || user_input=="HR" || user_input=="Staff" || user_input==staff9.getusername())
{
cout<<"\t Password: " ;cin>>password_input;
}
if (password_input=="Ad")
{
system("cls");
cout<<"\t\t You have Succefully Login into the System "<<endl;
cout<<"\t\t========================================================"<<endl;
system("pause");
admin3.AD_Menu();
}
else if ((password_input==staff9.getpassword()) && (staff9.getdepartment()==departA))
{
system("cls");
cout<<"\t\t You have Succefully Login into the System "<<endl;
cout<<"\t\t========================================================"<<endl;
system("pause");
admin3.AD_Menu();
}
else if (password_input=="HR")
{
system("cls");
cout<<"\t\t You have Succefully Login into the System "<<endl;
cout<<"\t\t========================================================"<<endl;
system("pause");
HR2.HR_Menu();
}
else if ((password_input==staff9.getpassword()) && (staff9.getdepartment()==departB))
{
system("cls");
cout<<"\t\t You have Succefully Login into the System "<<endl;
cout<<"\t\t========================================================"<<endl;
system("pause");
HR2.HR_Menu();
}
else if ((password_input==staff9.getpassword()) && (staff9.getdepartment()==departC))
{
system("cls");
cout<<"\t\t Here is your Detail "<<endl;
cout<<"\t\t========================================================"<<endl;
cout<<"\n\n"<<endl;
cout<<"Staff Number : "<<staff9.getstaffNum()<<"\n";
cout<<"Name : "<<staff9.getstaffName()<<"\n";
cout<<"IC Number : "<<staff9.getIC_num()<<"\n";
cout<<"Gender : "<<staff9.getgender()<<"\n";
cout<<"Designation : "<<staff9.getdesignation()<<"\n";
cout<<"Department : "<<staff9.getdepartment()<<"\n";
cout<<"Date of Join : "<<staff9.getjoinDate()<<"\n";
cout<<"Nationality : "<<staff9.getnationality()<<"\n";
cout<<"Religion : "<<staff9.getreligion()<<"\n";
cout<<"DoB : "<<staff9.getdate_of_birth()<<"\n";
cout<<"Martial Status : "<<staff9.getmaritalStatus()<<"\n";
cout<<"UserName : "<<staff9.getusername()<<"\n";
cout<<"Password : "<<staff9.getpassword()<<"\n";
system("pause");
system("cls");
login1.Log_Menu();
}
}
if(user_input!=staff9.getpassword())
{
cout<<"Enter Your Password"<<endl;
system("pause");
system("cls");
login1.Log_Menu();
}
if(password_input!=staff9.getusername())
{
cout<<"Enter Your UserName"<<endl;
system("pause");
system("cls");
login1.Log_Menu();
}
LogIn.flush();
LogIn.close();
system("pause");
}
main.cpp
#include"Admin.h"
#include"HumanResource.h"
#include"Login.h"
#include"Staff.h"
#include <iostream>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::ios;
using std::left;
using std::right;
using std::showpoint;
#include <fstream>
using std::ofstream;
using std::ostream;
using std::fstream;
#include <iomanip>
using std::setw;
using std::setprecision;
using namespace std;
Admin admin6;
Login login6;
int main()
{
admin6.CreateFile();
fstream FILE("Save.txt",ios::app | ios::ate | ios::in |ios::out | ios::binary);
if(!FILE) // The Program will be Terminated if fstream cannot be open.
{
cerr<<"Save File cannot be Open...."<<endl;
system("pause");
exit(1);
}
login6.Log_Menu();
FILE.flush();
FILE.close();
return 0;
}
reg.cpp
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <limits>
#include <ctime>
using namespace std;
using std::ofstream;
using std::ostream;
using std::fstream;
#include "Admin.h"
#include "Staff.h"
Admin admin7;
Staff STAFF1;
void Admin::register_All(fstream &FileWriting)
{
int input1;
int ID=1;
system("cls");
cout<<"Enter Number Of Registration ";cin>>input1;
for(int i=0 ; i<input1; i++)
{
system("cls");
int staffnumber;
while(!FileWriting.eof())
{
FileWriting.seekg(ID*sizeof(Staff));
FileWriting.read(reinterpret_cast< char *>(&STAFF1),sizeof (Staff));
ID+=1;
FileWriting.flush();
FileWriting.close();
}
ID+=0;
staffnumber = ID;
cout<<endl<<"Staff Number: " << staffnumber;
FileWriting.seekg((staffnumber-1)* sizeof(Staff));
FileWriting.read(reinterpret_cast< char *>(&STAFF1),sizeof (Staff)); // It will read the record from here.
int input2;
int input3;
string username;
string password;
string name;
string gender;
char g;
long ic;
int dateofbirth;
string maritalstatus;
string religion;
string nationality;
int joindate;
string designation;
string department;
string logintype;
string HR_Login1="HR";
string Admin_Login1="ADMIN";
cout<<endl<<"UserName : ";cin>>username;
cout<<endl<<"Password : ";cin>>password;
cout<<endl<<"Name : ";cin>>name;
while(true)
{
cout<<endl<<"Gender [F/M]: ";cin>>g;
if(g == 'M' || g == 'm')
{
gender = "Male";
break;
}
else
if(g == 'F' || g == 'f')
{
gender = "Female";
break;
}
else
{
cout<<"Invalid Gender. Please Enter [F]emale or [M]ale."<<endl;
}
}
cout<<endl<<"IC Number : ";cin>>ic;
cout<<endl<<"DoB: ";cin>>dateofbirth;
cout<<endl<<"Martial Status : ";cin>>maritalstatus;
cout<<endl<<"Religion : ";cin>>religion;
cout<<endl<<"Nationality : ";cin>>nationality;
cout<<endl<<"Date Join : ";cin>>joindate;
while(true)
{
cout<<endl<<"\t\t======================================="<<endl;
cout<<endl<<"\t\t Degignation "<<endl;
cout <<"\t\t======================================="<<endl;
cout <<"\t\t "<<endl;
cout <<"\t\t 1 - Managing Director "<<endl;
cout <<"\t\t 2 - Senior Manager "<<endl;
cout <<"\t\t 3 - Manager "<<endl;
cout <<"\t\t 4 - Senior Executive "<<endl;
cout <<"\t\t 5 - Executive "<<endl;
cout <<"\t\t 6 - Junior Executive "<<endl;
cout <<"\t\t "<<endl;
cout <<"\t\t======================================="<<endl;
cout <<"\t\t Enter Your Designation : ";cin>>input2;
if(input2==1)
{
designation = "ManagingDirector";
break;
}
else
if(input2==2)
{
designation = "SeniorManager";
break;
}
else
if(input2==3)
{
designation = "Manager";
break;
}
else
if(input2==4)
{
designation = "SeniorExecutive ";
break;
}
else
if(input2==5)
{
designation = "Executive";
break;
}
else
if(input2==6)
{
designation = "JuniorExecutive ";
break;
}
else
{
cout<<"Unknown Number. Please Enter the Correct Number!"<<endl;
}
}
while(true)
{
cout<<endl<<"\t\t======================================="<<endl;
cout<<endl<<"\t\t Department "<<endl;
cout <<"\t\t======================================="<<endl;
cout <<"\t\t "<<endl;
cout <<"\t\t 1 - Administrator "<<endl;
cout <<"\t\t 2 - Human Resource "<<endl;
cout <<"\t\t 3 - Staff "<<endl;
cout <<"\t\t "<<endl;
cout <<"\t\t======================================="<<endl;
cout <<"\t\t Enter Department : ";cin>>input3;
if(input3==1)
{
department = "Administrator";
logintype = "Administrator";
break;
}
else
if(input3==2)
{
department = "HumanResource";
logintype = "HumanResource";
break;
}
else
if(input3==3)
{
department = "Staff";
logintype = "Staff";
break;
}
else
{
cout<<"Unknown Number. Please Enter the Correct Number!"<<endl;
}
}
STAFF1.setusername(username);
STAFF1.setpassword(password);
STAFF1.setstaffName(name);
STAFF1.setIC_num(ic);
STAFF1.setdate_of_birth(dateofbirth);
STAFF1.setmaritalStatus(maritalstatus);
STAFF1.setreligion(religion);
STAFF1.setnationality(nationality);
STAFF1.setjoinDate(joindate);
STAFF1.setdesignation(designation);
STAFF1.setdepartment(department);
STAFF1.setgender(gender);
STAFF1.setstaffNum(staffnumber);
STAFF1.setlogintype(logintype);
FileWriting.clear();
FileWriting.seekp((staffnumber - 1)* sizeof (Staff));
FileWriting.write(reinterpret_cast< const char * >( &STAFF1),sizeof(Staff));
FileWriting.flush();
FileWriting.close();
}
admin7.AD_Menu();
}
regstaff.cpp
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <limits>
#include <ctime>
using namespace std;
using std::ofstream;
using std::ostream;
using std::fstream;
#include "Admin.h"
#include "HumanResource.h"
#include "Login.h"
#include "Staff.h"
Staff STAFF2;
HumanResource HR14;
void HumanResource::register_staff(fstream &FileWriting_STAFF)
{
int input1;
int ID=1;
system("cls");
cout<<"Enter Number Of Registration ";cin>>input1;
for(int i=0 ; i<input1; i++)
{
system("cls");
int staffnumber;
while(!FileWriting_STAFF.eof())
{
FileWriting_STAFF.seekg(ID*sizeof(Staff));
FileWriting_STAFF.read(reinterpret_cast< char *>(&STAFF2),sizeof (Staff));
ID+=1;
}
ID+=0;
staffnumber = ID;
cout<<endl<<"Staff Number : " << staffnumber;
FileWriting_STAFF.seekg((staffnumber-1)* sizeof(Staff));
FileWriting_STAFF.read(reinterpret_cast< char *>(&STAFF2),sizeof (Staff));
int input2;
int input3;
string username;
string password;
string name;
string gender;
char g;
long ic;
int dateofbirth;
string maritalstatus;
string religion;
string nationality;
int joindate;
string designation;
string department;
string logintype;
string HR_Login1="HR";
string Admin_Login1="ADMIN";
cout<<endl<<"UserName : ";cin>>username;
cout<<endl<<"Password : ";cin>>password;
cout<<endl<<"Name : ";cin>>name;
while(true)
{
cout<<endl<<"GENDER [M / F] : "<<endl;
cin>>g;
if(g == 'M' || g == 'm')
{
gender = "Male";
break;
}
else
if(g == 'F' || g == 'f')
{
gender = "Female";
break;
}
else
{
cout<<"Invalid Gender. Please Enter [F]emale or [M]ale."<<endl;
}
}
cout<<endl<<"IC Number : ";cin>>ic;
cout<<endl<<"DoB: ";cin>>dateofbirth;
cout<<endl<<"Martial Status : ";cin>>maritalstatus;
cout<<endl<<"Religion : ";cin>>religion;
cout<<endl<<"Nationality : ";cin>>nationality;
cout<<endl<<"Date Join : ";cin>>joindate;
while(true)
{
cout<<endl<<"\t\t======================================="<<endl;
cout<<endl<<"\t\t Degignation "<<endl;
cout <<"\t\t======================================="<<endl;
cout <<"\t\t "<<endl;
cout <<"\t\t 1 - Managing Director "<<endl;
cout <<"\t\t 2 - Senior Manager "<<endl;
cout <<"\t\t 3 - Manager "<<endl;
cout <<"\t\t 4 - Senior Executive "<<endl;
cout <<"\t\t 5 - Executive "<<endl;
cout <<"\t\t 6 - Junior Executive "<<endl;
cout <<"\t\t "<<endl;
cout <<"\t\t======================================="<<endl;
cout <<"\t\t Enter Your Designation : ";cin>>input2;
if(input2==1)
{
designation = "ManagingDirector";
break;
}
else
if(input2==2)
{
designation = "SeniorManager";
break;
}
else
if(input2==3)
{
designation = "Manager";
break;
}
else
if(input2==4)
{
designation = "SeniorExecutive ";
break;
}
else
if(input2==5)
{
designation = "Executive";
break;
}
else
if(input2==6)
{
designation = "JuniorExecutive ";
break;
}
else
{
cout<<"Unknown Number. Please Enter the Correct Number!"<<endl;
}
}
while(true)
{
cout<<endl<<"\t\t==============================="<<endl;
cout<<endl<<"\t\t Department "<<endl;
cout <<"\t\t==============================="<<endl;
cout <<"\t\t 1.Staff "<<endl;
cout <<"\t\t==============================="<<endl;
cout <<"\t\t Enter Department : ";cin>>input3;
if(input3==1)
{
department = "Staff";
logintype = "Staff";
break;
}
else
{
cout<<"Unknown Number. Please Enter the Correct Number!"<<endl;
}
}
STAFF2.setusername(username);
STAFF2.setpassword(password);
STAFF2.setstaffName(name);
STAFF2.setIC_num(ic);
STAFF2.setdate_of_birth(dateofbirth);
STAFF2.setmaritalStatus(maritalstatus);
STAFF2.setreligion(religion);
STAFF2.setnationality(nationality);
STAFF2.setjoinDate(joindate);
STAFF2.setdesignation(designation);
STAFF2.setdepartment(department);
STAFF2.setgender(gender);
STAFF2.setstaffNum(staffnumber);
STAFF2.setlogintype(logintype);
FileWriting_STAFF.clear();
FileWriting_STAFF.seekp((staffnumber - 1)* sizeof (Staff));
FileWriting_STAFF.write(reinterpret_cast< const char * >( &STAFF2), sizeof(Staff));
FileWriting_STAFF.flush();
FileWriting_STAFF.close();
}
HR14.HR_Menu();
}
search.cpp
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <limits>
#include <sstream>
using namespace std;
using std::ofstream;
using std::ostream;
using std::fstream;
#include "admin.h"
#include "Login.h"
#include "Staff.h"
Admin admin14;
void Admin::search_staff(fstream &SearchFile)
{
Staff Staff1;
Admin Admin1;
system("cls");
int choice_num;
int search_by_Id;
long search_by_ic;
string search;
int searchic;
cout<<"\t\t=============================================="<<endl;
cout<<"\t\t SEARCH "<<endl;
cout<<"\t\t=============================================="<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t 1 - Staff Number "<<endl;
cout<<"\t\t 2 - Name "<<endl;
cout<<"\t\t 3 - IC Number "<<endl;
cout<<"\t\t 4 - Date Join "<<endl;
cout<<"\t\t 0 - Main Menu "<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t=============================================="<<endl;
cout<<"\t\t Enter Your Choice: ";cin>>choice_num;
if(choice_num==1)
{
cout<<" Enter Staff Number: ";cin>>search_by_Id;
SearchFile.seekg((search_by_Id-1)* sizeof(Staff));
SearchFile.read(reinterpret_cast< char *>(&Staff1),sizeof (Staff));
while(!SearchFile.eof())
{
if(search_by_Id==Staff1.getstaffNum())
{
cout<<"\t\t========================================================="<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t Staff Number : "<<Staff1.getstaffNum()<<endl;
cout<<"\t\t Name : "<<Staff1.getstaffName()<<"\n";
cout<<"\t\t IC Number : "<<Staff1.getIC_num()<<"\n";
cout<<"\t\t Gender : "<<Staff1.getgender()<<"\n";
cout<<"\t\t Designation : "<<Staff1.getdesignation()<<"\n";
cout<<"\t\t Department : "<<Staff1.getdepartment()<<"\n";
cout<<"\t\t Date Join : "<<Staff1.getjoinDate()<<"\n";
cout<<"\t\t Nationality : "<<Staff1.getnationality()<<"\n";
cout<<"\t\t Religion : "<<Staff1.getreligion()<<"\n";
cout<<"\t\t DoB : "<<Staff1.getdate_of_birth()<<"\n";
cout<<"\t\t Martial Status : "<<Staff1.getmaritalStatus()<<"\n";
cout<<"\t\t UserName : "<<Staff1.getusername()<<"\n";
cout<<"\t\t Password : "<<Staff1.getpassword()<<"\n";
cout<<"\t\t "<<endl;
cout<<"\t\t========================================================="<<endl;
system("pause");
Admin1.search_staff(SearchFile);
SearchFile.flush();
SearchFile.close();
}
else if (search!=Staff1.getstaffName())
{
cout<<"File is not found....."<<endl;
system("pause");
Admin1.search_staff(SearchFile);
SearchFile.flush();
SearchFile.close();
}
}
}
else
if(choice_num==2)
{
cout<<" Enter Name: ";cin>>search;
int i=0;
while(!SearchFile.eof())
{
SearchFile.seekg(i*sizeof(Staff));
SearchFile.read(reinterpret_cast< char *>(&Staff1),sizeof (Staff));
i+=1;
if(search==Staff1.getstaffName())
{
cout<<"\t\t========================================================="<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t Staff Number : "<<Staff1.getstaffNum()<<endl;
cout<<"\t\t Name : "<<Staff1.getstaffName()<<"\n";
cout<<"\t\t IC Number : "<<Staff1.getIC_num()<<"\n";
cout<<"\t\t Gender : "<<Staff1.getgender()<<"\n";
cout<<"\t\t Designation : "<<Staff1.getdesignation()<<"\n";
cout<<"\t\t Department : "<<Staff1.getdepartment()<<"\n";
cout<<"\t\t Date Join : "<<Staff1.getjoinDate()<<"\n";
cout<<"\t\t Nationality : "<<Staff1.getnationality()<<"\n";
cout<<"\t\t Religion : "<<Staff1.getreligion()<<"\n";
cout<<"\t\t DoB : "<<Staff1.getdate_of_birth()<<"\n";
cout<<"\t\t Martial Status : "<<Staff1.getmaritalStatus()<<"\n";
cout<<"\t\t UserName : "<<Staff1.getusername()<<"\n";
cout<<"\t\t Password : "<<Staff1.getpassword()<<"\n";
cout<<"\t\t "<<endl;
cout<<"\t\t========================================================="<<endl;
system("pause");
Admin1.search_staff(SearchFile);
SearchFile.flush();
SearchFile.close();
}
}
}
if (choice_num==3)
{
cout<<" Enter IC Number : ";cin>>search_by_ic;
int i=0;
while(!SearchFile.eof())
{
SearchFile.seekg(i*sizeof(Staff));
SearchFile.read(reinterpret_cast< char *>(&Staff1),sizeof (Staff));
i+=1;
if(search_by_ic==Staff1.getIC_num())
{
cout<<"\t\t========================================================="<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t Staff Number : "<<Staff1.getstaffNum()<<endl;
cout<<"\t\t Name : "<<Staff1.getstaffName()<<"\n";
cout<<"\t\t IC Number : "<<Staff1.getIC_num()<<"\n";
cout<<"\t\t Gender : "<<Staff1.getgender()<<"\n";
cout<<"\t\t Designation : "<<Staff1.getdesignation()<<"\n";
cout<<"\t\t Department : "<<Staff1.getdepartment()<<"\n";
cout<<"\t\t Date Join : "<<Staff1.getjoinDate()<<"\n";
cout<<"\t\t Nationality : "<<Staff1.getnationality()<<"\n";
cout<<"\t\t Religion : "<<Staff1.getreligion()<<"\n";
cout<<"\t\t DoB : "<<Staff1.getdate_of_birth()<<"\n";
cout<<"\t\t Martial Status : "<<Staff1.getmaritalStatus()<<"\n";
cout<<"\t\t UserName : "<<Staff1.getusername()<<"\n";
cout<<"\t\t Password : "<<Staff1.getpassword()<<"\n";
cout<<"\t\t "<<endl;
cout<<"\t\t========================================================="<<endl;
system("pause");
Admin1.search_staff(SearchFile);
SearchFile.flush();
SearchFile.close();
}
}
if(search_by_ic!=Staff1.getIC_num())
{
cout<<"File is Not Found"<<endl;
Admin1.search_staff(SearchFile);
SearchFile.flush();
SearchFile.close();
}
}
if(choice_num==4)
{
cout<<"Enter Join Date : ";cin>>search;
int i=0;
while(!SearchFile.eof())
{
SearchFile.seekg(i*sizeof(Staff));
SearchFile.read(reinterpret_cast< char *>(&Staff1),sizeof (Staff));
i+=1;
if(searchic==Staff1.getjoinDate())
{
cout<<"\t\t========================================================="<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t Staff Number : "<<Staff1.getstaffNum()<<endl;
cout<<"\t\t Name : "<<Staff1.getstaffName()<<"\n";
cout<<"\t\t IC Number : "<<Staff1.getIC_num()<<"\n";
cout<<"\t\t Gender : "<<Staff1.getgender()<<"\n";
cout<<"\t\t Designation : "<<Staff1.getdesignation()<<"\n";
cout<<"\t\t Department : "<<Staff1.getdepartment()<<"\n";
cout<<"\t\t Date Join : "<<Staff1.getjoinDate()<<"\n";
cout<<"\t\t Nationality : "<<Staff1.getnationality()<<"\n";
cout<<"\t\t Religion : "<<Staff1.getreligion()<<"\n";
cout<<"\t\t DoB : "<<Staff1.getdate_of_birth()<<"\n";
cout<<"\t\t Martial Status : "<<Staff1.getmaritalStatus()<<"\n";
cout<<"\t\t UserName : "<<Staff1.getusername()<<"\n";
cout<<"\t\t Password : "<<Staff1.getpassword()<<"\n";
cout<<"\t\t "<<endl;
cout<<"\t\t========================================================="<<endl;
system("pause");
Admin1.search_staff(SearchFile);
SearchFile.flush();
SearchFile.close();
}
}
if(searchic!=Staff1.getjoinDate())
{
cout<<"File is not Found ....."<<endl;
Admin1.search_staff(SearchFile);
SearchFile.flush();
SearchFile.close();
}
}
else
if(choice_num==00)
{
Admin1.AD_Menu();
}
{
cout<<" Data for Staff Number that have been entered is Empty."<<endl;
system("pause");
Admin1.search_staff(SearchFile);
}
SearchFile.flush();
SearchFile.close();
}
staffmenu.cpp
#include <string>
using namespace std;
#include"Staff.h"
Staff::Staff(int SNum, string SName, long ic, string g, string d, string depart, int jd, string n, string r,int dob, string ms, string S_username, string S_password, string S_logintype)
{
setstaffNum(SNum);
setstaffName(SName);
setIC_num(ic);
setgender(g);
setdesignation(d);
setdepartment(depart);
setjoinDate(jd);
setnationality(n);
setreligion(r);
setdate_of_birth(dob);
setmaritalStatus(ms);
setusername(S_username);
setpassword(S_password);
setlogintype(S_logintype);
}
void Staff::setstaffNum(int SNum)
{ staff_num= SNum;}
int Staff::getstaffNum() const
{return staff_num;}
void Staff::setstaffName(string SName)
{staff_name= SName;}
string Staff::getstaffName() const
{return staff_name;}
void Staff::setIC_num(long ic)
{IC_num= ic;}
long Staff::getIC_num() const
{return IC_num;}
void Staff::setgender(string g)
{ gender= g;}
string Staff::getgender() const
{return gender;}
void Staff::setdesignation(string d)
{ designation= d;}
string Staff::getdesignation() const
{return designation;}
void Staff::setdepartment(string depart)
{ department= depart;}
string Staff::getdepartment() const
{return department;}
void Staff::setjoinDate(int jd)
{ joinDate= jd;}
int Staff::getjoinDate() const
{return joinDate;}
void Staff::setnationality(string n)
{ nationality= n;}
string Staff:: getnationality() const
{return nationality;}
void Staff::setreligion(string r)
{ religion= r;}
string Staff::getreligion() const
{return religion;}
void Staff::setdate_of_birth(int dob)
{ date_of_birth= dob;}
int Staff::getdate_of_birth() const
{return date_of_birth;}
void Staff::setmaritalStatus(string ms)
{ maritalStatus= ms;}
string Staff::getmaritalStatus() const
{return maritalStatus;}
void Staff::setusername(string S_username)
{username= S_username;}
string Staff::getusername() const
{return username;}
void Staff::setpassword(string S_password)
{password= S_password;}
string Staff::getpassword() const
{return password;}
void Staff::setlogintype(string S_logintype)
{ logintype=S_logintype;}
string Staff::getlogintype() const
{return logintype;}