Вы находитесь на странице: 1из 38

Introducation

This is the STAFF PERSONAL SYSTEM is generally used large scale companies. There are three Department in this system first is the admin, second is the human resource, third is the staff. An admin and human resource department have authorities to access all details regarding companies. human resource is a balancing act. At one extreme, you hire only qualified people

who are well suited to the firm's needs. At the other extreme, you train and develop employees to meet the firm's needs. Most expanding small businesses fall between the two extremes, they hire the best people they can find and afford, and they also recognize the need to train and develop both current and new employees as the firm grows. There are different type of designation in this system. They are managing director, Senior Manager, Manager, Senior Executive, Executive, junior
executive

Business Rules
Some of the business rules that apply to this application: A human resource belongs to only manage the schedule of staff. The staff is used for registering and fulfilling service requests. The admin will record all the information required, including the fulfilling of requests by designation.

Design

Login

Home

Add

Edit

Delete

View records

Search

Search Record

Staff

Staff Record

Source Code
#include #include #include #include "Admin.h" "Staff.h" "Login.h" "HR.h"

void Admin::viewMenu() { int select; Admin_IO *adminio_obj; Staff a; Login back2Login; do { adminio_obj = new Admin_IO; top: cout << endl<<endl ; cout << "\t\t****************************************" cout << "\t\t* Admin Menu *" cout << "\t\t****************************************" cout << "\t\t* *" cout << "\t\t* 1. View Record *" cout << "\t\t* 2. Add Record *" cout << "\t\t* 3. Search Record *" cout << "\t\t* 4. Edit Record *" cout << "\t\t* 5. Delete Record *" cout << "\t\t* 0. Logout *" cout << "\t\t* *" cout << "\t\t****************************************" select = a.menuSelection(); switch(select) { case 0: char logout; cout << "Are you sure want to log out? (Y/N)"; cin >> logout; if (logout == 'Y' || logout == 'y') { cout << "You are back to Login!"; back2Login.LoginModule(); break; } else if (logout == 'N' || logout == 'n') { goto top; } case 1: cout <<endl<<endl;

<<endl; <<endl; <<endl; <<endl; <<endl; <<endl; <<endl; <<endl; <<endl; <<endl; <<endl; <<endl;

cout<<"\t**************************************************************"<<endl; cout<<"\t* View staff record! *" << endl;

cout<<"\t**************************************************************"<<endl<<en dl; adminio_obj->viewFromFile(); break; case 2: cout <<endl<<endl; cout<<"\t**************************************************************"<<endl; cout<<"\t* Add staff record! *" << endl; cout<<"\t**************************************************************"<<endl<<en dl; adminio_obj->add(); break; case 3: cout << "Hi, you're searching! The function is implemented!" << endl; adminio_obj->searchMenu(); break; case 4: cout <<endl<<endl; cout<<"\t**************************************************************"<<endl; cout<<"\t* Edit staff record! *" << endl; cout<<"\t**************************************************************"<<endl<<en dl; adminio_obj->edit(); break; case 5: cout <<endl<<endl; cout<<"\t**************************************************************"<<endl; cout<<"\t* Delete staff record! *" << endl; cout<<"\t**************************************************************"<<endl<<en dl; adminio_obj->del(); break; } delete adminio_obj; } while (select != 0); } void Admin_IO::viewFromFile() { EmployeeRec *x = new EmployeeRec(); ifstream inStaff; inStaff.open("staff", ios::beg | ios::in); if(!inStaff) { cout<<endl<<endl<<"\t\tNo data inside, please insert new data!"<<endl<<endl; return;

} inStaff.seekg(0); inStaff.read(reinterpret_cast<char *>(x),sizeof(Admin)); while(inStaff && !inStaff.eof()) { if(x->getEmpID()!=0) { x->display(); } inStaff.read(reinterpret_cast<char *>(x),sizeof(Admin)); } inStaff.close(); } void Admin_IO::add() { int designation, dob[3], datejoined[3]; string name, gender, department, nationality, religion, status; double nric; EmployeeRec *x = new EmployeeRec(); cout << "\nEnter the Data:- " << endl; cout << "\nName: "; cin >> name; cout << "\nNRIC (14 digits only w/o dash): "; cin >> nric; cout << "\nGender: "; cin >> gender; cout << "\nSelect a Designation: " << endl << "\t1. Managing Director" << endl << "\t2. Senior Manager" << endl << "\t3. Manager" << endl << "\t4. Senior Executive" << endl << "\t5. Executive" << endl << "\t6. Junior Executive" << endl << "Enter selection: "; cin >> designation; cout << "\nDepartment: "; cin >> department; int flag; do { cout << "\nDate Joined: \n" << endl << "\tYear (xxxx): "; cin >> datejoined[0]; cout << endl << "\tMonth (xx): "; cin >> datejoined[1]; cout << endl << "\tDate (xx): "; cin >> datejoined[2]; switch (x->checkYear(datejoined[0], datejoined[1], datejoined[2])){ case 1: cout << "\nCorrect date"; flag = 0; break; case 0: cout << "\nInvalid date!";

flag = 1; break; } } while(flag != 0); cout << "\nNationality: "; cin >> nationality; cout << "\nReligion: "; cin >> religion; cout << "\nDate of Birth: \n"; cout << "\n\tYear (xxxx): "; cin >> dob[0]; cout << "\n\tMonth (xx): "; cin >> dob[1]; cout << "\n\tDate (xx): "; cin >> dob[2]; cout << "\nMarital Status: "; cin >> status; x->add2EmployeeRec(name,nric,gender,x->selectDesignation(designation),department, datejoined, nationality,religion,dob,status); //BEGIN - write into file ofstream outStaff; outStaff.open("staff",ios::app|ios::binary); if(!outStaff) { cout<<endl<<endl<<"\t\tUnable to open file, please try again!"<<endl<<endl; return; } outStaff.write(reinterpret_cast<const char *>(x),sizeof(Admin)); outStaff.close(); cout<<endl<<"\tStaff record saved to database!"<<endl; cout << "The staff's Staff ID is " << x->getEmpID() <<"." <<endl; //END - write into file x->view(); } void Admin_IO::searchMenu() { EmployeeRec *x = new EmployeeRec(); system("CLS"); int sID; cout <<endl<<endl; cout<<"\t**************************************************************"<<endl; cout<<"\t* Search staff record! *" << endl; cout<<"\t**************************************************************"<<endl<<en dl; cout << "\n\tEnter the Staff ID you want to search with" << endl << "\tStaff ID: "; cin >> sID; x->viewRecord(sID); } void Admin_IO::edit() {

int dob[3], datejoined[3], designation; double nric; string name, gender, department, nationality, religion, status; EmployeeRec *x = new EmployeeRec(); char proceed; int index,option,tempID; fflush(stdin); //check input for int do { try { cout<<endl<<"\tPlease enter the staff ID to be updated: ";; if(x->checkData(tempID)==true) break; } catch(runtime_error e) { cout<<endl<<e.what(); fflush(stdin); } }while(true); index=x->searchRecord(tempID); if(index==-1) { cout<<endl<<"\tStaff record not found!"<<endl<<endl; return; } else if(index==-2) return; cout<<endl<<"\tContinue update [Y/N]?: "; cin>>proceed; fflush(stdin); if(proceed!='Y'&&proceed!='y'&&proceed!='N'&&proceed!='n') { cout<<endl<<"\tInvalid choice!"<<endl; return; } else if(proceed=='N'||proceed=='n') return; cout<<endl; cout<<"\n1. Name"; cout<<"\n2. IC Number"; cout<<"\n3. Gender"; cout<<"\n4. Designation"; cout<<"\n5. Department"; cout<<"\n6. Date Joined"; cout<<"\n7. Nationality"; cout<<"\n8. Religion"; cout<<"\n9. Date of Birth"; cout<<"\n10. Marital Status";

do { cout<<endl<<"\tPlease select which field to update [1-10]: "; cin>>option; fflush(stdin); switch(option) { case 1: cout<<endl<<"\nName: "<<x->getName()<<endl; cout<<"\nNew Name: "; cin >> name; x->setName(name); break; case 2: cout<<endl<<"\nIC Number: "<<x->showIC(1) << "-" << x->showIC(2) << "-" << x->showIC(3)<<endl; cout<<"\nNew IC Number: "; cin >> nric; x->setNRIC(nric); break; case 3: cout<<endl<<"\nGender: "<<x->getGender()<<endl; cin >> gender; x->setGender(gender); break; case 4: cout<<endl<<"\nDesignation: "<<x->getDesignation()<<endl; cout<<"\nNew Designation: "; cout << "\nSelect a New Designation: " << endl << "\t1. Managing Director" << endl << "\t2. Senior Manager" << endl << "\t3. Manager" << endl << "\t4. Senior Executive" << endl << "\t5. Executive" << endl << "\t6. Junior Executive" << endl << "Enter selection: "; cin >> designation; x->setDesignation(x->selectDesignation(designation)); break; case 5: cout<<endl<<"\nDepartment: "<<x->getDepartment()<<endl; cout<<"\nNew Department: "; cin >> department; x->setDepartment(department); break; case 6: cout<<endl<<"\nDate of Joined: "<<x->getDatejoined(2)<<"-"<<x>getDatejoined(1)<<"-"<<x->getDatejoined(0)<<endl; //validation for date int flag; do

{ cout << "\nNew Date Joined: \n" << endl << "\tYear (xxxx): "; cin >> datejoined[0]; cout << endl << "\tMonth (xx): "; cin >> datejoined[1]; cout << endl << "\tDate (xx): "; cin >> datejoined[2]; switch (x->checkYear(datejoined[0], datejoined[1], datejoined[2])) { case 1: cout << "\nCorrect date"; flag = 0; break; case 0: cout << "\nInvalid date!"; flag = 1; break; } } while(flag != 0); x->setDatejoined(datejoined); break; case 7: cout<<endl<<"\nNationality: "<<x->getNationality()<<endl; cout<<"\nNew Nationality: "; cin >> nationality; x->setNationality(nationality); break; case 8: cout<<endl<<"\nReligion: "<<x->getReligion()<<endl; cout<<"\nNew Religion: "; cin >> religion; x->setReligion(religion); break; case 9: cout<<endl<<"\nDate of Birth: "<<x->getDob(2)<<"-"<<x->getDob(1)<<""<<x->getDob(0)<<endl; //validation for date do { cout << "\nNew Date of Birth: \n" << endl << "\tYear (xxxx): "; cin >> dob[0]; cout << endl << "\tMonth (xx): "; cin >> dob[1]; cout << endl << "\tDate (xx): "; cin >> dob[2]; switch (x->checkYear(dob[0], dob[1], dob[2])) { case 1: cout << "\nCorrect date"; flag = 0; break; case 0:

cout << "\nInvalid date!"; flag = 1; break; } } while(flag != 0); x->setDob(dob); break; case 10: cout<<endl<<"\nMarital Status: "<<x->getStatus()<<endl; cout<<"\nNew Marital Status: "; cin >> status; x->setStatus(status); break; default: cout<<endl<<"\tInvalid user choice!"<<endl; break; } cout<<endl<<"\tContinue updating Staff information [Y/N]?: "; cin>>proceed; fflush(stdin); }while(proceed=='Y'||proceed=='y'); fstream outStaff; outStaff.open("staff"); if(!outStaff) { cout<<endl<<endl<<"\t\tUnable to open file, please try again!"<<endl<<endl; return; } outStaff.seekp(index); outStaff.write(reinterpret_cast<const char *>(x),sizeof(Admin)); outStaff.close(); cout<<endl<<"\tStaff record updated!"<<endl; } void Admin_IO::del() { char cont; int tempId,pos; EmployeeRec *x = new EmployeeRec(); //validation for int input do { fflush(stdin); try { cout<<"\tPlease enter the Staff ID to be deleted: "; if(x->checkData(tempId)==true) break; } catch(runtime_error e) { cout<<endl<<e.what();

fflush(stdin); } }while(true); pos=x->searchRecord(tempId); if(pos==-1) { cout<<endl<<"\tStaff record not found!"<<endl; return; } cout<<endl<<"\tContinue delete [Y/N]?: "; cin>>cont;fflush(stdin); if(cont!='Y'&&cont!='y'&&cont!='N'&&cont!='n') { cout<<endl<<"\tInvalid choice!"<<endl; return; } else if(cont=='N'||cont=='n') return; fstream outStaff; outStaff.open("staff"); if(!outStaff) { cout<<endl<<endl<<"\t\tUnable to open file, please try again!"<<endl<<endl; return; } outStaff.seekp(pos); x->setEmpID(0); outStaff.write(reinterpret_cast<const char *>(x),sizeof(Admin)); outStaff.close(); cout<<endl<<"\tStaff record deleted!"<<endl; }

#include "EmpRec.h" #include "HR.h" #include "Admin.h" void EmployeeRec::add2EmployeeRec(string n, double ic, string sex, string rank, string unit, int* date, string nation, string belief, int* bday, string stat) { num = generateRandomNumber(); name = n; nric = ic; gender = sex; designation = rank; department = unit; for(int i=0;i<3;i++) { datejoined[i] = date[i]; dob[i] = bday[i]; } nationality = nation; religion = belief; status = stat; } void EmployeeRec::view() { cout << "\n Staff Number: " << num << "\n Staff Name: " << name << "\n NRIC: " << showIC(1) << "-" << showIC(2) << "-" << showIC(3) << "\n Gender: " << gender << "\n Designation: " << designation << "\n Department: " << department << "\n Date Joined: " << datejoined[0] << "/" << datejoined[1] << "/" << datejoined[2] << "\n Nationality: " << nationality << "\n Religion: " << religion << "\n Date of Birth: " << dob[0] << "/" << dob[1] << "/" << dob[2] << "\n Marital Status: " << status; } int EmployeeRec::generateRandomNumber() { int rdm; srand(time(NULL)); rdm = rand() % (1000000-100000)+100000; return rdm; } bool EmployeeRec::isLeapYear(unsigned short year) { return (!(year%4) && (year%100) || !(year%400)); } bool EmployeeRec::checkYear(unsigned short year,unsigned short month,unsigned short day) { unsigned short monthlen[]={31,28,31,30,31,30,31,31,30,31,30,31}; if (!year || !month || !day || month>12) return 0; if (isLeapYear(year) && month==2) monthlen[1]++; if (day>monthlen[month-1]) return 0; return 1;

} string EmployeeRec::selectDesignation(int x) { switch(x) { case 1: return "MD"; break; case 2: return "SM"; break; case 3: return "MA"; break; case 4: return "SE"; break; case 5: return "EX"; break; case 6: return "JE"; break; } return NULL; } void EmployeeRec::viewRecord(int byID) { int index; index=searchRecord(byID); if(index==-1) { cout<<endl<<"\t\tStaff record not found!"<<endl; return; } ifstream iEmp; iEmp.open("staff",ios::beg); //if unable to open Staff file if(!iEmp) { cout<<endl<<endl<<"\t\tUnable to open file, please try again!"<<endl<<endl; return; } iEmp.read(reinterpret_cast<char *>(this),sizeof(Admin)); //reads the particular record from the file displays it while(iEmp && !iEmp.eof()) { if(num!=0 && num==byID) { display(); } iEmp.read(reinterpret_cast<char *>(this),sizeof(Admin));

} iEmp.close(); } int EmployeeRec::searchRecord(int search) { int found; ifstream iEmp; iEmp.open("staff", ios::beg); if(!iEmp) { cout << "\n\nNo data found, please try again!"; return -2; } iEmp.read(reinterpret_cast<char *>(this), sizeof(Admin)); while(iEmp && !iEmp.eof() && num!=search) iEmp.read(reinterpret_cast<char *>(this), sizeof(Admin)); if(num==search) { found=iEmp.tellg(); found=found-sizeof(Admin); } else found = -1; iEmp.close(); return found; } bool EmployeeRec::checkData(int &data) { char t; t=cin.peek(); if(t>='0' && t <='9') { cin>>data; fflush(stdin); return true; } else throw runtime_error("\tInvalid Command!\n\n"); } void EmployeeRec::display() { cout<<endl<<"\t Staff ID\t\t: " <<num <<endl<<"\t Name\t\t\t: " <<name <<endl<<"\t IC Number\t\t: " <<showIC(1) << "-" << showIC(2) << "-" << showIC(3) <<endl<<"\t Gender\t\t: " <<gender <<endl<<"\t Designation\t\t: " <<decodeDesignation(designation) <<endl<<"\t Department\t\t: " <<department <<endl<<"\t Date of Joined\t: " <<datejoined[2]<<"/"<<datejoined[1]<<"/"<<datejoined[0] <<endl<<"\t Nationality\t\t: " <<nationality <<endl<<"\t Religion\t\t: " <<religion

<<endl<<"\t <<endl<<"\t

Date of Birth\t: "

<<dob[2]<<"/"<<dob[1]<<"/"<<dob[0]

Marital Status\t: " <<status<<endl;

cout<<"\t---------------------------------------------------------"; } string EmployeeRec::decodeDesignation(string x) { if (x == "MD") return "Managing Director"; else if ( x == "SM") return "Senior Manager"; else if ( x == "MA") return "Manager"; else if ( x == "SE") return "Senior Executive"; else if ( x == "EX") return "Executive"; else if ( x == "JE") return "Junior Executive"; return NULL; } int EmployeeRec::showIC(int x) { int b, c, d; b = nric/1000000; d = fmod(nric, 10000); c = fmod((nric/10000),100); switch(x) { case 1: return b; break; case 2: return c; break; case 3: return d; break; } return 0; }

#include "HR.h" #include "Staff.h" #include "Login.h" void HR::viewMenu() { int select; HR_IO *hrio_obj; Staff a; Login back2Login; do { hrio_obj = new HR_IO; top: cout << endl<<endl ; cout << "\t\t****************************************" cout << "\t\t* Human Recource Menu *" cout << "\t\t****************************************" cout << "\t\t* *" cout << "\t\t* 1. View Record *" cout << "\t\t* 2. Add Record *" cout << "\t\t* 3. Search Record *" cout << "\t\t* 4. Edit Record *" cout << "\t\t* 5. Delete Record *" cout << "\t\t* 0. Logout *" cout << "\t\t* *" cout << "\t\t****************************************" select = a.menuSelection(); switch(select) { case 0: char logout; cout << "Are you sure want to log out? (Y/N)"; cin >> logout; if (logout == 'Y' || logout == 'y') { cout << "You are back to Login!"; back2Login.LoginModule(); break; } else if (logout == 'N' || logout == 'n') { goto top; } case 1: cout <<endl<<endl; cout<<"\t**************************************************************"<<endl; cout<<"\t* View staff record! *" << endl; cout<<"\t**************************************************************"<<endl<<en dl; hrio_obj->viewFromFile(); break; case 2:

<<endl; <<endl; <<endl; <<endl; <<endl; <<endl; <<endl; <<endl; <<endl; <<endl; <<endl; <<endl;

cout <<endl<<endl; cout<<"\t**************************************************************"<<endl; cout<<"\t* Add staff record! *" << endl; cout<<"\t**************************************************************"<<endl<<en dl; hrio_obj->add(); break; case 3: cout << "Hi, you're searching! The function is implemented!" << endl; hrio_obj->searchMenu(); break; case 4: cout <<endl<<endl; cout<<"\t**************************************************************"<<endl; cout<<"\t* Edit staff record! *" << endl; cout<<"\t**************************************************************"<<endl<<en dl; hrio_obj->edit(); break; case 5: cout <<endl<<endl; cout<<"\t**************************************************************"<<endl; cout<<"\t* Delete staff record! *" << endl; cout<<"\t**************************************************************"<<endl<<en dl; hrio_obj->del(); break; } delete hrio_obj; } while (select != 0); } string HR::set_Department() { Login userLogin; int selection; selectD: cout << "\nAssign a Department" << "\n1. Staff" << "\n2. Human Resource" << "\n\nEnter Selection: "; cin >> selection; switch(selection) { case 1: return "Staff"; break;

case 2: if (userLogin.getUserLevel() == _Admin) { return "HR"; break; } else { cout << "\nThe current user level has no privilege for this action." << "\nPlease try again..."; system("PAUSE"); goto selectD; } break; } return NULL; } void HR_IO::viewFromFile() { int c = 0; int q = 0; EmployeeRec *x = new EmployeeRec(); ifstream inStaff; inStaff.open("staff", ios::beg | ios::in); if(!inStaff) { cout<<endl<<endl<<"\t\tNo data inside, please insert new data!"<<endl<<endl; return; } inStaff.seekg(0); inStaff.read(reinterpret_cast<char *>(x),sizeof(HR)); while(inStaff && !inStaff.eof()) { c += 1; if(x->getEmpID()!=0) { x->display(); } else { q += 1; } inStaff.read(reinterpret_cast<char *>(x),sizeof(HR)); } if (c == q) cout<<endl<<endl<<"\t\tNo data inside, please insert new data!"<<endl<<endl; inStaff.close(); } void HR_IO::add() { int designation, dob[3], datejoined[3];

string name, gender, department, nationality, religion, status; double nric; EmployeeRec *x = new EmployeeRec(); HR *hr_ptr = new HR(); cout << "\nEnter the Data:- " << endl; cout << "\nName: "; cin >> name; cout << "\nNRIC (14 digits only w/o dash): "; cin >> nric; cout << "\nGender: "; cin >> gender; cout << "\nSelect a Designation: " << endl << "\t1. Managing Director" << endl << "\t2. Senior Manager" << endl << "\t3. Manager" << endl << "\t4. Senior Executive" << endl << "\t5. Executive" << endl << "\t6. Junior Executive" << endl << "Enter selection: "; cin >> designation; cout << "\nDepartment: "; department = hr_ptr->set_Department(); int flag; do { cout << "\nDate Joined: \n" << endl << "\tYear (xxxx): "; cin >> datejoined[0]; cout << endl << "\tMonth (xx): "; cin >> datejoined[1]; cout << endl << "\tDate (xx): "; cin >> datejoined[2]; switch (x->checkYear(datejoined[0], datejoined[1], datejoined[2])){ case 1: cout << "\nCorrect date"; flag = 0; break; case 0: cout << "\nInvalid date!"; flag = 1; break; } } while(flag != 0); cout << "\nNationality: "; cin >> nationality; cout << "\nReligion: "; cin >> religion; cout << "\nDate of Birth: \n"; do { cout << "\n\tYear (xxxx): "; cin >> dob[0]; cout << "\n\tMonth (xx): "; cin >> dob[1]; cout << "\n\tDate (xx): ";

cin >> dob[2]; switch (x->checkYear(dob[0], dob[1], dob[2])){ case 1: cout << "\nCorrect date"; flag = 0; break; case 0: cout << "\nInvalid date!"; flag = 1; break; } } while(flag != 0); cout << "\nMarital Status: "; cin >> status; x->add2EmployeeRec(name,nric,gender,x->selectDesignation(designation), department, datejoined, nationality,religion,dob,status); //BEGIN - write into file ofstream outStaff; outStaff.open("staff",ios::app|ios::binary); if(!outStaff) { cout<<endl<<endl<<"\t\tUnable to open file, please try again!"<<endl<<endl; return; } outStaff.write(reinterpret_cast<const char *>(x),sizeof(HR)); outStaff.close(); cout<<endl<<"\tStaff record saved to database!"<<endl; cout << "The staff's Staff ID is " << x->getEmpID() <<"." <<endl; //x->view(); } void HR_IO::searchMenu() { EmployeeRec *x = new EmployeeRec(); system("CLS"); int sID; cout <<endl<<endl; cout<<"\t**************************************************************"<<endl; cout<<"\t* Search staff record! *" << endl; cout<<"\t**************************************************************"<<endl<<en dl; cout << "\n\tEnter the Staff ID you want to search with" << endl << "\tStaff ID: "; cin >> sID; x->viewRecord(sID); } void HR_IO::edit() { int dob[3], datejoined[3], designation; double nric; string name, gender, department, nationality, religion, status;

EmployeeRec *x = new EmployeeRec(); HR *hr_ptr = new HR(); char proceed; int index,option,tempID; fflush(stdin); //check input for int do { try { cout<<endl<<"\tPlease enter the staff ID to be updated: ";; if(x->checkData(tempID)==true) break; } catch(runtime_error e) { cout<<endl<<e.what(); fflush(stdin); } }while(true); index=x->searchRecord(tempID); if(index==-1) { cout<<endl<<"\tStaff record not found!"<<endl<<endl; return; } else if(index==-2) return; cout<<endl<<"\tContinue update [Y/N]?: "; cin>>proceed; fflush(stdin); if(proceed!='Y'&&proceed!='y'&&proceed!='N'&&proceed!='n') { cout<<endl<<"\tInvalid choice!"<<endl; return; } else if(proceed=='N'||proceed=='n') return; cout<<endl; cout<<"\n1. Name"; cout<<"\n2. IC Number"; cout<<"\n3. Gender"; cout<<"\n4. Designation"; cout<<"\n5. Department"; cout<<"\n6. Date Joined"; cout<<"\n7. Nationality"; cout<<"\n8. Religion"; cout<<"\n9. Date of Birth"; cout<<"\n10. Marital Status"; do

{ cout<<endl<<"\tPlease select which field to update [1-10]: "; cin>>option; fflush(stdin); switch(option) { case 1: cout<<endl<<"\nName: "<<x->getName()<<endl; cout<<"\nNew Name: "; cin >> name; x->setName(name); break; case 2: cout<<endl<<"\nIC Number: "<<x->showIC(1) << "-" << x->showIC(2) << "-" << x->showIC(3)<<endl; cout<<"\nNew IC Number: "; cin >> nric; x->setNRIC(nric); break; case 3: cout<<endl<<"\nGender: "<<x->getGender()<<endl; cout<<"\nNew Gender: "; cin >> gender; x->setGender(gender); break; case 4: cout<<endl<<"\nDesignation: "<<x->getDesignation()<<endl; cout<<"\nNew Designation: "; cout << "\nSelect a New Designation: " << endl << "\t1. Managing Director" << endl << "\t2. Senior Manager" << endl << "\t3. Manager" << endl << "\t4. Senior Executive" << endl << "\t5. Executive" << endl << "\t6. Junior Executive" << endl << "Enter selection: "; cin >> designation; x->setDesignation(x->selectDesignation(designation)); break; case 5: cout<<endl<<"\nDepartment: "<<x->getDepartment()<<endl; cout<<"\nNew Department: "; x->setDepartment(hr_ptr->set_Department()); break; case 6: cout<<endl<<"\nDate of Joined: "<<x->getDatejoined(0)<<"-"<<x>getDatejoined(1)<<"-"<<x->getDatejoined(2)<<endl; //validation for date int flag; do { cout << "\nNew Date Joined: \n" <<

endl << "\tYear (xxxx): "; cin >> datejoined[0]; cout << endl << "\tMonth (xx): "; cin >> datejoined[1]; cout << endl << "\tDate (xx): "; cin >> datejoined[2]; switch (x->checkYear(datejoined[0], datejoined[1], datejoined[2])) { case 1: cout << "\nCorrect date"; flag = 0; break; case 0: cout << "\nInvalid date!"; flag = 1; break; } } while(flag != 0); x->setDatejoined(datejoined); break; case 7: cout<<endl<<"\nNationality: "<<x->getNationality()<<endl; cout<<"\nNew Nationality: "; cin >> nationality; x->setNationality(nationality); break; case 8: cout<<endl<<"\nReligion: "<<x->getReligion()<<endl; cout<<"\nNew Religion: "; cin >> religion; x->setReligion(religion); break; case 9: cout<<endl<<"\nDate of Birth: "<<x->getDob(0)<<"-"<<x->getDob(1)<<""<<x->getDob(2)<<endl; //validation for date do { cout << "\nNew Date of Birth: \n" << endl << "\tYear (xxxx): "; cin >> dob[0]; cout << endl << "\tMonth (xx): "; cin >> dob[1]; cout << endl << "\tDate (xx): "; cin >> dob[2]; switch (x->checkYear(dob[0], dob[1], dob[2])) { case 1: cout << "\nCorrect date"; flag = 0; break; case 0: cout << "\nInvalid date!"; flag = 1;

break; } } while(flag != 0); x->setDob(dob); break; case 10: cout<<endl<<"\nMarital Status: "<<x->getStatus()<<endl; cout<<"\nNew Marital Status: "; cin >> status; x->setStatus(status); break; default: cout<<endl<<"\tInvalid user choice!"<<endl; break; } cout<<endl<<"\tContinue updating Staff information [Y/N]?: "; cin>>proceed; fflush(stdin); }while(proceed=='Y'||proceed=='y'); fstream outStaff; outStaff.open("staff"); if(!outStaff) { cout<<endl<<endl<<"\t\tUnable to open file, please try again!"<<endl<<endl; return; } outStaff.seekp(index); outStaff.write(reinterpret_cast<const char *>(x),sizeof(HR)); outStaff.close(); cout<<endl<<"\tStaff record updated!"<<endl; } void HR_IO::del() { char cont; int tempId,pos; EmployeeRec *x = new EmployeeRec(); //validation for int input do { fflush(stdin); try { cout<<"\tPlease enter the Staff ID to be deleted: "; if(x->checkData(tempId)==true) break; } catch(runtime_error e) { cout<<endl<<e.what(); fflush(stdin); }

}while(true); pos=x->searchRecord(tempId); if(pos==-1) { cout<<endl<<"\tStaff record not found!"<<endl; return; } cout<<endl<<"\tContinue delete [Y/N]?: "; cin>>cont;fflush(stdin); if(cont!='Y'&&cont!='y'&&cont!='N'&&cont!='n') { cout<<endl<<"\tInvalid choice!"<<endl; return; } else if(cont=='N'||cont=='n') return; fstream outStaff; outStaff.open("staff"); if(!outStaff) { cout<<endl<<endl<<"\t\tUnable to open file, please try again!"<<endl<<endl; return; } outStaff.seekp(pos); x->setEmpID(0); outStaff.write(reinterpret_cast<const char *>(x),sizeof(HR)); outStaff.close(); cout<<endl<<"\tStaff record deleted!"<<endl; }

#include "Login.h" #include <conio.h> #include "Staff.h" #include "HR.h" #include "Admin.h" //#include "Admin.h" //default constructor Login::Login() { loginID = ""; password = ""; privilege = ""; } void Login::LoginModule() { userLevel = _NotLoggedIn; string id, pw; int fail = 1; fflush(stdin); system("CLS"); cout<<"\n\t\t****************************************" <<endl; cout<<"\t\t* Welcome to Staff Personel System *" <<endl; cout<<"\t\t****************************************" <<endl<<endl; cout << "\t\t ***Please Login to proceed***" << endl << endl; do { fflush(stdin); password = ""; //clear password cout << "\n\n\tLogin ID: "; getline(cin, loginID); cout << endl << "\tPassword: "; //BEGIN - Password Masking http://www.cplusplus.com/forum/general/3766/ char c = ' '; while (c != 13) { c = (char)_getch(); if(c==13) { break; } else if(c == 8) //get backspace { if (password.length()) { cout << "\b \b"; password.erase( password.end() -1 ); } } else { password += c; // get string putchar('*'); } }

//END - Password Masking if (loginID == "Admin" && password == "Admin") { Admin AdminMenu; AdminMenu.viewMenu(); fail = 1; } else if (loginID == "HR" && password == "HR") { userLevel = _HR; HR HRMenu; HRMenu.viewMenu(); fail = 1; } else if (loginID == "Staff" && password == "Staff") { userLevel = _Staff; //cout << "Staff logged in."; Staff StaffMenu; StaffMenu.viewMenu(); fail = 1; } else cout<<"\n\n\t\tInvalid username or password! Please try again!" <<endl<<endl; fail = 0; } while (fail != 1); } //void //{ // // // // // // // // // // // // // // // //} Login::checkPrivilege(string p) Staff staffMenu; HR HRMenu; //Admin adminMenu; if (p == "Admin") { userLevel = _Admin; } else if (p == "Human Resources") userLevel = _HR; HRMenu.viewMenu(); } else if (p == "Staff") { userLevel = _Staff; }

void Login::mainMenu() { system("CLS"); cout << "This menu only shown up after logged in."; cout << "\n\n"; /*if (userLevel = _Admin)*/ }

Conclusion
Creating this system has been extremely difficult. I have learned that several technologies need to be properly understood in order to make a correct website. The first lesson is about sessions, of which I had no idea existed. The first challenge encountered was the login challenge not to actually validate the user credentials but to be able to store temporary variables for the user across pages. Several other problems have hindered the progress of this work, and the final website is the combined effort of several weeks of hard work. I wish to thank my university for giving me the opportunity to make such an assignment. I truly have learned a lot and I now view dynamic websites with a different eye.

Вам также может понравиться