Skip to main content

OOPS CPP Program-11

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();
}

Comments

Popular posts from this blog

C-Programming with Record

C-Programming Programs Syllabus Click for full record  1.a) Write a C program to ask the user to enter one char ( Upper-Case letter) check  whether user  entered a Upper-case letter or not(by using relational and logical operators) and then if user has  entered a Upper-case letter  convert into a Lower-case letter? ( hint: Upper-case means capital letters,  use ASCII information to check for Upper-case and convert) b) Write a  C program to ask the user to enter two integers and apply all arithmetic operations on those  print the corresponding values?(hint : +,-,*,/,%)     c) Write a C program to Determine the ranges of char, short, int and long int variables both signed and  Unsigned   By using sizeof operator(ii) By printing appropriate values from standard header (limits.h )   2.a) Write a Program to Find the Roots of a Quadratic Equation using if else and Switch statements. b) Write a Program which Gener...

OOPS CPP Program-14

14. Write a program to find transpose of a given matrix of mxn size using unary operator overloading #include<iostream> using namespace std; class matrix {         int x[5][5],m,n; public:         matrix(){ }         matrix(int a,int b)         {                m=a;n=b;         }         void get();         void put();         matrix operator !(); }; void matrix::get() {         int i,j;         cout<<"\n Enter a matrix of order"<<m<<"x"<<n<<"\n";                for(i=0;i<m;i++)                    for(j=0;j<n;j++)                        ...

OOPS CPP Program-15

15. Write a program to concatenate one string to another using binary operator overloading. #include<iostream> #include<string.h> using namespace std; class str  {         char *st; public:         str(int len, char *s)         {                  int l=strlen(s);                st= new char[l];                st=s;          }         str()         {         }         void put();         str operator +(str); }; str str :: operator +(str s)  {  /*str abc; abc.st=strcat(st, s.st); return abc;*/         st=strcat(st, s.st);         return *this; } void str :: put() {   cout<<...