Write a C++ program to find out the payroll system using single inheritance.




Program Algorithm:
Step 1: Include the header files
Step 2: Declare the base class emp.
Step 3: Define and declare the function get () to get the employee details.
Step 4: Declare the derived class salary.
Step 5: Declare and define the function get1 () to get the salary details.
Step 6: Define the function calculate () to find the net pay.
Step 7: Define the function display ().
Step 8: Create the derived class object.
Step 9: Read the number of employees.
Step 10: Call the function get (), get1 () and calculate () to each employee.
Step 11: Call the display ().




Program Code in C++:
#include<iostream.h>
#include<conio.h>
class emp
{
public:
int eno;
char name[20],des[20];
void get()
{



cout<<"Enter the employee number:";
cin>>eno;
cout<<"Enter the employee name:";
cin>>name;
cout<<"Enter the designation:";
cin>>des;
}
};
class salary:public emp
{
float bp,hra,da,pf,np;
public:
void get1()
{
cout<<"Enter the basic pay:";
cin>>bp;
cout<<"Enter the Humen Resource Allowance:";
cin>>hra;
cout<<"Enter the Dearness Allowance :";
cin>>da;
cout<<"Enter the Profitablity Fund:";
cin>>pf;
}
void calculate()
{
np=bp+hra+da-pf;
}
void display()
{
cout<<eno<<"\t"<<name<<"\t"<<des<<"\t"<<bp<<"\t"<<hra<<"\t"<<da<<"\t"<<pf<<"\t"<<np<<"\n";
}
};
void main()
{
int i,n; char
ch; salary
s[10];
clrscr();
cout<<"Enter the number of employee:";
cin>>n;
for(i=0;i<n;i++)
{
s[i].get();
s[i].get1();
s[i].calculate();
}
cout<<"\ne_no \t e_name\t des \t bp \t hra \t da \t pf \t np \n";
for(i=0;i<n;i++)
{
s[i].display();
}
getch();
}





Program Output:
Enter the Number of employee: 10
Enter the employee No: 570
Enter the employee Name: Ram
Enter the designation: AP
Enter the basic pay: 25000
Enter the HR allowance: 8000
Enter the Dearness allowance: 2500
Enter the profitability Fund: 1300
E.No E.name des BP HRA DA PF NP
570 Ram AP 25000 8000 2500 1300 34200
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: