Employee Management System
INTRODUCTION:
Employee Management System program is to provide a user-friendly interface for managing employee records efficiently. The program allows users to perform various operations on employee data, including adding new employees, displaying all employees, searching for employees by ID, updating employee details, and deleting employees.
By offering these functionalities, the program aims to streamline the process of managing employee information within an organization. It provides a simple and intuitive interface for users to interact with employee data, facilitating tasks such as adding new hires, updating existing employee details, and removing terminated employees from the system.
OBJECTIVES OF THE PROJECT:
The objective of this project is to let the students apply the
programming knowledge into a real- world situation/problem and
exposed the students how programming skills helps in developing a
good software.
1. Write programs utilizing modern software tools.
2. Apply object oriented programming principles effectively when
developing small to medium sized projects.
3. Write effective procedural code to solve small to medium sized
problems.
4. Students will demonstrate a breadth of knowledge in computer
science, as exemplified in the areas of systems, theory and
software development.
5. Students will demonstrate ability to conduct a research or
applied Computer Science project, requiring writing and
presentation skills which exemplify scholarly style in computer
science.
Algorithm :
Step 1. Begin the program.
Step 2. Declare a structure Employee with members id, name, age, and salary.
Step 3. Declare function prototypes for adding, displaying, searching, updating, and deleting employees.
Step 4. Define the main function.
Step 5. Declare an array employees of type Employee to store employee records, with a maximum capacity of 100 employees.
Step 6. Declare a variable numEmployees to keep track of the number of employees in the array.
Step 7. Start a do-while loop to display the menu and execute user-selected options until the user chooses to exit.
Step 8. Inside the loop, display the menu options:
a. Add Employee
b. Display All Employees
c. Search Employee by ID
d. Update Employee Details
e. Delete Employee
f. Exit
Step 9. Prompt the user to enter their choice.
Step 10. Use a switch statement to execute the corresponding function based on the user's choice:
a. If the choice is 1, call the addEmployee function.
b. If the choice is 2, call the displayAllEmployees function.
c. If the choice is 3, call the searchEmployeeByID function.
d. If the choice is 4, call the updateEmployeeDetails function.
e. If the choice is 5, call the deleteEmployee function.
f. If the choice is 6, display "Exiting..." and exit the loop.
Step 11. End the do-while loop.
Step 12. Return 0 to indicate successful execution and end the program.
Source code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Define structure for Employee
struct Employee {
int id;
char name[50];
int age;
float salary;
};
// Function prototypes
void addEmployee(struct Employee emp[], int *numEmployees);
void displayAllEmployees(struct Employee emp[], int numEmployees);
void searchEmployeeByID(struct Employee emp[], int numEmployees);
void updateEmployeeDetails(struct Employee emp[], int numEmployees);
void deleteEmployee(struct Employee emp[], int *numEmployees);
int main() {
struct Employee employees[100]; // Maximum 100 employees
int numEmployees = 0;
int choice;
do {
printf("\nEmployee Management System\n");
printf("1. Add Employee\n");
printf("2. Display All Employees\n");
printf("3. Search Employee by ID\n");
printf("4. Update Employee Details\n");
printf("5. Delete Employee\n");
printf("6. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch(choice) {
case 1:
addEmployee(employees, &numEmployees);
break;
case 2:
displayAllEmployees(employees, numEmployees);
break;
case 3:
searchEmployeeByID(employees, numEmployees);
break;
case 4:
updateEmployeeDetails(employees, numEmployees);
break;
case 5:
deleteEmployee(employees, &numEmployees);
break;
case 6:
printf("Exiting...\n");
break;
default:
printf("Invalid choice. Please enter a number between 1 and 6.\n");
}
} while(choice != 6);
return 0;
}
// Function to add a new employee
void addEmployee(struct Employee emp[], int *numEmployees) {
if (*numEmployees < 100) {
printf("Enter Employee ID: ");
scanf("%d", &emp[*numEmployees].id);
printf("Enter Employee Name: ");
scanf("%s", emp[*numEmployees].name);
printf("Enter Employee Age: ");
scanf("%d", &emp[*numEmployees].age);
printf("Enter Employee Salary: ");
scanf("%f", &emp[*numEmployees].salary);
(*numEmployees)++;
printf("Employee added successfully.\n");
} else {
printf("Maximum number of employees reached.\n");
}
}
// Function to display all employees
void displayAllEmployees(struct Employee emp[], int numEmployees) {
if (numEmployees == 0) {
printf("No employees to display.\n");
} else {
printf("Employee Details:\n");
for (int i = 0; i < numEmployees; i++) {
printf("Employee %d:\n", i+1);
printf("ID: %d\n", emp[i].id);
printf("Name: %s\n", emp[i].name);
printf("Age: %d\n", emp[i].age);
printf("Salary: %.2f\n", emp[i].salary);
}
}
}
// Function to search for an employee by ID
void searchEmployeeByID(struct Employee emp[], int numEmployees) {
if (numEmployees == 0) {
printf("No employees to search.\n");
return;
}
int id;
printf("Enter Employee ID to search: ");
scanf("%d", &id);
int found = 0;
for (int i = 0; i < numEmployees; i++) {
if (emp[i].id == id) {
printf("Employee found:\n");
printf("ID: %d, Name: %s, Age: %d, Salary: %.2f\n", emp[i].id, emp[i].name, emp[i].age, emp[i].salary);
found = 1;
break;
}
}
if (!found) {
printf("Employee with ID %d not found.\n", id);
}
}
// Function to update employee details
void updateEmployeeDetails(struct Employee emp[], int numEmployees) {
if (numEmployees == 0) {
printf("No employees to update.\n");
return;
}
int id;
printf("Enter Employee ID to update: ");
scanf("%d", &id);
int found = 0;
for (int i = 0; i < numEmployees; i++) {
if (emp[i].id == id) {
printf("Enter new details for Employee %d:\n", emp[i].id);
printf("Enter Employee Name: ");
scanf("%s", emp[i].name);
printf("Enter Employee Age: ");
scanf("%d", &emp[i].age);
printf("Enter Employee Salary: ");
scanf("%f", &emp[i].salary);
printf("Employee details updated successfully.\n");
found = 1;
break;
}
}
if (!found) {
printf("Employee with ID %d not found.\n", id);
}
}
// Function to delete an employee
void deleteEmployee(struct Employee emp[], int *numEmployees) {
if (*numEmployees == 0) {
printf("No employees to delete.\n");
return;
}
int id;
printf("Enter Employee ID to delete: ");
scanf("%d", &id);
int found = 0;
for (int i = 0; i < *numEmployees; i++) {
if (emp[i].id == id) {
for (int j = i; j < *numEmployees - 1; j++) {
emp[j] = emp[j + 1];
}
(*numEmployees)--;
printf("Employee with ID %d deleted successfully.\n", id);
found = 1;
break;
}
}
if (!found) {
printf("Employee with ID %d not found.\n", id);
}
}
OUTPUT:
Employee Management System
1. Add Employee
2. Display All Employees
3. Search Employee by ID
4. Update Employee Details
5. Delete Employee
6. Exit
Enter your choice: 1
Enter Employee ID: 101
Enter Employee Name: Ramesh
Enter Employee Age: 30
Enter Employee Salary: 50000
Employee added successfully.
Employee Management System
1. Add Employee
2. Display All Employees
3. Search Employee by ID
4. Update Employee Details
5. Delete Employee
6. Exit
Enter your choice: 2
Employee Details:
Employee 1:
ID: 101
Name: Ramesh
Age: 30
Salary: 50000.00
Employee Management System
1. Add Employee
2. Display All Employees
3. Search Employee by ID
4. Update Employee Details
5. Delete Employee
6. Exit
Enter your choice: 3
Enter Employee ID to search: 101
Employee found:
ID: 101, Name: Ramesh, Age: 30, Salary: 50000.00
Employee Management System
1. Add Employee
2. Display All Employees
3. Search Employee by ID
4. Update Employee Details
5. Delete Employee
6. Exit
Enter your choice: 4
Enter Employee ID to update: 101
Enter new details for Employee 101:
Enter Employee Name: Suresh
Enter Employee Age: 32
Enter Employee Salary: 55000
Employee details updated successfully.
Employee Management System
1. Add Employee
2. Display All Employees
3. Search Employee by ID
4. Update Employee Details
5. Delete Employee
6. Exit
Enter your choice: 5
Enter Employee ID to delete: 101
Employee with ID 101 deleted successfully.
Employee Management System
1. Add Employee
2. Display All Employees
3. Search Employee by ID
4. Update Employee Details
5. Delete Employee
6. Exit
Enter your choice: 6
Exiting...
CONCLUSION:
The Employee Management System program provides a convenient way to manage employee records efficiently. With its user-friendly interface and robust functionality, it helps organizations streamline their employee management processes.
No comments: