Introduction to Employee Management System Using C++
Employ management system using C++ is a menu-driven program that allows us to add, update, delete and search records of an employee working in an organization. The program employee management system stores employee ID, name, post, department, and salary of the employee. Initially, it has no data. Thus, we have to add employee records choosing appropriate options in this program (i.e. selecting option #1). Previously we had posted Employee Management System Using C with the same features.
Employee Management system using C++ program uses EmpID as a unique identifier (i.e. primary key) to recognize employee. So, we can’t add two employees having the same ID. After successful entry of records of some employees, we can search records on the basis of ID or department. We can search particular employees from ID choosing option #2 and if we want to see all employees working in a department, we have to choose another option (i.e. option#3 in the menu). We can list all employee records also using option #4 in the menu. Again, we can update and delete existing records. Thus, this project is useful to manage employee records in an organization.
Before going to the software code part, let’s see the output. The project Employee Management System Using C++ is compiled using TurboC++
Figure 1: Main Menu of Employee Management System Using C++
Figure 2: Adding New Employee Record
Figure 3: Searching Employee record using Employee ID
Figure 4: Deleting Existing Employee Record
Check out other interesting C++ projects posted on bestengineeringprojects.comÂ
- Telephone Diary using C++
- 3D Ball, graphics-based project on C++
- Base Conversion based on C++
- Color the text [C++ Based]
Software Code for Employee Management System Using C++:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
#include<iostream.h> #include<conio.h> #include<fstream.h> #include<stdlib.h> #include<iomanip.h> #include<string.h> #include<stdio.h> const char* fileName="Employee.txt"; class Employee { private: int EmpID; char EmpName[50],Post[50],Department[10]; float Salary; public: void ReadData(); int GetID(); void DisplayRecord(); char* GetDepartment(); }; void Employee::ReadData() { cout<<endl<<"Employee ID:"; cin>>EmpID; cout<<"Employee Name:"; cin>>EmpName; cout<<"Employee's Post:"; cin>>Post; cout<<"Employee's Department:"; cin>>Department; cout<<"Salary:"; cin>>Salary; } void Employee::DisplayRecord() { cout<<endl<<"_______________________________"; cout<<endl<<setw(5)<<EmpID<<setw(15)<<EmpName<<setw(15)<<Post<<setw(15)<<Department<<setw(8)<<Salary; } int Employee::GetID() { return EmpID; } char* Employee::GetDepartment() { return Department; } void main() { Employee emp,e; char option,ch,Dept[50]; int ID,isFound; clrscr(); fstream file; file.open(fileName,ios::ate|ios::in|ios::out|ios::binary); do { cout<<"*******Menu********"; cout<<endl<<"Enter your option"; cout<<endl<<"1 => Add a new record"; cout<<endl<<"2 => Search record from employee id"; cout<<endl<<"3 => List Employee of particular department"; cout<<endl<<"4 => Display all employee"; cout<<endl<<"5 => Update record of an employee"; cout<<endl<<"6 => Delete record of particular employee"; cout<<endl<<"7 => Exit from the program"<<endl; cout<<"********************"<<endl; cin>>option; switch(option) { case '1': emp.ReadData(); file.seekg(0,ios::beg); isFound=0; file.read((char*)&e,sizeof(e)); while(!file.eof()) { if(e.GetID()==emp.GetID()) { cout<<"This ID already exist...Try for another ID"; isFound=1; break; } file.read((char*)&e,sizeof(e)); } if(isFound==1) break; file.clear(); file.seekp(0,ios::end); file.write((char*)&emp, sizeof(emp)); cout<<endl<<"New record has been added successfully..."; break; case '2': isFound=0; cout<<endl<<"Enter ID of an employee to be searched:"; cin>>ID; file.seekg(0,ios::beg); file.read((char*)&e,sizeof(e)); while(!file.eof()) { if(e.GetID()==ID) { cout<<endl<<"The record found...."<<endl; cout<<endl<<setw(5)<<"ID"<<setw(15)<<"Name"<<setw(15)<<"Post"<<setw(15)<<"Department"<<setw(8)<<"Salary"; e.DisplayRecord(); isFound=1; break; } file.read((char*)&e,sizeof(e)); } file.clear(); if(isFound==0) cout<<endl<<"Data not found for employee ID#"<<ID; break; case '3': isFound=0; cout<<"Enter department name to list employee within it:"; cin>>Dept; file.seekg(0,ios::beg); file.read((char*)&e,sizeof(e)); while(!file.eof()) { if(strcmp(e.GetDepartment(),Dept)==0) { cout<<endl<<"The record found for this department"<<endl; cout<<endl<<setw(5)<<"ID"<<setw(15)<<"Name"<<setw(15)<<"Post"<<setw(15)<<"Department"<<setw(8)<<"Salary"; e.DisplayRecord(); isFound=1; break; } file.read((char*)&e,sizeof(e)); } file.clear(); if(isFound==0) cout<<endl<<"Data not found for department"<<Dept; break; case '4': cout<<endl<<"Record for employee"; file.clear(); file.seekg(0,ios::beg); int counter=0; file.read((char*)&e,sizeof(e)); while(!file.eof()) { counter++; if(counter==1) { cout<<endl<<setw(5)<<"ID"<<setw(15)<<"Name"<<setw(15)<<"Post"<<setw(15)<<"Department"<<setw(8)<<"Salary"; } e.DisplayRecord(); file.read((char*)&e,sizeof(e)); } cout<<endl<<counter<<"records found......"; file.clear(); break; case '5': int recordNo=0; cout<<endl<<"File is being modified...."; cout<<endl<<"Enter employee ID to be updated:"; cin>>ID; isFound=0; file.seekg(0,ios::beg); file.read((char*)&e,sizeof(e)); while(!file.eof()) { recordNo++; if(e.GetID()==ID) { cout<<"The old record of employee having ID"<<ID<< "is:"; e.DisplayRecord(); isFound=1; break; } file.read((char*)&e,sizeof(e)); } if(isFound==0) { cout<<endl<<"Data not found for employee ID#"<<ID; break; } file.clear(); int location=(recordNo-1)*sizeof(e); file.seekp(location,ios::beg); cout<<endl<<"Enter new record for employee having ID"<<ID; e.ReadData(); file.write((char*)&e, sizeof(e)); break; case '6': recordNo=0; cout<<endl<<"Enter employment ID to be deleted:"; cin>>ID; isFound=0; file.seekg(0,ios::beg); file.read((char*)&e,sizeof(e)); while(!file.eof()) { recordNo++; if(e.GetID()==ID) { cout<<" The old record of employee having ID "<<ID<< " is: "; e.DisplayRecord(); isFound=1; break; } file.read((char*)&e,sizeof(e)); } char tempFile[]="temp.txt"; fstream temp(tempFile,ios::out|ios::binary); if(isFound==0) { cout<<endl<<"Data not found for employee ID#"<<ID; break; } else { file.clear(); file.seekg(0,ios::beg); file.read((char*)&e,sizeof(e)); while(!file.eof()) { if(e.GetID()!=ID) temp.write((char*)&e,sizeof(e)); file.read((char*)&e,sizeof(e)); } file.close(); temp.close(); temp.open(tempFile,ios::in|ios::binary); file.open(fileName,ios::out|ios::binary); temp.read((char*)&e,sizeof(e)); while(!temp.eof()) { file.write((char*)&e,sizeof(e)); temp.read((char*)&e,sizeof(e)); } } temp.close(); file.close(); remove(tempFile); file.open(fileName,ios::ate|ios::in|ios::out|ios::binary); break; case '7': exit(0); break; default: cout<<"Invalid Options"; } cout<<"\nDo you want to continue.....?y/n"; cin>>ch; }while(ch!='n'); } |
The above given source code is only working in turbo c++ why not working in Dev-c.
Here are few parameter and keyword which is not supported by DEV-C++
Websites like this are really good, because they help other people who need help or are weak in programming . Keep up the good work. God bless
how to run the program
sir please tell me how i can run this program in dev C++.
please answer my question urgently.