Answer to Question #213776 in C++ for Hemambar

Question #213776

Define a class Employee with data members as empno, name and designation. Derive a class

Qualification from Employee that has data members UG, PG and experience. Create another class

Salary which is derived from both these classes to display the details of the employee and compute

their increments based on their experience and qualifications.


1
Expert's answer
2021-07-08T01:32:23-0400
#include <iostream>
#include <string>
using namespace std;
class Employee{
    protected:
    int empno;
    string name, designation;
    public:
    Employee(){
        getDetails();
    }
    void getDetails(){
        cout<<"Enter employee number: ";
        cin>>empno;
        cout<<"Enter employee name: ";
        cin>>name;
        cout<<"Enter employee designation: ";
        cin>>designation;
    }
};
class Qualification:public Employee{
    protected:
    bool UG, PG;
    int experience;
    public:
    Qualification():Employee(){
        Qualification::getDetails();
    }
    void getDetails(){
        cout<<"Enter UG: (1 if true, 0 if false)";
        cin>>UG;
        cout<<"Enter PG: (1 if true, 0 if false)";
        cin>>PG;
        cout<<"Enter experience: ";
        cin>>experience;
    }
};
class Salary:public Qualification{
    float salary;
    public:
    Salary(): Qualification(){
        calcSal();
    }
    void calcSal(){
        salary = 0;
        if(UG){
            salary = 500;
            if(PG) salary += 300;
        }
        if(experience > 5) salary += 200;
    }
    void display(){
        cout<<"Empno: "<<empno<<endl;
        cout<<"Name: "<<name<<endl;
        cout<<"Designation: "<<designation<<endl;
        cout<<"UG: "<<UG<<endl;
        cout<<"PG: "<<PG<<endl;
        cout<<"Experience: "<<experience<<endl;
        cout<<"Salary increment: "<<salary<<endl;
    }
};
int main(){
    Salary emp;
    emp.display();
    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