Answer to Question #173489 in C++ for praveenkumar.b

Question #173489

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.



1
Expert's answer
2021-03-27T07:51:45-0400
#include <iostream>
#include <string>


using namespace std;


class person 
{
private:
	string name;
	int age;
public:
	person(){}
	void setName(string n){
		name=n;
	}
	string getName(){
		return name;
	}
	void setAge(int a){
		age=a;
	}
	int getAge(){
		return age;
	}
};
class salary:public person
{
private:
	double salaryA;
public:
	salary(){}
	void setSalaryA(double s){
		salaryA=s;
	}
	double getSalaryA(){
		return salaryA;
	}
};
class employee:public salary
{
private:
	int degree;
	int experience;
public:
	employee(){}
	void setDegree(int d){
		degree=d;
	}
	int getDegree(){
		return degree;
	}
	void setExperience(int exp){
		experience=exp;
	}
	int getExperience(){
		return experience;
	}
};


class manager:public employee
{
public:
	manager(){}
	
	void pfund(){
		double pf=750;
		if(getSalaryA()>20000.0 && getExperience()>10){
			pf=1800;
		}
		double netSalary=getSalaryA() + pf;
		cout<<"Name: "<<getName()<<endl;
		cout<<"Age: "<<getAge()<<endl;
		cout<<"Salary: "<<getSalaryA()<<endl;
		cout<<"Degree: "<<getDegree()<<endl;
		cout<<"Experience: "<<getExperience()<<endl;
		cout<<"Net salary: "<<netSalary<<endl;
	}
};




int main(){
	manager Peter;
	Peter.setName("Peter");
	Peter.setAge(30);
	Peter.setSalaryA(65000);
	Peter.setDegree(10);
	Peter.setExperience(10);
	Peter.pfund();
	cout<<"\n";
	manager Wilson;
	Wilson.setName("Wilson");
	Wilson.setAge(52);
	Wilson.setSalaryA(15000);
	Wilson.setDegree(7);
	Wilson.setExperience(8);
	Wilson.pfund();
	cout<<"\n";
	manager Thomas;
	Thomas.setName("Thomas");
	Thomas.setAge(18);
	Thomas.setSalaryA(85000);
	Thomas.setDegree(15);
	Thomas.setExperience(15);
	Thomas.pfund();

	system("pause");
	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