Answer to Question #297390 in C++ for Rajen

Question #297390

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-15T09:53:27-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:
	double basicSalary,allowances;
public:


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


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


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 print(){
		Employee::print();
		cout<<"Rate per day: "<<rate_per_day<<"\n";
		cout<<"No. of days worked : "<<noDaysWorked<<"\n";
		cout<<"Salary: "<<calculateSalary()<<"\n";
	}
	double calculateSalary(){
		return rate_per_day*noDaysWorked;
	}
};




int main() {
	FullTime fullTime(2000,400,"John");
	fullTime.print();


	PartTime partTime(40,20,"Mike");
	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