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
#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;
}
Comments
Leave a comment