Answer to Question #174158 in C++ for Keega

Question #174158

Develop a code for the hybrid Inheritance diagram given below

·         The employee details class consisting of data members such as name and emp_id.

·         The normal pay class consisting of data members such as basic salary.

·         The additional pay class consisting of data members such as hours, rupees and additional pay.

·         The net pay class consisting of member function cal() to find the employee total salary = additional pay + basic salary. 



1
Expert's answer
2021-03-22T06:30:25-0400
#include<iostream>
using namespace std;


class Employee
{
    protected:
        string emp_name;
        int emp_id;
    public:
        void get_emp_details()
        {
            cout<<"Enter the name of the employee: "<<endl;
            cin>>emp_name;
            cout<<"Enter the employee ID: "<<endl;
            cin>>emp_id;
        }
        string display_employee_name()
        {
            return emp_name;
        }
        int display_employee_id()
        {
            return emp_id;
        }


};
class NormalPay: public Employee
{
    protected:
        double basic_salary;
    public:
        void get_basic_salary()
        {
            cout<<"Enter the basic salary: "<<endl;
            cin>>basic_salary;
        }
};
class AdditionalPay
{
    protected:
        double hours;
        double rupees;
        double additional_pay;
    public:
        void get_additional_pay()
        {
            cout<<"Enter rupees payment per additional hour: "<<endl;
            cin>>rupees;


            cout<<"Enter additional hours worked: "<<endl;
            cin>>hours;


        }
        void calc_additional_pay()
        {
            additional_pay = hours * rupees;
        }
        double display_additional_pay()
        {
            return additional_pay;
        }
};
class NetPay : public NormalPay , public AdditionalPay
{
    protected:
        int total_salary;


    public:
        double calc()
        {
            total_salary = basic_salary + additional_pay;
        }
        double display_total_pay()
        {
            return total_salary;
        }


};
int main(){
    //Create NetPay class object
    NetPay pay1;
    pay1.get_emp_details();
    pay1.get_basic_salary();
    pay1.get_additional_pay();
    pay1.calc_additional_pay();
    pay1.calc();
    //Summary
    cout<<"Employee name: \t"<<pay1.display_employee_name()<<endl;
    cout<<"Employee ID: \t"<<pay1.display_employee_id()<<endl;
    cout<<"Additional Pay: "<<pay1.display_additional_pay()<<endl;
    cout<<"Total salary: \t"<<pay1.display_total_pay()<<endl;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS