Develop a code for the multilevel inheritance diagram given below
· The person class consisting of data members such as name and age.
· The salary details class consisting of data members such as salary.
· The employee class consisting of data members such as degree and experience.
· The manager class consisting of member function pfund() to find the employee provident fund satisfying the condition total experience to be greater than 10 and salary to be greater than Rs. 20,000 and then calculate net salary = basic pay + pf. The provident fund amount sanctioned is Rs. 1800 for basic pay Rs 20,000 otherwise provident fund amount sanctioned is Rs. 750.
#include <iostream>
#include <string>
using namespace std;
class Person
{
public:
Person() {};
Person(string n, int a);
string GetName() { return name; };
int GetAge() { return age; };
private:
string name;
int age;
};
Person::Person(string n, int a) : name(n), age(a)
{}
class Salary : public Person
{
public:
Salary() {};
Salary(string n, int a, double s);
double GetSalary() { return salary; }
private:
double salary;
};
Salary::Salary(string n, int a, double s) : Person(n, a), salary(s)
{}
class Employee : public Salary
{
public:
Employee() {};
Employee(string n, int a, double s, string d, int e);
string GetDegree() { return degree; };
int GetExperience() { return experience; };
private:
string degree;
int experience;
};
Employee::Employee(string n, int a, double s, string d, int e) : Salary(n, a, s), degree(d), experience(e)
{}
class Manager : public Employee
{
public:
Manager() {};
Manager(string n, int a, double s, string d, int e);
void pfund();
};
Manager::Manager(string n, int a, double s, string d, int e) : Employee(n, a, s, d, e)
{}
void Manager::pfund()
{
if (GetSalary() > 20000 && GetExperience() > 10)
{
cout << "Name is " << GetName() << " and age is: " << GetAge() << " years." << endl;
cout << "Basic salary is: Rs. " << GetSalary() << " and experience is: " << GetExperience() << " years." << endl;
cout << "Provident fund is Rs. 1800 and net salary is: Rs. " << GetSalary() + 1800 << endl;
}
else
{
cout << "Name is " << GetName() << " and age is: " << GetAge() << " years." << endl;
cout << "Basic salary is: Rs. " << GetSalary() << " and experience is: " << GetExperience() << " years." << endl;
cout << "Provident fund is Rs. 750 and net salary is: Rs. " << GetSalary() + 750 << endl;
}
}
int main()
{
Manager Mike("Mike", 34, 18000, "Ph. ", 15);
Mike.pfund();
cout << endl;
Manager Bill("Bill", 38, 25000, "Ph. ", 3);
Bill.pfund();
cout << endl;
Manager Brian("Brian", 42, 28000, "Ph. ", 14);
Brian.pfund();
return 0;
}
Comments
Leave a comment