In: Computer Science
C++
MENU
1. ADD EMPLOYEE DETAILS
2. DELETE EMPLOYEE
3. SEARCH EMPLOYEE
4. PRINT EMPLOYEE PAYROLL
5. EXIT
EmpNo. Name Rate Hours Regular Pay Overtime Pay Gross Pay
#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;
}