In: Computer Science
Develop an algorithm to implement an employee list with employee ID ,name designation and department using link list and perform the following operation on the list
i)add employee details based on department
ii)remove employee details
iv)count the number of employee in each department
PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU
NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR
YOU
#include <bits/stdc++.h>
using namespace std;
struct Employee
{
int employeeID;
string name;
string designation;
string department;
Employee *next;
Employee(int EmployeeID, string Name, string Designation, string Department)
{
employeeID = EmployeeID;
name = Name;
designation = Designation;
department = Department;
next = NULL;
}
};
Employee *AddEmployee(unordered_map<string, int> &department_count)
{
string name, designation, department;
int employeeID;
cout << "Enter EmploeeID: ";
cin >> employeeID;
cout << "Enter Name: ";
cin >> name;
cout << "Enter Department: ";
cin >> department;
cout << "Enter designation : ";
cin >> designation;
Employee *nw = new Employee(employeeID, name, designation, department);
department_count[department]++;
return nw;
}
Employee *deleteEmployee(Employee *first, unordered_map<string, int> &department_count)
{
int ID;
cout << "Enter Employee Id:";
cin >> ID;
Employee *temp = first, *prev = NULL;
while (temp != NULL && temp->employeeID != ID)
{
prev = temp;
temp = temp->next;
}
if (temp != NULL)
{
department_count[temp->department]--;
if (temp != first)
{
prev->next = temp->next;
cout << "Successfully deleted record of Employee " << temp->name << endl;
}
else
{
first = first->next;
}
delete temp;
}
else
{
cout << "Entered ID Employee is not listed in Company\n";
}
return first;
}
void displayAll(Employee *first)
{
Employee *temp = first;
if (first == NULL)
{
cout << "We Don't have any emploee details\n";
return;
}
while (temp != NULL)
{
cout << "Employee ID: " << temp->employeeID << endl;
cout << "Employee name: " << temp->name << endl;
cout << "Employee Designation: " << temp->designation << endl;
cout << "Emplyee department : " << temp->department << endl;
temp = temp->next;
cout << endl;
}
}
void displayDepartmentCount(unordered_map<string, int> &department_count)
{
if (department_count.size() == 0)
{
cout << "NO Emploee Details Present\n";
return;
}
for (auto department : department_count)
{
cout << department.first << ":" << department.second << endl;
}
}
int main()
{
// freopen("input.txt","r",stdin);
int choice = -1;
unordered_map<string, int> department_count;
Employee *first = NULL, *last = NULL;
while (1)
{
cout << "\n1.Add Employee\n2.Delete Emploee\n3.Display All Emploee Details\n4.Display count of Each department\n5.Exit\nEnter choice:\n";
cin >> choice;
switch (choice)
{
case 1:
{
/* code */
Employee *nw = AddEmployee(department_count);
if (first == NULL)
first = last = nw;
else
{
last->next = nw;
last = nw;
}
break;
}
case 2:
first = deleteEmployee(first, department_count);
break;
case 3:
displayAll(first);
break;
case 4:
displayDepartmentCount(department_count);
break;
case 5:
return 0;
break;
default:
cout << "Enter Valid choice ";
break;
}
}
}