Question

In: Computer Science

implementing linked list using c++ Develop an algorithm to implement an employee list with employee ID,...

implementing linked list using c++

  1. Develop an algorithm to implement an employee list with employee ID, name, designation and department using linked list and perform the following operations on the list.
  1. Add employee details based on department
  2. Remove employee details based on ID if found, otherwise display appropriate message
  3. Display employee details
  4. Count the number of employees in each department

Solutions

Expert Solution

I Have Atteched screenshots of output of program

#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;
    }
};
//It will return the pointer of new employee

Employee  *AddEmployee(unordered_map<string,int>&department_count,unordered_map<int,bool>&cheking_id){
    
    string name,designation,department;
    int employeeID;
    bool br=true;
    while(br){
    cout<<"Enter EmploeeID: ";
    cin>>employeeID;
    
    if(cheking_id[employeeID]==true)
    {
        cout<<"Employee Id is Already Prsent,Please enter Other Id\n";

    }else{
        cheking_id[employeeID]=true;
        br=false;
    }


    }

    cout<<"Enter Name: ";
    cin>>name;
    cout<<"Enter Department: ";
    cin>>department;
    cout<<"Enter designation : ";
    cin>>designation;
    Employee *nw=new Employee(employeeID,name,designation,department);
//It is used to count department type
    department_count[department]++;
    return nw;

}
//deleting the emplyee

Employee*  deleteEmployee(Employee *first, unordered_map<string,int>&department_count,unordered_map<int,bool>&cheking_id){
    int ID;
    cout<<"Enter Employee Id:";
    cin>>ID;
    Employee *temp=first,*prev=NULL;

    //maintaining prev so we could get parent pointer of deleting Node

    while(temp!=NULL&&temp->employeeID!=ID){
        prev=temp;
        temp=temp->next;
    }
//if temp is NULL that means that employeeId is not present
    if(temp!=NULL){
        //we are deleting the employee so we need to delete
        //employee department we counted and employeeid 
        department_count[temp->department]--;
        cheking_id[temp->employeeID]=false;
         //Handling case where deleting node is first node
        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 displayEmployeeDetails(Employee *first){
     Employee *temp=first;
    if(first==NULL)
    {
        cout<<"We Don't have any emploee details\n";
        return;
    }
    bool found=false;
    int id;
    cout<<"Enter EmployeeID:";
    cin>>id;
    //traversing linked list to get add details of employess
    while(temp!=NULL){

       if(id==temp->employeeID)
       {
           cout<<"===Employee Details===\n";
        cout<<"Employee ID: "<<temp->employeeID<<endl;
        cout<<"Employee name: "<<temp->name<<endl;
        cout<<"Employee Designation: "<<temp->designation<<endl;
        cout<<"Emplyee department : "<<temp->department<<endl;
         
           cout<<endl;
        found=true;
        break;
       }
        temp=temp->next;
    }
    if(!found)
    cout<<"Entered EmployeeID Employee is not found\n";

}


void displayDepartmentCount(unordered_map<string,int>&department_count){
       if(department_count.size()==0)
       {
           cout<<"NO Emploee Details Present\n";
           return;
       }
       //print the department and its count

       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;
     unordered_map<int,bool>cheking_id;
     Employee *first=NULL,*last=NULL;
    
    while(1){
        cout<<"\n1.Add Employee\n2.Delete Emploee\n3.Display All Emploee Details\n4.Display Perticular Employee Detail\n5.Display count of Each department\n6.Exit\nEnter choice:\n";
        cin>>choice;

        switch (choice)
        {
        case 1:{
               
            /* code */
            
            Employee *nw=AddEmployee(department_count,cheking_id);
            if(first==NULL)
            first=last=nw;
            else
            {
                last->next=nw;
                last=nw;
            }
            

            break;
        }
        case 2:
            first=deleteEmployee(first,department_count,cheking_id);
            break;
        case 3:
            displayAll(first);

            break;
        case 4:
             displayEmployeeDetails(first);
            break;
        case 5:
            displayDepartmentCount(department_count);
            break;
        case 6:
           return 0;
           break;

        default:
        cout<<"Enter Valid choice ";
            break;
        }
    }
    
}
 

Related Solutions

Develop an algorithm to implement an employee list with employee ID ,name designation and department using...
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
(Write a C# program DO NOT USE CLASS)Implement the merge sort algorithm using a linked list...
(Write a C# program DO NOT USE CLASS)Implement the merge sort algorithm using a linked list instead of arrays. You can use any kind of a linked structure, such as single, double, circular lists, stacks and/or queues. You can populate your list from an explicitly defined array in your program. HINT: You will not be using low, middle and high anymore. For finding the middle point, traverse through the linked list while keeping count of the number of nodes. Break...
Develop an algorithm and implement a Preemptive Priority scheduling algorithm using C++ and using bubble sorting...
Develop an algorithm and implement a Preemptive Priority scheduling algorithm using C++ and using bubble sorting .Arrival time, burst time and priority values.The code should also display: (i) Gantt chart and determine the following: (ii) Determine the Turnaround time(TAT), waiting time(WT) of each process (iii) Determine the Average Waiting Time (AWT) and Average Turnaround Time (ATAT) of all processes. please write the comments
Develop an algorithm and implement Optimal Page Replacement algorithm using C++. Determine the number of page...
Develop an algorithm and implement Optimal Page Replacement algorithm using C++. Determine the number of page faults and page hits by considering the Frame size=4, ReferenceString:2 4 6 7 8 2 4 9 13 9 2 7 2 6 1 4 9 2
Develop an algorithm and implement Multilevel Queuing scheduling using C++.and using bubble sorting. Consider a set...
Develop an algorithm and implement Multilevel Queuing scheduling using C++.and using bubble sorting. Consider a set of user and system processes and determine (i) turnaround time (ii) waiting time of each process (iii) Average Waiting Time (AWT) and (iv) Average Turnaround Time (ATAT) of all processes. please write comment
In C++, Implement the queue ADT with a singly linked list
In C++, Implement the queue ADT with a singly linked list
using C++. edit this code down below so that it will implement stack with linked list...
using C++. edit this code down below so that it will implement stack with linked list contains a default constructor, a copy constructor, and a destructor. #include <iostream> #include <vector> #include <string> #include <stack> #include <limits> using namespace std; class Stack { public: bool isEmpty(); int top(); int pop(); void push(int); void printList(); private: vector<int> elements; }; bool Stack::isEmpty() { return elements.empty(); } int Stack::top() { if(isEmpty()) { throw runtime_error("error: stack is empty"); } return elements.back(); } int Stack::pop() {...
C++ Data Structures: Implement a Stack and a Queue using Linked list In this lab you...
C++ Data Structures: Implement a Stack and a Queue using Linked list In this lab you will implement the functionality of a stack and a queue using a linked list. Your program must use of the declaration of the Stack and Queue class in Stack.h and Queue.h You have to implement the functionalities of queue (enq, deq, displayQueue) in a file called Queue.cpp. All the functions in Queue.cpp should follow the prototypes declared in Queue.h. Your code should make use...
Write a program of doubly Circular linked list to maintain records of employees. Take employee ID,...
Write a program of doubly Circular linked list to maintain records of employees. Take employee ID, name and salary as data of each employee. Search a particular record on ID and display the previous and next records as well. Whichever ID it give, it should display all the records because of being circular. Code needed in Java.
(using single linkedlist c++)In this assignment, you will implement a Polynomial linked list(using single linkedlist only),...
(using single linkedlist c++)In this assignment, you will implement a Polynomial linked list(using single linkedlist only), the coefficients and exponents of the polynomial are defined as a node. The following 2 classes should be defined. p1=23x 9 + 18x 7+3 1. Class Node ● Private member variables: coefficient (double), exponents (integer), and next pointer. ● Setter and getter functions to set and get all member variables ● constructor 2. Class PolynomialLinkedList ● Private member variable to represent linked list (head)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT