Employee Management System Using C
Algorithm:
1. Define Structure:
● Define a structure e to represent an employee with the
following fields:
○ id (integer)
○ name (character array of size 50)
○ salary (integer)
2. Define Functions:
● Declare the following functions:
○ display(n) to display all employees' details.
○ searchid(int y, int n) to search for an employee by their
ID.
○ salary(n) to display details of employees earning more
than ₹15,000.
3. Input Employee Details:
● Prompt the user to input the number of employees (n).
● Use a loop to collect the following details for n employees:
○ Employee ID
○ Employee Name
○ Employee Salary
4. Menu-Driven Program:
● Display a menu with the following options:
1.Display details of all employees.
2.Search for an employee using their ID.
3.Display details of employees with salaries greater than
₹15,000.
4.Exit the program.
5. Execute Menu Options:
● Use a do-while loop to execute the menu until the user
chooses to exit (option 4).
● Inside the loop, use a switch statement for the menu
options:
1.Option 1: Display Employee Details
■ Call the display(n) function.
■ Iterate through all employees and print their id,
name, and salary.
2.Option 2: Search for Employee by ID
■ Prompt the user to input an employee ID (y).
■ Call searchid(y, n).
■ Search for the employee in the array, and if
found, display their details.
3.Option 3: Display Employees with Salary > ₹15,000
■ Call salary(n).
■ Iterate through all employees and print details of
those whose salary exceeds ₹15,000.
6. Terminate Program:
● Exit the loop when the user chooses option 4.
7. Function Implementations:
●display(n) Function:
○ Loop through all employees and print their details.
● searchid(y, n) Function:
○ Loop through all employees.
○ Compare the input ID (y) with each employee's ID.
○ If a match is found, print the employee's details.
● salary(n) Function:
○ Loop through all employees.
○ Check if their salary is greater than ₹15,000.
○ If true, print the employee's details.
8. End Program:
● Ensure that the program terminates gracefully after all
menu operations are completed.
Flowchart:
Program Source Code:
#include <stdio.h>
#include <string.h>
#include <conio.h>
struct e
{int id;
char name[50];
int salary;
} e[50];
void display (n);
void searchid(int y, int z);
void salary(n);
int main()
{int a, y, n, i, op;
printf("enter the number of employees: \n");
scanf("%d",&n);
for (i=0;i<n;i++)
{printf("\nenter the employee id: ");
scanf("%d",&e[i].id);
printf("\nenter the employee %d name: ",i+1);
scanf("%s",&e[i].name);
printf("\nenter the employee salary: \n");
scanf("%ld",&e[i].salary);}
do
{
printf("\nenter the choice.\[Link] details of
employee\[Link] for employee using search employee
id\[Link] salary of employees more than 15k");
scanf("%d", &op);
switch(op)
{case 1:
{
display(n);
}
break;
case 2:
{
printf("\nenter the employee id");
scanf("%d",&y);
searchid(y,n);
}
break;
case 3:
{
salary(n);
}
break;
}
} while (op!=4);
return 0;}
void display (int n)
{int i;
for (i=0;i<n;i++)
{
printf("\nthe employee id is %d",e[i].id);
printf("\nthe employee name is %s",e[i].name);
printf("\nthe employee salary is %ld",e[i].salary);
}
}
void searchid(int y, int n)
{int i;
for (i=0;i<n;i++)
{ if (y==e[i].id)
{printf("\nemployee id is %d",e[i].id);
printf("\nemployee name is %s",e[i].name);
printf("\nemployee salary is %ld",e[i].salary);}}
}
void salary(n)
{
int i;
for (i=0;i<n;i++)
{
if (e[i].salary>15000)
printf("\nemployee id is %d",e[i].id);
printf("\nemployee name is %s",e[i].name);
printf("\nemployee salary is %ld",e[i].salary);}}
Sample output: