Sunday, February 25, 2018

C++ : Multiple Inheritence

#include <iostream>
#include <string>
using namespace std;
class Employee {
public:
    string Name;
    double salary;
    Employee(string fName, double sal) : Name(fName), salary(sal) {}
    void show() {
        cout << Name << " " << salary;
    }
    void addBonus(double bonus) {
        salary += bonus;
    }
};

class Manager :public Employee {
public:
    Manager(string fName, double sal) : Employee(fName, sal) {}
};

class Clerk :public Employee {
public:
    Clerk(string fName, double sal) : Employee(fName, sal) {}
};
void congratulate(Employee* emp) {
    emp->addBonus(200);
    emp->show();
    cout << " ";
};

int main() {
    Employee* emp;
    int sal_m, sal_c;
    cin >> sal_c >> sal_m;
    Manager m1("Steve", sal_m);
    Clerk c1("Kevin", sal_c);
emp = &c1;
congratulate (emp);
emp = &m1;
congratulate (emp);
    return 0;
}

No comments:

Post a Comment

Derivatives stock list at NSE

Complete FNO stock list at NSE. ABB India Ltd ACC Ltd APL Apollo Tubes Ltd AU Small Finance Bank Ltd Aarti Industries Ltd Abbott India Ltd A...