Answer to Question #257913 in C++ for chetna

Question #257913

Create a class which stores employee name,id and salary Derive two classes from ‘Employee’ class: ‘Regular’ and ‘Part-Time’. The ‘Regular’ class stores DA, HRA and basic salary. The ‘Part-Time’ class stores the number of hours and pay per hour. Calculate the salary of a regular employee and a par-time employee, using virtual function


1
Expert's answer
2021-10-28T01:29:39-0400
#include<iostream>
using namespace std;
class Employee{
	private:
	string name;
	int id;
	double salary;
	
	public:
		void setData(string n, int i){
			name = n;
			id = i;
		}
		
		virtual void calculateSalary()=0;
};
class Part_Time: private Employee{
	private:
	int number_of_hours;
	double pay_per_hour;
	public:
		Part_Time(int n, double d){
			number_of_hours = n;
			pay_per_hour = d;
		}
		void calculateSalary(){
		cout<<"The employee salary is:  "<<number_of_hours *pay_per_hour <<endl;
	}
	
};


class Regular: private Employee{
	private:
	double DA, HRA , basic_salary;
	public:
	Regular(double d, double h, double b){
		DA = d;
		HRA = h;
		basic_salary = b;
	}
	public:
	void calculateSalary(){
		cout<<"The employee salary is:  "<<DA+ HRA + basic_salary<<endl;
	}
};


int main(){
	Part_Time p(2,3000);
	Regular r(300,1000,200);
	p.calculateSalary();
	r.calculateSalary();
}

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