Wednesday, March 22, 2023

BCA and B.Sc Programs - Programming in C++ Lab - Bharathiar University - Practical Program 6- Write a C++ Program to create a class, which consists of EMPLOYEE Detail like E_Number, E_Name, Department, Basic_Salary and Grade. Write a member function to get and display them. Derive a class PAY from the above class and write a member function to calculate DA, HRA and PF depending on the grade.

Bharathiar University

Programming in C++ Lab
C++ Program 6
Write a C++ Program to create a class, which consists of EMPLOYEE Detail like E_Number, E_Name, Department, Basic_Salary and Grade. Write a member function to get and display them. Derive a class PAY from the above class and write a member function to calculate DA, HRA and PF depending on the grade.

In this page

  • C++ Source Code for MS Dos Turbo C++
  • C++ Source Code for Visual Studio Code
Source code for Turbo C++

 #include<iostream.h>

#include<conio.h>


class EMPLOYEE {

    public:

    int E_Number;

    char E_Name[50],dept[50];

    char grade;

    float basic_sal;

    void get()

    {

cout<<"Enter Employee details::"<<endl;

cout<<"Enter Employee Number: ";

cin>>E_Number;

cout<<"Enter Employee Name: ";

cin>>E_Name;

cout<<"Enter Employee department: ";

cin>>dept;

cout<<"Enter Employee Basic Salary: ";

cin>>basic_sal;

cout<<"Enter Employee Grade(A/B/C): ";

cin>>grade;

    }

    void display()

    {

cout<<"Employee Details"<<endl;

cout<<"****************"<<endl;

cout<<"Employee Number: "<<E_Number<<endl;

cout<<"Employee Name: "<<E_Name<<endl;

cout<<"Employee Department: "<<dept<<endl;

cout<<"Employee Basic salary: "<<basic_sal<<endl;

cout<<"Employee Grade: "<<grade<<endl;

    }

};


class PAY:public EMPLOYEE

{

float hra,da,pf,netsal;

    public:

    void calculate()

    {

if(grade=='A')

{

    da=0.5*basic_sal;

    hra=0.4*basic_sal;

    pf=0.1*(basic_sal+da);

    netsal=basic_sal+da+hra-pf;

}

else if(grade=='B')

{

     da=0.4*basic_sal;

    hra=0.3*basic_sal;

    pf=0.08*(basic_sal+da);

    netsal=basic_sal+da+hra-pf;

}

else

{

     da=0.3*basic_sal;

    hra=0.2*basic_sal;

    pf=0.05*(basic_sal+da);

    netsal=basic_sal+da+hra-pf;

}

    }

void disp_sal()

{

    cout<<"Dearness Allowance: "<<da<<endl;

    cout<<"House Rent Allowance: "<<hra<<endl;

    cout<<"Provident Fund: "<<pf<<endl;

    cout<<"Employee Net Salary: "<<netsal<<endl;

}

};


int main()

{

    PAY p;

    clrscr();

    p.get();

    p.calculate();

    p.display();

    p.disp_sal();

    getch();

return 0;

}


OUTPUT




Source code for Visual studio Code

#include<iostream>
#include<conio.h>
using namespace std;
class EMPLOYEE {
    public:
    int E_Number;
    char E_Name[50],dept[50];
    char grade;
    float basic_sal;
    void get()
    {
cout<<"Enter Employee details::"<<endl;
cout<<"Enter Employee Number: ";
cin>>E_Number;
cout<<"Enter Employee Name: ";
cin>>E_Name;
cout<<"Enter Employee department: ";
cin>>dept;
cout<<"Enter Employee Basic Salary: ";
cin>>basic_sal;
cout<<"Enter Employee Grade(A/B/C): ";
cin>>grade;
    }
    void display()
    {
cout<<"Employee Details"<<endl;
cout<<"****************"<<endl;
cout<<"Employee Number: "<<E_Number<<endl;
cout<<"Employee Name: "<<E_Name<<endl;
cout<<"Employee Department: "<<dept<<endl;
cout<<"Employee Basic salary: "<<basic_sal<<endl;
cout<<"Employee Grade: "<<grade<<endl;
    }
};

class PAY:public EMPLOYEE
{
float hra,da,pf,netsal;
    public:
    void calculate()
    {
if(grade=='A')
{
    da=0.5*basic_sal;
    hra=0.4*basic_sal;
    pf=0.1*(basic_sal+da);
    netsal=basic_sal+da+hra-pf;
}
else if(grade=='B')
{
     da=0.4*basic_sal;
    hra=0.3*basic_sal;
    pf=0.08*(basic_sal+da);
    netsal=basic_sal+da+hra-pf;
}
else
{
     da=0.3*basic_sal;
    hra=0.2*basic_sal;
    pf=0.05*(basic_sal+da);
    netsal=basic_sal+da+hra-pf;
}
    }
void disp_sal()
{
    cout<<"Dearness Allowance: "<<da<<endl;
    cout<<"House Rent Allowance: "<<hra<<endl;
    cout<<"Provident Fund: "<<pf<<endl;
    cout<<"Employee Net Salary: "<<netsal<<endl;
}
};

int main()
{
    PAY p;
    
    p.get();
    p.calculate();
    p.display();
    p.disp_sal();
    
return 0;
}

OUTPUT 

Enter Employee details::
Enter Employee Number: 101
Enter Employee Name: Raja
Enter Employee department: HR
Enter Employee Basic Salary: 15000
Enter Employee Grade(A/B/C): A
Employee Details
****************
Employee Number: 101
Employee Name: Raja
Employee Department: HR
Employee Basic salary: 15000
Employee Grade: A
Dearness Allowance: 7500
House Rent Allowance: 6000
Provident Fund: 2250
Employee Net Salary: 26250


No comments:

Post a Comment

Program 12 BCA Madras University BCA Object Oriented Programming using C++ Practical Madras University Program 12 Implement a telephone directory using files

  BCA Object Oriented Programming using C++ Practical Madras University  Program 12  Implement a telephone directory using files SOURCE CODE...