Answer to Question #297451 in C++ for Rajen

Question #297451

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

1
Expert's answer
2022-02-17T05:21:15-0500


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


class Employee{
private:
	string name;
public:


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


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


class FullTime:Employee{
private:
	float basic_salary,allowances;
public:


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


	void print(){
		Employee::print();
		cout<<"Bsic salary: "<<basic_salary<<"\n";
		cout<<"Allowances: "<<allowances<<"\n";
		cout<<"Salary: "<<computeSalary()<<"\n";
	}
	float computeSalary(){
		return basic_salary+allowances;
	}
};


class PartTime:Employee{
private:
	float rate_per_day;
	int no_days_worked;
public:
	PartTime(float rate_per_day,float no_days_worked,string name):Employee(name){
		this->rate_per_day=rate_per_day;
		this->no_days_worked=no_days_worked;
	}


	void print(){
		Employee::print();
		cout<<"Rate per day: "<<rate_per_day<<"\n";
		cout<<"No. of days worked : "<<no_days_worked<<"\n";
		cout<<"Salary: "<<computeSalary()<<"\n";
	}
	float computeSalary(){
		return rate_per_day*no_days_worked;
	}
};




int main() {
	FullTime _FullTime(2500,352,"John");
	_FullTime.print();


	PartTime _PartTime(20,15,"Julia");
	_PartTime.print();


	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