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 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.
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...
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.
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
Could you write a c- program that reads a text file into a linked list of...
Could you write a c- program that reads a text file into a linked list of characters and then manipulate the linked list by making the following replacements 1. In paragraph 1 Replace all “c” with “s” if followed by the characters “e”, “i” or “y”; otherwise 2. In pragraph 2 Replace "We" with v"i" This is the text to be manipulated: Paragraph1 She told us to take the trash out. Why did she do that? I wish she would...
Could you write a c- program that reads a text file into a linked list of...
Could you write a c- program that reads a text file into a linked list of characters and then manipulate the linked list by making the following replacements 1. Replace all “c” with “s” if followed by the characters “e”, “i” or “y”; otherwise 2. Replace "sh" with ph This is the text to be manipulated: Paragraph1 She told us to take the trash out. Why did she do that? I wish she would not do that Paragraph 2 We...
1.Please write a C++ program that counts the nodes in a linked list with the first...
1.Please write a C++ program that counts the nodes in a linked list with the first node pointed to by first. Also please explain. 2. Write a program to determine the average of a linked list of real numbers with the first node pointed to by first. 3. Determine the computing times of the algorithms in question 1 and 4. Write a program to insert a new node into a linked list with the first node pointed to by first...
Write a C program that creates and prints out a linked list of strings. • Define...
Write a C program that creates and prints out a linked list of strings. • Define your link structure so that every node can store a string of up to 255 characters. • Implement the function insert_dictionary_order that receives a word (of type char*) and inserts is into the right position. • Implement the print_list function that prints the list. • In the main function, prompt the user to enter strings (strings are separated by white-spaces, such as space character,...
write a C++ program to CREATE A CLASS EMPLOYEE WITH YOUR CHOICE OF ATTRIBUTES AND FUNCTIONS...
write a C++ program to CREATE A CLASS EMPLOYEE WITH YOUR CHOICE OF ATTRIBUTES AND FUNCTIONS COVERING THE FOLLOWING POINTS: 1) COUNTING NUMBER OF OBJECTS CREATED ( NO OBJECT ARRAY TO BE USED) USING ROLE OF STATIC MEMBER 2) SHOWING THE VALID INVALID STATEMENTS IN CASE OF STATIC MEMBER WITH NON STATIC MEMBER FUNCTION, NON STATIC MEMBERS OF CLASS WITH STATIC MEMBER FUNCTION, BOTH STATIC. SHOW THE ERRORS WHERE STATEMENTS ARE INVALID. 3) CALL OF STATIC MEMBER FUNCTION, DECLARATION OF...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT