Answer to Question #186175 in C++ for Ajith

Question #186175

Suppose there are some employees working in a firm. The firm hires only two types of employees- either driver or developer. Now, you have to develop a C++ program to store information about them. Employee class has name and getEmployee(), declare showEmployee() as pure virtual function. There is no need to make objects of employee class. Make objects to only driver or developer. Also, both must have experience and salary. Set default salary 15000 for developer and 6000 for driver. Provide salary according to their experience. Give 500 rupees extra for each 1 one year of experience. Make Employee as an abstract class and Developer and Driver its subclasses. Use abstract class and Pure virtual functions concept.


1
Expert's answer
2021-04-30T16:54:40-0400
#include <iostream>
using namespace std;


class Employee {
    protected:
        string name;
    public:
        // virtual int getSalary () = 0;
        virtual string getEmployee () = 0;
        virtual void showEmployee()=0;
        
};


class Developer : public Employee {
    private:
        int salary;
        int experience;


    public:
        Developer () {
            salary=15000;
        }
        Developer (int s, int e) {
            salary=s;
            experience=e;
            int extra=500;
            if (experience>=1)
                extra=extra*e;
            salary=salary+extra;
        }
    
        void showEmployee () {
            cout<<"Name: "<<name<<endl;
            cout<<"Employee type: Developer"<<endl;
            cout<<"Salary: "<<salary<<endl;
        }
        string getEmployee () {
            return "Developer";
        }
};


class Driver : public Employee {
    private:
        int salary;
        int experience;


    public:
        Driver(){
            salary=6000;
        }
        Driver (int s, int e) {
            salary=s;
            experience=e;
            int extra=500;
            if (experience>=1)
                extra=extra*e;
            salary=salary+extra;
        }
    
        void showEmployee () {
            cout<<"Name: "<<name<<endl;
            cout<<"Employee type: Driver"<<endl;
            cout<<"Salary: "<<salary<<endl;
            
        }
        string getEmployee () {
            return "Driver";
        }
};


int main()
{
    Developer dev(15000,3);
    Driver d(6000,2);
    
    dev.showEmployee();
    
    d.showEmployee();


    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