-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmployee.c
216 lines (174 loc) · 6.89 KB
/
Employee.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
#include <stdio.h>
#include <stdlib.h>
void main()
{
struct Employee
{
int empId;
char empName[30];
float totalSalary;
};
struct Node
{
struct Employee employee;
struct Node *address;
};
struct Node *START = NULL;
struct Node *PTR = NULL;
struct Node *NEWNODE = NULL;
struct Node *PREV = NULL;
int choice;
do
{
printf("\n\n-------- Employee Menu ----------");
printf("\n1). Insert Employee Details");
printf("\n2). Display Details in Tabular Form");
printf("\n3). Find Highest and Lowest Salary Employee");
printf("\n4). Identify Employee with Salary Rs.10000");
printf("\n5). Exit");
printf("\n\nEnter Your Choice: ");
scanf(" %d", &choice);
switch (choice)
{
case 1:
NEWNODE = (struct Node *)malloc(sizeof(struct Node));
NEWNODE->address = NULL;
struct Employee inputEmployee;
printf("\nEnter the Employee Name: ");
scanf(" %[^\n]s", inputEmployee.empName);
printf("\nEnter the Employee ID: ");
scanf(" %d", &inputEmployee.empId);
printf("\nEnter the Employee Salary: ");
scanf(" %f", &inputEmployee.totalSalary);
NEWNODE->employee = inputEmployee;
if (START == NULL)
{
START = NEWNODE;
PTR = NEWNODE;
}
else
{
PTR->address = NEWNODE;
PTR = NEWNODE;
}
printf("\nData Insertion Completed!");
break;
case 2:
if (START == NULL)
{
printf("\nNo Elements to Display");
break;
}
else
{
printf("| Employee Name | ID | Salary |\n");
printf("|---------------------|-----|-----------------|\n");
}
PTR = START;
int index = 1;
while (PTR->address != NULL)
{
printf("| %s | %d | %f |\n",
PTR->employee.empName, PTR->employee.empId, PTR->employee.totalSalary);
PTR = PTR->address;
}
printf("| %s | %d | %f |\n",
PTR->employee.empName, PTR->employee.empId, PTR->employee.totalSalary);
break;
case 3:
struct Employee highestSalary = START->employee;
struct Employee lowestSalary = START->employee;
if (START == NULL)
{
printf("\nNo Elements to Display");
break;
}
PTR = START;
while (PTR->address != NULL)
{
if (PTR->employee.totalSalary > highestSalary.totalSalary)
highestSalary = PTR->employee;
if (PTR->employee.totalSalary < lowestSalary.totalSalary)
lowestSalary = PTR->employee;
PTR = PTR->address;
}
if (PTR->employee.totalSalary > highestSalary.totalSalary)
highestSalary = PTR->employee;
if (PTR->employee.totalSalary < lowestSalary.totalSalary)
lowestSalary = PTR->employee;
printf("\nEmployee With Highest Salary\n\n");
printf("| Employee Name | ID | Salary |\n");
printf("|---------------------|-----|-----------------|\n");
printf("| %s | %d | %f |\n",
highestSalary.empName, highestSalary.empId, highestSalary.totalSalary);
printf("\nEmployee With Lowest Salary\n\n");
printf("| Employee Name | ID | Salary |\n");
printf("|---------------------|-----|-----------------|\n");
printf("| %s | %d | %f |\n",
lowestSalary.empName, lowestSalary.empId, lowestSalary.totalSalary);
break;
case 4:
if (START == NULL)
{
printf("\nNo Elements to Display");
break;
}
else
{
printf("\nEmployees With Salary 10000\n\n");
printf("| Employee Name | ID | Salary |\n");
printf("|---------------------|-----|-----------------|\n");
}
PTR = START;
while (PTR->address != NULL)
{
if (PTR->employee.totalSalary == 10000)
{
printf("| %s | %d | %f |\n",
PTR->employee.empName, PTR->employee.empId, PTR->employee.totalSalary);
PTR = PTR->address;
}
}
if (PTR->employee.totalSalary == 10000)
{
printf("| %s | %d | %f |\n",
PTR->employee.empName, PTR->employee.empId, PTR->employee.totalSalary);
}
break;
default:
printf("\nKindly Enter a Valid Choice!");
}
} while (choice != 5);
}
/*
Algorithm
______________
Start
Declare a structure Employee with members emp_id, emp_name, total_salary and next pointer
Declare a global pointer variable head of Employee type and initialize it to NULL
Declare functions insert_employee_details(), display_employee_details(), display_highest_and_lowest_salary() and identify_employee_with_salary()
In insert_employee_details() function:
a. Allocate memory for a new employee using malloc()
b. Take employee details (emp_id, emp_name, total_salary) as input from user
c. Set next pointer of new_employee to NULL
d. If head is NULL, set head to new_employee
e. Else, traverse the list till the end and set the next pointer of last node to new_employee
In display_employee_details() function:
a. Display employee details in tabular format
In display_highest_and_lowest_salary() function:
a. Traverse the list and keep track of highest and lowest salary employees
b. Display details of highest and lowest salary employees in tabular format
In identify_employee_with_salary() function:
a. Traverse the list and identify employees with salary Rs.10000/
b. Display details of employees with salary Rs.10000/ in tabular format
In main() function:
a. Display menu options
b. Take choice as input from user
c. If choice is 1, call insert_employee_details() function
d. If choice is 2, call display_employee_details() function
e. If choice is 3, call display_highest_and_lowest_salary() function
f. If choice is 4, call identify_employee_with_salary() function
g. If choice is 5, exit the program
h. If choice is invalid, display error message
End
*/