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

Henry's law constant for CO 2 ​ in water is 1.67×10 ∘ Pa at 298 K . Calculate the quantity of CO 2 ​ in 500 mL , of soda water when packed under 2.5 atm CO 2 ​ pressure at 298 K .

  Explanation To calculate the amount of CO 2 ​ dissolved, we use Henry's Law: P = k H ​ × x _ C O 2 ​ where:\ P = partial pressure of...