Answer to Question #175142 in C++ for Raj

Question #175142

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-24T16:48:31-0400
#include <iostream>
#include <string>


using namespace std;
//The person class consisting of data members such as name and age.
class person 
{
private:
	string name;
	int age;
public:
	person(){}


	person(string name,int age){
		this->name=name;
		this->age=age;
	}


	string getName(){
		return this->name;
	}
	int getAge(){
		return this->age;
	}
};
//The salary details class consisting of data members such as salary.
class salaryPerson:public person
{
private:
	float salary;
public:
	salaryPerson(){}


	salaryPerson(string name,int age,float salary):person(name,age){
		this->salary=salary;
	}
	float getSalary(){
		return this->salary;
	}
};
//The employee class consisting of data members such as degree and experience.
class employee:public salaryPerson
{
private:
	int degree;
	int experience;
public:
	employee(){}


	employee(string name,int age,float salary,int degree,int experience):salaryPerson(name,age,salary){
		this->degree=degree;
		this->experience=experience;
	}
	int getDegree(){
		return this->degree;
	}
	int getExperience(){
		return this->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.
class manager:public employee
{
public:
	manager(){}
	manager(string name,int age,float salary,int degree,int experience):employee(name,age,salary,degree,experience){}
	
	void pfund(){
		float pf=750;
		if(getExperience()>10 && getSalary()>20000){
			pf=1800;
		}
		float netSalary=getSalary() + pf;


		cout<<"Name: "<<getName()<<"\n";
		cout<<"Age: "<<getAge()<<"\n";
		cout<<"Salary: Rs. "<<getSalary()<<"\n";
		cout<<"Degree: "<<getDegree()<<"\n";
		cout<<"Experience: "<<getExperience()<<"\n";
		cout<<"Net salary: Rs. "<<netSalary<<"\n";


		cout<<"\n";
	}
};


int main(){
	manager manager("Peter",25,50000,6,55);
	manager.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