#include<iostream>

#include<string>

using namespace std;

class Employee{                                                       //Base Class Employee

    protected: string name;

        double hworked, hrate,ovthrs;

public:Employee( ){ }

        virtual void inputemployee()=0;

        virtual double ovtpay()=0;

        virtual double gpay()=0;

        virtual double tamt()=0;

        virtual double netpay()=0;

        virtual void display()=0;

};

class hourly: public Employee{                            //Sub Class Hourly Inheriting from Base Class

    public: hourly( ){

        name="";

        hworked=0;

        hrate=0; }

void setEmployeeInfo(string n, double hw, double hr) {

    name = n;

    hworked = hw;

    hrate = hr; }

void inputemployee(){

    {

        cout<<"Please Input Name of Employee: ";

        cin>>name;

        cout<<"Please Input Name of Hours Worked: ";

        cin>>hworked;

        cout<<"Please Input Name of Hourly Rate: ";

        cin>>hrate;

    }}

double regpay(){

        if (hworked == 40){

            return (40 * hrate);

    }    else return hworked*hrate;

}

double ovtpay(){

    if (hworked>40){

        double ovthrs, ovtpay;

        ovthrs = (hworked - 40);

        ovtpay = (ovthrs * hrate * 1.5);

        return ovtpay;

    }     else return 0;

}

double gpay(){

        double gpay;

        return gpay=regpay()+ovtpay();

    }

double tamt( ){

    double trate=0.3;

    double tamt;

    tamt=gpay()*trate;

    return tamt;

}

double netpay( ){

    double netpay;

    netpay=gpay()-tamt();

    return netpay;

}

void display( )

    {

    cout<<"The Name of Employee is: "<<name<<endl;

    cout<<"The Hours Worked are : "<<hworked<<endl;

    cout<<"The Hourly Rate is : "<<hrate<<endl;

    cout<<"The Over Time Pay is : "<<ovtpay()<<endl;

    cout<<"The Regular Pay is : "<<regpay()<<endl;

    cout<<"The Tax Amount is : "<<tamt()<<endl;

    cout<<"The Net Pay is : "<<netpay()<<endl;

}};                                                                 // End Sub Class Hourly

 

class salary: public Employee{                 //Sub Class Salary Inheriting from Base Class

        private: double sal;

    public:

void setEmployeeInfo(string n, double hw, double saly) {

        name = n;

        hworked = hw;

        sal = saly; }

void inputemployee( ){

        cout<<"Please Input Name of Employee: ";

        cin>>name;

        cout<<"Please Input Employees Salary: ";

        cin>>sal;

        cout<<"Please Input Number of Hours worked: ";

        cin>>hworked;

}

double gpay( ){   

    return (sal/52);

}

double hrate( ){

    return (gpay( )/40);

}

double ovtpay( ){

        if (hworked>40){

        double ovthrs;

        ovthrs = (hworked - 40);

        return (ovthrs* hrate( ) * 1.5);

    }    else return 0;

}

double tamt( ){

        double trate=0.3;

        return gpay( )*trate;

}

string getname( ){

        return name;}

        double netpay( ){

        return gpay( )-tamt( );

    }

void display( )

    {

        cout<<"The Name of Employee is: "<<name<<endl;

        cout<<"The Hours Worked are : "<<hworked<<endl;

        cout<<"The Hourly Rate is : "<<hrate()<<endl;   

        cout<<"The Over Time Pay is : "<<ovtpay()<<endl;

        cout<<"The Gross Pay is : "<<gpay()<<endl;

        cout<<"The Tax Amount is : "<<tamt()<<endl;

        cout<<"The Net Pay is : "<<netpay()<<endl;

    }

};                         //End of Sub Class Salary

main( ){

        char choice='z';

        Employee *emp[100];

        int i=0;

       while (choice!='e'&&choice!='E'){

                cout<<endl<<"Employee Database"<<endl;

                cout<<endl<<"Hourly Employee(H)"<<endl;

                cout<<endl<<"Salaried Employee(S)"<<endl<<endl<<endl;

                cout<<"Type e to exit"<<endl<<endl;

                cin>>choice;

        switch(choice){                                        //Switch function

                case'H':

                        emp[i]=new hourly;

                        emp[i]->inputemployee( );

                        emp[i]->gpay( );   

                        emp[i]->ovtpay( );

                        emp[i]->netpay( );

                        emp[i]->tamt( );

                        i++;

                        break;

                case'S':

                        emp[i]=new salary;

                        emp[i]->inputemployee( );

                        emp[i]->tamt( );

                        emp[i]->netpay( );

                        emp[i]->ovtpay( );

                        i++;

                        break;

    }

}

int scan,pass;                                            //sorting net pay using bubble sort

                for(pass=1;pass<i;pass++){

                        for(scan=0; scan<i-pass;scan++){

                            if(emp[scan]->netpay()>emp[scan+1]->netpay()){

                                Employee* temp;

                                temp=emp[scan];

                                emp[scan]=emp[scan+1];

                                emp[scan+1]=temp; }

                            }//end scan

                    }//end pass

        cout<< "Sorted Employee's Pay: "<<endl;

                for(int j=0;j<i; j++){

                        emp[j]->display();

                        cout<<endl;}

                        return 0;

        }

 

 

<<Main Page>>

Hosted by www.Geocities.ws

1