0% found this document useful (0 votes)
17 views

Employee Management System

The document describes an employee management system built with C++. The system allows users to add, view, edit and delete employee records stored in a file. It uses a class with functions for listing, showing details, editing and adding/removing employee data.

Uploaded by

muhammad moaz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Employee Management System

The document describes an employee management system built with C++. The system allows users to add, view, edit and delete employee records stored in a file. It uses a class with functions for listing, showing details, editing and adding/removing employee data.

Uploaded by

muhammad moaz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Employee Management System

SUBMITTED TO:

Mr. Muhammad Faheem

SUBMITTED BY:

Talha Attaullah (23-CS-97)

Hadia Qasim(23-CS-99)

Rao Huzaifa Aqeel (23-CS-102)

Hannan Asad (23-CS-103)


2nd Semester

Department of Computer Science, UET Taxila

#include<iostream>
#include<conio.h>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<windows.h>
#include<unistd.h>
using namespace std;

class employee{
private:
// Variables for employee details
char name[30];
char id[5];
char designation[10];
int age;
int ctc;
int experience;

// Utility functions
void waitForEnter(void){
cout<<"\n\n\n Press enter to go back \n\n";
cin.get();
cin.get();
}

// Functions to perform desired actions


void listEmployees(void){ //To list total employees with Name, Id and Designation
system("cls");
FILE *file;
file= fopen("data.txt", "r");
cout<<"\n\t List of Employees\n";
cout<<"\n----------------------------------------------";
cout<<"\n NAME | ID | DESIGNATION\n";
cout<<"----------------------------------------------";
while(fscanf(file, "%s %s %s %d %d %d", &name[0], &id[0] , &designation[0], &age, &ctc,
&experience)!= EOF)
cout<<"\n"<<name<<"\t\t"<<id<<"\t\t"<<designation;
fclose(file);
waitForEnter();
}

void showDetails(void){ //Displays all details according to Employee's id


system("cls");
FILE *file;
char checkId[5];
cout<<"\n\nEnter Employee ID: ";
cin>>checkId;
file= fopen("data.txt", "r");
while(fscanf(file, "%s %s %s %d %d %d", &name[0], &id[0] , &designation[0], &age, &ctc,
&experience)!=EOF)
if(strcmp(checkId,id)==0){
cout<<"\n---------------------";
cout<<"\nName: "<<name;
cout<<"\n---------------------";
cout<<"\nId: "<<id;
cout<<"\n---------------------";
cout<<"\nDesignation: "<<designation;
cout<<"\n---------------------";
cout<<"\nAge: "<<age;
cout<<"\n---------------------";
cout<<"\nCTC: "<<ctc;
cout<<"\n---------------------";
cout<<"\nExperience: "<<experience;
cout<<"\n---------------------";
}
fclose(file);
waitForEnter();
}

void editExisting(void){ //edits Designation and CTC of an employee


system("cls");
char checkId[5];
cout<<"\nEnter employee id: ";
cin>>checkId;
char newDesignation[10];
cout<<"\n-----------------------------";
cout<<"\nEnter new designation: ";
cin>>newDesignation;
int newCtc;
cout<<"------------------------------";
cout<<"\nEnter new CTC: ";
cin>>newCtc;
FILE *file, *tempfile;
file= fopen("data.txt", "r");
tempfile= fopen("temp.txt", "w");
while(fscanf(file, "%s %s %s %d %d %d", &name[0], &id[0] , &designation[0], &age, &ctc,
&experience)!=EOF){
if(strcmp(checkId, id)==0)
fprintf(tempfile, "%s %s %s %d %d %d \n", name, id, newDesignation, age, newCtc, experience
);
else
fprintf(tempfile, "%s %s %s %d %d %d \n", name, id, designation, age, ctc, experience );
}
fclose(file);
fclose(tempfile);
int isRemoved= remove("data.txt");
int isRenamed= rename("temp.txt", "data.txt");
waitForEnter();
}

void addNewEmployee(void){ //adding records


system("cls");
cout<<"\n----------------------------------------";
cout<<"\n Enter First Name of Employee: ";
cin>>name;
cout<<"\n----------------------------------------";
cout<<"\n Enter Employee ID [max 4 digits]: ";
cin>>id;
cout<<"\n----------------------------------------";
cout<<"\n Enter Designation: ";
cin>>designation;
cout<<"\n----------------------------------------";
cout<<"\n Enter Employee Age: ";
cin>>age;
cout<<"\n----------------------------------------";
cout<<"\n Enter Employee CTC: ";
cin>>ctc;
cout<<"\n----------------------------------------";
cout<<"\n Enter Employee Experience: ";
cin>>experience;
cout<<"\n----------------------------------------";

char ch;
cout<<"\nEnter 'y' to save above information\n";
cin>>ch;
if(ch=='y'){
FILE *file;
file= fopen("data.txt","a");
fprintf(file, "%s %s %s %d %d %d \n", name, id, designation, age, ctc, experience );
fclose(file);
cout<<"\nNew Employee has been added to database\n";
}
else
addNewEmployee();
waitForEnter();
}

void deleteEmployeeDetails(void){ //removing records


system("cls");
char checkId[5];
cout<<"\n----------------------------------";
cout<<"\nEnter Employee Id To Remove: ";
cin>>checkId;
char ch;
cout<<"----------------------------------";
cout<<"\n\n\n\n\nCONFIRMATION\nEnter 'y' To Confirm Deletion \n";
cin>>ch;
if(ch=='y'){
FILE *file, *tempfile;
file= fopen("data.txt", "r");
tempfile= fopen("temp.txt", "w");
while(fscanf(file, "%s %s %s %d %d %d", &name[0], &id[0] , &designation[0], &age, &ctc,
&experience)!=EOF)
if(strcmp(checkId, id)!=0)
fprintf(tempfile, "%s %s %s %d %d %d \n", name, id, designation, age, ctc, experience );
fclose(file);
fclose(tempfile);
int isRemoved= remove("data.txt");
int isRenamed= rename("temp.txt", "data.txt");
cout<<"\nRemoved Successfully\n";
waitForEnter();
}
else
deleteEmployeeDetails();
}

public:
// Function to serve as end point
void options(void){ //menu
int login(); //login declaration
login();//login screen
while(true){
system("cls");

// Options to choose an action


cout<<"\n\t\t\t>>>>>>>>> EMPLOYEE MANAGEMENT SYSTEM <<<<<<<<<";
cout<<"\n";
cout<<"\n\t\t\t------------------------------------------------";
cout<<"\n\t\t\tENTER 1: To View List of Employees";
cout<<"\n\t\t\t------------------------------------------------";
cout<<"\n\t\t\tENTER 2: To View Employee Details";
cout<<"\n\t\t\t------------------------------------------------";
cout<<"\n\t\t\tENTER 3: To Modify Existing Employee Details";
cout<<"\n\t\t\t------------------------------------------------";
cout<<"\n\t\t\tENTER 4: To Add New Employee Details";
cout<<"\n\t\t\t------------------------------------------------";
cout<<"\n\t\t\tENTER 5: To Remove an Employee Details";
cout<<"\n\t\t\t------------------------------------------------";
cout<<"\n\t\t\tENTER 0: To Exit ";
cout<<"\n\t\t\t------------------------------------------------";
cout<<"\n\n\t\t\t Please Enter Your Choice: ";

// Taking the action input


int choice;
cin>>choice;
// Calling relevant function as per choice
switch (choice) {
case 0:
system("CLS");
cout<<"\n\nEMPLOYEE MANAGEMENT SYSTEM \n\n Brought To You By code-
projects.org\n\n ";
Sleep(10);
return;
case 1:
listEmployees();
break;
case 2:
showDetails();
break;
case 3:
editExisting();
break;
case 4:
addNewEmployee();
break;
case 5:
deleteEmployeeDetails();
break;
default:
cout<<"\n Sorry! I don't understand that! \n";
break;
}

}
}

};

int main(){
// Call the options function
employee e;
e.options();
return 0;
}

int login(){ //login procedure


string pass ="";
char ch;
cout <<"\n\n\n\n\t\t\t\t\tEMPLOYEE MANAGEMENT SYSTEM";
cout <<"\n\n\n\n\n\t\t\t\t\tEnter Your Password :";
ch = _getch();
while(ch != 13){//character 13 is enter
pass.push_back(ch);
cout << '*';
ch = _getch();
}
if(pass == "pass"){
cout<<"\n\n\n\t\t\t\t\tLOADING \n\t\t\t\t\t";
for(int a=1;a<8;a++) // Change 'a<?' to how many * you want
{
Sleep(500);
cout << "...";
}
cout << "\n\n\n\t\t\t\t\tAccess Granted!! \n\n\n";

system("PAUSE");
system("CLS");
}else{
cout << "\nAccess Aborted...\n";
login();
}
}
OUTPUT :
1 : To Add Employe

2: To View Employe Details


3: To View List Of Employee

4: To Delete Employee
Introduction:

The Employee Management System (EMS) is designed to streamline employee data management
within an organization. This system allows administrators to perform various tasks such as adding
new employee records, editing existing employee details, deleting employee records, and viewing
employee information.
The system is implemented using C++ programming language and utilizes file handling for data
storage. It provides a menu-driven interface for easy navigation and interaction.

Methodology:

Class Structure:

The EMS is implemented using a single class employee, which encapsulates all the
necessary functionalities and data members.

Data Members:

➢ name: Stores the name of the employee.


➢ id: Stores the unique identifier of the employee.
➢ designation: Stores the job designation of the employee.
➢ age: Stores the age of the employee.
➢ ctc: Stores the cost to company (CTC) of the employee.
➢ experience: Stores the experience of the employee.

Member Functions:

1. waitForEnter(): Waits for the user to press enter before proceeding.


2. listEmployees(): Lists all employees with their name, ID, and designation.
3. showDetails(): Displays detailed information about a specific employee based on
their ID.
4. editExisting(): Allows editing of an existing employee's designation and CTC.
5. addNewEmployee(): Adds a new employee record to the system.
6. deleteEmployeeDetails(): Deletes an existing employee record from the system.
7. options(): Displays the main menu and handles user input to execute the desired
functionality.

Main Function:
The main() function initializes an object of the employee class and calls the options()
function to start the EMS.

Login Function:

The login() function is implemented to provide access control to the system. Users are
prompted to enter a password, and access is granted upon successful authentication.
Working:

Login Procedure:
• Upon running the program, users are prompted to enter a password.
• If the correct password is entered, access is granted, and the main menu is displayed.
• If the password is incorrect, access is denied, and users are prompted to retry.

Main Menu:
• Users are presented with a menu displaying various options such as viewing
employee lists, adding, editing, or deleting employee records, and exiting the
system.
• Users can input their choice, and the corresponding functionality is executed.

Functionality:
• Viewing Employee Lists: Displays a list of all employees with their basic
information.
• Viewing Employee Details: Allows users to view detailed information about a
specific employee by entering their ID.
• Editing Existing Employee Details: Enables users to modify the designation and
CTC of an existing employee by entering their ID.
• Adding New Employee Details: Allows users to input details of a new employee and
adds them to the system.
• Deleting Employee Details: Enables users to remove an existing employee record
from the system by entering their ID.

Data Storage:

• Employee records are stored in a text file named data.txt.


• File handling operations are performed to read from and write to this file during
various functionalities.

You might also like