An organization has two types of employees: regular and adhoc. Regular employees get a salary which is basic + DA + HRA where DA is 10% of basic and HRA is 30% of basic. Adhoc employees are daily wagers who get a salary which is equal to Number * Wage.
Define the constructors. When a regular employee is created, basic must be a parameter. When adhoc employee is created wage must be a parameter. (iii) Define the destructors. (iv)Define the member functions for each class. The member function days ( ) updates number of the Adhoc employee. (v) Write a test program to test the classes
#include <iostream>
using namespace std;
class Regular{
float basic;
float DA;
float HRA;
float salary;
public:
Regular(float sal): basic(sal){
DA = 0.1 * basic;
HRA = 0.3 * basic;
salary = DA + HRA + basic;
}
float getSalary(){
return salary;
}
~Regular(){}
};
class Adhoc{
int number;
float wage;
public:
Adhoc(float wag): wage(wag){
}
void days(int n){
number = n;
}
float getSalary(){
return number * wage;
}
~Adhoc(){}
};
int main(){
Regular empl1(2000);
Adhoc empl2(200);
empl2.days(2);
cout<<"Salary of regular: "<<empl1.getSalary();
cout<<"\nSalary of adhoc: "<<empl2.getSalary();
return 0;
}
Comments
Leave a comment