Answer to Question #198286 in C++ for Root

Question #198286

We want to design a system for a company to calculate salaries of different types of employees. 

https://ibb.co/swS948B

Every employee has an employee ID and a basic salary. The Commissioned employee has a sales amount and rate. Hourly employee is paid on the basis of number of working hours. A regular employee may have a bonus. You have to implement all the above classes. Write constructor for all classes. The main functionality is to calculate salary for each employee which is calculated as follows: Commissioned Employee: Total Salary=sales amount*rate/100+basic salary Hourly Employee: Total salary=basic salary + pay per hour*extra hours Regular Employee: Total salary= basic salary + bonus You have to define the following function in all classes: float calculateSalary() and run the given main() for the following two cases: 1. when the calculateSalary() in base class is not virtual

2. when the calculateSalary() in base class is made virtual



1
Expert's answer
2021-05-25T04:36:02-0400
#include<iostream>
#include<bits/stdc++.h>
using namespace std;




class Employee{
	public:
		int basicSalary;
		int totalSalary;
		
		Employee()
		{
			cout<<"Enter Basic Salary : ";
			cin>>basicSalary;
		}
		
		virtual float calculateSalary()
		{
			totalSalary = basicSalary;
			cout<<endl<<"Total Salary of Employee : "<<totalSalary<<endl;
		}
		
//		float calculateSalary()
//		{
//			totalSalary = basicSalary;
//			cout<<endl<<"Total Salary of Employee : "<<totalSalary<<endl;
//		}
		
};


class commissionedEmployee:public Employee{
	public:
		int salesAmount;
		int rate;
		
		commissionedEmployee()
		{
			cout<<"Enter Sales Amount : ";
			cin>>salesAmount;
			cout<<"Enter rate : ";
			cin>>rate;
		}
		
		float calculateSalary()
		{
			totalSalary = salesAmount*rate/100 + basicSalary;
			cout<<endl<<"Total Salary of Employee : "<<totalSalary<<endl;
		}
};


class HourlyEmployee:public Employee{
	public:
		int extraHours;
		int payPerHour;
		
		HourlyEmployee()
		{
			cout<<"Enter Extra hours : ";
			cin>>extraHours;
			cout<<"Enter pay per Hour : ";
			cin>>payPerHour;
		}
		
		float calculateSalary()
		{
			totalSalary = basicSalary + extraHours*payPerHour;
			cout<<endl<<"Total Salary of Employee : "<<totalSalary<<endl;
		}
};


class RegularBonus:public Employee{
	public:
		int bonus;
		
		RegularBonus()
		{
			cout<<"Enter Bonus : ";
			cin>>bonus;
		}
		
		float calculateSalary()
		{
			totalSalary = basicSalary + bonus;
			cout<<endl<<"Total Salary of Employee : "<<totalSalary<<endl;	
		}
};


int main()
{
	
	Employee *e;
	commissionedEmployee ce;
	e = &ce;
	
	e->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