Question

In: Computer Science

C++ Write a program to create a linked list which stores the details of employees(Employee number,...

C++

  • Write a program to create a linked list which stores the details of employees(Employee number, employee name, rate, hours worked). Create a menu to manage the emoployee data.

MENU

1. ADD EMPLOYEE DETAILS

2. DELETE EMPLOYEE

3. SEARCH EMPLOYEE

4. PRINT EMPLOYEE PAYROLL

5. EXIT

  • When the user selected option #4 the program should print the following pay report for each employee:

EmpNo.     Name      Rate    Hours    Regular Pay      Overtime Pay     Gross Pay

  • Any hours worked above 40 hours are paid at time and a half. Additionally, the program should display the totals of regular, overtime and gross pay columns.

Solutions

Expert Solution

#include<iostream>
#include<cstring>
using namespace std;
static double totalGp=0;//total gross pay
static double totalOt=0;//
static double totalRt=0;

//node class
class Node{
   public:
   int empNo;
   string name;
   int rate;
   double hours;
   double regularPay;
   double overtimePay;
   double grosspay;
   Node *next;
   Node(int e,string n,int r,double h,double rp,double op,double gp, Node *ne=NULL)
   {
       empNo=e;
       name=n;
       rate=r;
       hours=h;
       regularPay=rp;
       overtimePay=op;
       grosspay=gp;
       next=ne;
       totalGp+=grosspay;
       totalOt+=overtimePay;
       totalRt+=regularPay;
   }
  
};

class List{
   public:
    Node *head;
    List(){
       head=NULL;
   }
  
   void add();
   void deelete();
   void search();
   void print();
};

void List::add() {
   cout <<"Enter the empno"<< endl;
   int eno;
   cin >> eno;
   cout <<"Enter the name"<<endl;
   string ename;
   cin >>ename;
   cout <<"Enter the rate"<< endl;
   int ratee;
   cin>>ratee;
   cout <<"Enter the hour"<< endl;
   double hr;
   cin>>hr;
   cout <<"Enter the regular pay"<< endl;
   double rp;
   cin>>rp;
   cout <<"Enter the overtime pay"<< endl;
   double op;
   cin>>op;
   cout <<"Enter the gross pay"<< endl;
   double gp;
   cin>>gp;
  
   if(head==NULL){
       head=new Node(eno,ename,ratee,hr,rp,op,gp,NULL);
        return;
   }
  
   Node *newNode=new Node(eno,ename,ratee,hr,rp,op,gp,head);
   head=newNode;
}

void List ::deelete(){
   cout <<"Enter the empno"<< endl;
   int eno;
   cin >> eno;
   Node *temp=head;

    if(temp==NULL)
   {
   cout <<"List is empty"<<endl;
   return;
    }
      
   if(head->empNo==eno){
       Node *deletedNode=head;
       head=head->next;
       delete deletedNode;
       return;
   }
   while(temp->next!=NULL){
       if(temp->next->empNo==eno){
           Node *deletedNode=temp->next;
           temp->next=temp->next->next;
           delete deletedNode;
           cout<<"entry has been deleted"<<endl;
           return;
       }
       temp=temp->next;
   }
   cout <<"Sry, employee number does not exist"<<endl;
   return;
}


void List ::search(){
   cout <<"Enter the empno"<< endl;
   int eno;
   cin >> eno;
   Node *temp=head;
   if(temp==NULL)
   {
   cout <<"List is empty"<<endl;
   return;
}  
   while(temp->next!=NULL){
       if(temp->empNo==eno){
           cout <<"Entry found"<<endl;
           return;
       }
       temp=temp->next;
   }
   cout <<"Sry, entry does not exist"<<endl;
   return;
}

void List::print(){
Node *temp=head;
while(temp!=NULL){
      cout <<"EMP details:"
   cout <<temp->empNo<<endl;
   cout <<temp->name<< endl;
   cout <<temp->rate<<endl;
   cout <<temp->hours<<endl;
   cout<<temp->regularPay<<endl;
   cout << temp->overtimePay<<endl;
   cout <<temp->grosspay<<endl<<endl;
   temp=temp->next;
}
cout <<"Total regular pay "<<totalRt <<endl;
cout <<"Total overtime pay "<<totalOt<<endl;
cout <<"Total grosspay pay "<<totalGp <<endl;
}

int main(){
  
   char ch;

List list;
   do
   {
       cout <<"Menu"<< endl;
       cout <<"1. Add"<< endl;
       cout <<"2. Delete"<< endl;
       cout <<"3. Search"<< endl;
       cout <<"4. Print"<< endl;
       cout << "5.Exit"<<endl;
       cout <<" Enter Your choice"<<endl;
       int choice;
       cin>>choice;
      
       switch(choice){
           case 1: list.add();
                   break;
            case 2: list.deelete();
                   break;
           case 3: list.search();
                   break;  
          case 4: list.print();
                   break;
           case 5: return 0;
       }
       cout <<"Do you want to more (y/n)"<< endl;
       cin>>ch;
   }while(ch=='y'||ch=='Y');
return 0;
          
}


Related Solutions

1) a. Write down a C++ program which will create a list (simple linear linked list)...
1) a. Write down a C++ program which will create a list (simple linear linked list) of nodes. Each node consists of two fields. The first field is a pointer to a structure that contains a student id (integer) and a gradepoint average (float). The second field is a link. The data are to be read from a text file. Your program should read a file of 10 students (with student id and grade point average) and test the function...
Write down a C program which will create a list (simple linear linked list) of nodes....
Write down a C program which will create a list (simple linear linked list) of nodes. Each node consists of two fields. The first field is a pointer to a structure that contains a student id (integer) and a grade-point average (float). The second field is a link. The data are to be read from a text file. Your program should read a file of 10 students (with student id and grade point average) and test the function you wrote...
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.
Hi, i'm creating a c++ program with a linked list of Employees, i'm running into issues...
Hi, i'm creating a c++ program with a linked list of Employees, i'm running into issues as far as displaying programmers only portion and the average salary of all the employees. Please make any changes or comments ! Employee.h file: #ifndef EMPLOYEE_H #define EMPLOYEE_H #include using namespace std; enum Role {programmer, manager, director}; struct Employee { std::string firstName; std::string lastName; int SSN; std::string department; double salary; Role role; }; #endif #ifndef NODE_H #define NODE_H Node.h file: #include "Employee.h" typedef Employee...
Create a C++ integer linked list program that performs the following methods below: Please create these...
Create a C++ integer linked list program that performs the following methods below: Please create these three source files: intList.h, intList.cpp, & intListTest.cpp. Implement recursive routines in the intList class to do the following: Print the list in reverse order Return the value in the middle node Return the average of all the odd values Remove every node containing an odd value Modify main (in IntListTest.cpp) so it does the following: Insert the numbers 1, 3, 4, 6, 7, 10,...
Write a program that create a single linked list and consist of all the necessary functions...
Write a program that create a single linked list and consist of all the necessary functions to do the following Add an element to the list, insertion position can be anywhere in the list (first, last and middle) delete an element from the list, deletion position can be anywhere in the list (first, last and middle) Note: You need to add proper documentation to your programs and you need to include the output of each program C++
Write a program in C to process weekly employee timecards for all employees of an organization...
Write a program in C to process weekly employee timecards for all employees of an organization (ask the user number of employees in the start of the program). Each employee will have three data items: an identification number, the hourly wage rate, and the number of hours worked during a given week.A tax amount of 3.625% of gross salary will be deducted. The program output should show the identification number and net pay. Display the total payroll and the average...
implementing linked list using c++ Develop an algorithm to implement an employee list with employee ID,...
implementing linked list using c++ 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. Add employee details based on department Remove employee details based on ID if found, otherwise display appropriate message Display employee details Count the number of employees in each department
Write in C++: create a Doubly Linked List class that holds a struct with an integer...
Write in C++: create a Doubly Linked List class that holds a struct with an integer and a string. It must have append, insert, remove, find, and clear.
Write a program of linked list in which in which element can be inserted only at...
Write a program of linked list in which in which element can be inserted only at the end of the linked list and deletion can also take place at the end. Code needed in java.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT