Answer to Question #183042 in C++ for Panjumin

Question #183042

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-19T19:07:08-0400
#include <iostream>
using namespace std;

class Employee {
    protected:
    int empno;
    public:
    virtual int getSalary () = 0;
    virtual string toString () = 0;
};

class Developer : public Employee {
    private:
    int salary;

    public:
    Developer () {}
    Developer (int eno, int sal) {
        empno = eno;
        salary = sal;
    }
    int getSalary () {
        return salary;
    }
    string toString () {
        return "Developer: ";
    }
};

class Driver : public Employee {
    private:
    int salary;

    public:
    Driver () {}
    Driver (int eno, int sal) {
        empno = eno;
        salary = sal;
    }
    int getSalary () {
        return salary;
    }
    string toString () {
        return "Driver: ";
    }
};

int main()
{
    Employee *e1, *e2;

    e1 = new Driver (100, 35000);
    e2 = new Developer (200, 105000);

    cout << e1->toString () << e1->getSalary () << endl;
    cout << e2->toString () << e2->getSalary () << 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