Answer to Question #297389 in C++ for Rajen

Question #297389

Develop a C++ program implementing hierarchical inheritance upon a base class "Employee", and derived classes "Full-time" containing basic salary and allowances for calculating the salary of the employee and "Part-time" containing rate_per_day and no. of days worked for calculating the pay.

1
Expert's answer
2022-02-14T15:04:41-0500


#include <iostream>
#include <string>
using namespace std;


class Employee{
private:
	string name;
public:


	Employee(string name){
		this->name=name;
	}


	void display(){
		cout<<"Name: "<<name<<"\n";
	}
};


class FullTime:Employee{
private:
	double basicSalary,allowances;
public:


	FullTime(double basicSalary,double allowances,string name):Employee(name){
		this->basicSalary=basicSalary;
		this->allowances=allowances;
	}


	void display(){
		Employee::display();
		cout<<"Bsic salary: "<<basicSalary<<"\n";
		cout<<"Allowances: "<<allowances<<"\n";
		double salary=basicSalary+allowances;
		cout<<"Salary: "<<salary<<"\n";
	}
};


class PartTime:Employee{
private:
	double rate_per_day;
	int noDaysWorked;
public:


	PartTime(double rate_per_day,double noDaysWorked,string name):Employee(name){
		this->rate_per_day=rate_per_day;
		this->noDaysWorked=noDaysWorked;
	}


	void display(){
		Employee::display();
		cout<<"Rate per day: "<<rate_per_day<<"\n";
		cout<<"No. of days worked : "<<noDaysWorked<<"\n";
		double salary=rate_per_day*noDaysWorked;
		cout<<"Salary: "<<salary<<"\n";
	}
};




int main() {
	FullTime fullTime(1500,500,"Peter");
	fullTime.display();


	PartTime partTime(35,10,"Mary");
	partTime.display();
	
	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