Implement a function to raise the salary for an employee in CPP
/* Problem Statement : Define a structure to represent a employee record containing information like employee id, name, Employee band and salary for an employee. Possible values of Employee band are from 1 to 4 (Engineer-1, Senior Engineer-2, Manager-3, VP-4). Use enumeration employee band. One data member of this structure is Special Incentive. As there are 3 types of special incentive (i.e. Bonus, Sales Incentive and Productivity Incentive) and only one of them will be applicable to each empolyee, create a "Union" for this. Use this structure to store and print the values for the same. Implement name as a character pointer (char*) and allocate exact amount of memory required for the name entered by a user. Implement a function to raise the salary for an employee. */
#include<iostream>
using namespace std;
enum band
{
Engineer =1, Senior_eng, Manager, VP
};
union incentive
{
float bonus;
float sale_inc;
float prod_inc;
};
struct employees
{
int emp_id;
char *name;
int salary;
enum band b;
union incentive i;
};
void raise_salary(struct employees e)
{
if(e.b == Engineer)
{
e.salary += e.i.bonus ;
cout<<"\n\n\tEngineer's new Salary : "<<e.salary<<endl;
}
if(e.b == Senior_eng)
{
e.salary += e.i.sale_inc ;
cout<<"\n\n\tSenior Engineer's new Salary : "<<e.salary<<endl;
}
if(e.b == Manager)
{
e.salary += e.i.prod_inc ;
cout<<"\n\n\tManager's new Salary : "<<e.salary<<endl;
}
cout<<endl;
}
int main()
{
struct employees e;
int temp;
e.name = new char[10];
cout<<"\nEnter the information of the employee. ";
cout<<"\nEnter name : ";
cin>>e.name;
cout<<"\nEnter emp_id: ";
cin>>e.emp_id;
cout<<"\nEnter salary : ";
cin>>e.salary;
cout<<"\nEnter band of the employee (1 for Engineer, 2 for Senior Engineer, 3 for Manager, 4 for VP) : ";
cin>>temp;
if(temp == 1)
e.b=Engineer;
else if(temp == 2)
e.b=Senior_eng;
else if(temp == 3)
e.b=Manager;
else if(temp == 4)
e.b=VP;
if(e.b == 1)
e.i.bonus = 0.1 * e.salary;
if(e.b == 2)
e.i.sale_inc = 0.2 * e.salary;
if(e.b == 3)
e.i.prod_inc = 0.3 * e.salary;
if(e.b == 4)
e.i.prod_inc = 0.4 * e.salary;
cout<<"\nHike in the salary is : ";
raise_salary(e);
delete []e.name;
return 0;
}
Problem Statement : Define a structure to represent a employee record containing information like employee id, name, Employee band and salary for an employee. Possible values of Employee band are from 1 to 4 (Engineer-1, Senior Engineer-2, Manager-3, VP-4). Use enumeration employee band. One data member of this structure is Special Incentive. As there are 3 types of special incentive (i.e. Bonus, Sales Incentive and Productivity Incentive) and only one of them will be applicable to each employee, create a "Union" for this. Use this structure to store and print the values for the same. Implement name as a character pointer (char*) and allocate exact amount of memory required for the name entered by a user. Implement a function to raise the salary for an employee.
#COFPROG
Sign up here with your email
ConversionConversion EmoticonEmoticon