Use the three header files and the following two implementation programs, hourly
ID: 3717988 • Letter: U
Question
Use the three header files and the following two implementation programs, hourlyemployee.cpp, and salariedemployee.cpp. Redefine the function give_raise in both HourlyEmployee and SalariedEmployee such that:
1. Hourly_bases employees receive 10% raise on their hourly rate (wage_rate)
2. Salaried employees receive 6% raise of their salary
// ********************************************************HourlyEmployee.h
#ifndef HOURLYEMPLOYEE_H
#define HOURLYEMPLOYEE_H
#include
#include "employee.h"
using namespace std;
namespace workemployees
{
class HourlyEmployee : public Employee
{
public:
HourlyEmployee();
HourlyEmployee(string new_name, string new_ssn, double new_wage_rate,
double new_hours);
void set_rate(double new_wage_rate);
double get_rate();
void set_hours(double hours_worked);
double get_hours();
void give_raise(double amount);
void print_check();
private:
double wage_rate;
double hours;
};
}
#endif //HOURLYMPLOYEE_H
// ********************************************************SalariedEmployee.h
//This is the HEADER FILE salariedemployee.h.
//This is the INTERFACE for the class SalariedEmployee.
#ifndef SALARIEDEMPLOYEE_H
#define SALARIEDMPLOYEE_H
#include
#include "employee.h"
using namespace std;
namespace workemployees
{
class SalariedEmployee : public Employee
{
public:
SalariedEmployee();
SalariedEmployee (string new_name, string new_ssn, double new_weekly_salary);
double get_salary();
void change_salary(double new_salary);
void print_check();
void give_raise(double amount);
private:
double salary; //weekly
};
}
#endif //SALARIEDEMPLOYEE_H
// ********************************************************Employee.h
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include
using namespace std;
namespace workemployees
{
class Employee
{
public:
Employee();
Employee(string new_name, string new_ssn);
string get_name();
string get_ssn();
void change_name(string new_name);
void change_ssn(string new_ssn);
void print_check();
void give_raise(double amount);
protected:
string name;
string ssn;
double net_pay;
};
}
#endif //EMPLOYEE_H
// ******************************************************** Employee.cpp
#include
#include
#include
#include "employee.h"
using namespace std;
namespace workemployees
{
Employee::Employee() // default is to fetch data from keyboard
{
cout << "Enter employee name, followed by return.: ";
getline(cin, name);
cout << endl << "Enter employee social security number," << " followed by return.: ";
getline(cin, ssn);
cin.ignore(10000, ' ');
cout << endl;
}
Employee::Employee(string new_name, string new_number) :
name(new_name), ssn(new_number) //initializer list
{
//deliberately empty
}
string Employee::get_name()
{
return name;
}
string Employee::get_ssn()
{
return ssn;
}
void Employee::change_name(string new_name)
{
name = new_name;
}
void Employee::change_ssn (string new_ssn)
{
ssn = new_ssn;
}
void Employee::print_check()
{
cout << " ERROR: print_check FUNCTION CALLED FOR AN "
<< "UNDIFFERENTIATED EMPLOYEE. Aborting the program. "
<< "Check with the author of the program about this bug. ";
exit(1);
}
void Employee::give_raise(double amount)
{
cout << " ERROR: give_raise FUNCTION CALLED FOR AN "
<< "UNDIFFERENTIATED EMPLOYEE. Aborting the program. "
<< "Check with the author of the program about this bug. ";
exit(1);
}
}//END EMPLOYEE.CPP
// ******************************************************** HourlyEmployee.cpp
#include
#include
#include "hourlyemployee.h"
using namespace std;
namespace workemployees
{
HourlyEmployee::HourlyEmployee() : Employee()
{
cout << "Enter HourlyEmployee wage rate, followed by return.: ";
cin >> wage_rate;
cout << "Enter number of hours worked, followed by return: ";
cin >> hours;
}
HourlyEmployee::HourlyEmployee(string new_name, string new_number,
double new_wage_rate, double new_hours)
: Employee(new_name, new_number),
wage_rate(new_wage_rate), hours(new_hours)
{
//deliberately empty
}
void HourlyEmployee::set_rate(double new_wage_rate)
{
wage_rate = new_wage_rate;
}
double HourlyEmployee::get_rate()
{
return wage_rate;
}
void HourlyEmployee::set_hours(double hours_worked)
{
hours = hours_worked;
}
double HourlyEmployee::get_hours()
{
return hours;
}
void HourlyEmployee::give_raise( double amount)
{
wage_rate = wage_rate + amount;
}
void HourlyEmployee::print_check()
{
net_pay = hours * wage_rate;
cout << " ________________________________________________ ";
cout << "Pay to the order of " << name << endl;
cout << "The sum of " << net_pay << " Dollars ";
cout << "________________________________________________ ";
cout << "Check Stub: NOT NEGOTIABLE ";
cout << "Employee Number: " << ssn << endl;
cout << "Hourly Employee. Hours worked: " << hours
<< " Rate: " << wage_rate << " Pay: " << net_pay << endl;
cout << "_________________________________________________ ";
}
}//END HOURLYEMPLOYEE.CPP
// ********************************************************SalariedEmployee.cpp
#include
#include
#include "salariedemployee.h"
using namespace std;
namespace workemployees
{
SalariedEmployee::SalariedEmployee():Employee()
{
cout << " Enter Salaried Employee's weekly salary ";
cin >> salary;
}
SalariedEmployee::SalariedEmployee(string new_name, string new_number,
double new_weekly_pay )
: Employee(new_name, new_number), salary(new_weekly_pay)
{
//deliberately empty
}
void SalariedEmployee::give_raise(double amount)
{
salary = salary + amount;
}
double SalariedEmployee::get_salary()
{
return salary;
}
void SalariedEmployee::change_salary(double new_salary)
{
salary = new_salary;
}
void SalariedEmployee::print_check()
{
net_pay = salary;
cout << " __________________________________________________ ";
cout << "Pay to the order of " << name << endl;
cout << "The sum of " << net_pay << " Dollars ";
cout << "_________________________________________________ ";
cout << "Check Stub NOT NEGOTIABLE " ;
cout << "Employee Number: " << ssn << endl;
cout << " Salaried Employee. Regular Pay: "
<< salary << endl;
cout << "_________________________________________________ ";
}
}//END SALARIEDEMPLOYEE.CPP
Explanation / Answer
// ******************************************************** HourlyEmployee.cpp
#include
#include
#include "hourlyemployee.h"
using namespace std;
namespace workemployees
{
HourlyEmployee::HourlyEmployee() : Employee()
{
cout << "Enter HourlyEmployee wage rate, followed by return.: ";
cin >> wage_rate;
cout << "Enter number of hours worked, followed by return: ";
cin >> hours;
}
HourlyEmployee::HourlyEmployee(string new_name, string new_number,
double new_wage_rate, double new_hours)
: Employee(new_name, new_number),
wage_rate(new_wage_rate), hours(new_hours)
{
//deliberately empty
}
void HourlyEmployee::set_rate(double new_wage_rate)
{
wage_rate = new_wage_rate;
}
double HourlyEmployee::get_rate()
{
return wage_rate;
}
void HourlyEmployee::set_hours(double hours_worked)
{
hours = hours_worked;
}
double HourlyEmployee::get_hours()
{
return hours;
}
void HourlyEmployee::give_raise( double amount)
{
wage_rate = wage_rate + amount;
//10% raise
wage_rate = wage_rate + (wage_rate/10);
}
void HourlyEmployee::print_check()
{
net_pay = hours * wage_rate;
cout << " ________________________________________________ ";
cout << "Pay to the order of " << name << endl;
cout << "The sum of " << net_pay << " Dollars ";
cout << "________________________________________________ ";
cout << "Check Stub: NOT NEGOTIABLE ";
cout << "Employee Number: " << ssn << endl;
cout << "Hourly Employee. Hours worked: " << hours
<< " Rate: " << wage_rate << " Pay: " << net_pay << endl;
cout << "_________________________________________________ ";
}
}//END HOURLYEMPLOYEE.CPP
// ********************************************************SalariedEmployee.cpp
#include
#include
#include "salariedemployee.h"
using namespace std;
namespace workemployees
{
SalariedEmployee::SalariedEmployee():Employee()
{
cout << " Enter Salaried Employee's weekly salary ";
cin >> salary;
}
SalariedEmployee::SalariedEmployee(string new_name, string new_number,
double new_weekly_pay )
: Employee(new_name, new_number), salary(new_weekly_pay)
{
//deliberately empty
}
void SalariedEmployee::give_raise(double amount)
{
salary = salary + amount;
//6% raise
salary = salary + (6/100*salaray);
}
double SalariedEmployee::get_salary()
{
return salary;
}
void SalariedEmployee::change_salary(double new_salary)
{
salary = new_salary;
}
void SalariedEmployee::print_check()
{
net_pay = salary;
cout << " __________________________________________________ ";
cout << "Pay to the order of " << name << endl;
cout << "The sum of " << net_pay << " Dollars ";
cout << "_________________________________________________ ";
cout << "Check Stub NOT NEGOTIABLE " ;
cout << "Employee Number: " << ssn << endl;
cout << " Salaried Employee. Regular Pay: "
<< salary << endl;
cout << "_________________________________________________ ";
}
}//END SALARIEDEMPLOYEE.CPP
Since you don't have any main methods, program compiles. But returns nothing.
Highlighted portion is the change of the code.
Please comment in case of any doubts.