11. Write a program to calculate gross and net pay of employee from basic salary. Create employee class which consists of employee name, emp_id, and basic salary as its data members. Use parameterized constructor in the derived class to initialize data members of the base class and calculate gross and net pay of the employee in the derived class.

#include<iostream.h>
#include<string.h>
class employee
{
    protected:
                int id,basic;                    
                char name[20];
    public:
                employee(int i,char *s,int b)
                    {
                        id=i;    
                        strcpy(name,s);         
                        basic=b;
                    }
                void show()
                    {
                        cout<<"\nEmp. Id: "<<id<<"\n";
                        cout<<"Emp. Name: "<<name<<"\n";
                        cout<<"Basic Salary: "<<basic<<"\n";
                    }
};
class grossnet: public employee
{
            float deduct,gross,net;
            public:
                        grossnet(int i,char *s, int b,int d,float g,float n): employee(i,s,b)
                        {
                                    deduct=d;      gross=g;         net=n;
                        }
                        void calculate();
};
void grossnet::calculate()
{
    float da,hra;
    da=0.4*basic;
    hra=0.2*basic;
    gross=basic+da+hra;
    net=gross-deduct;
    cout<<"Gross Pay: "<<gross<<"\n";
    cout<<"Net Pay: "<<net<<"\n";
}
 
void main()
{
    int eid,ebasic;
    float ededuct;
    char ename[20];
    cout<<"Enter:\n";
    cout<<"Employee Id: ";                  
    cin>>eid;
    cout<<"Employee Name: ";           
    cin>>ename;
    cout<<"Basic Salary: ";    
    cin>>ebasic;
    cout<<"Deductions: ";      
    cin>>ededuct;
    grossnet gn(eid,ename,ebasic,ededuct,0,0);
    gn.show();
    gn.calculate();
}

OUTPUT:

Enter:
Employee Id: 123
Employee Name: Lahari
Basic Salary: 10000
Deductions: 1450.0

Emp. Id: 123
Emp. Name: Lahari
Basic Salary: 10000
Gross Pay: 16000

Net Pay: 14550
Posted by Unknown On 03:33 3 comments

3 comments:

  1. I am thankful to this blog giving unique and helpful knowledge about this topic, I read your blog now share great information here. This blog increse my knowledge source .
    Concrete Contractors San Diego

    ReplyDelete
  2. Thank You so much for the blog

    ReplyDelete

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

Blog Archive

Contact Us


Name

E-mail *

Message *