C++ Employee Class Program The Employee Class For this project you need to desig
ID: 3722605 • Letter: C
Question
C++ Employee Class Program
The Employee Class
For this project you need to design an Employee class. Your Employee class should have the following data members:
employeeNumber (integer), name (string), address (string), phone (string), hourlyWage (double), hoursWorked this week (double)
Your Employee class will have the following functions:
A constructor for the Employee class that takes arguments to initialize all of the above mentioned data members.
'Getters' for each data attribute of your class.
Setters for every attribute except employeeNumber. We will not use the setters in this assignment, but in an actual payroll application, employee data, except for the employee number, can change (due to address change, marriage, a raise or promotion etc.).
A function, calcPay() that calculates and returns an employee's net pay. An employee's gross pay is calculated by multiplying the hours worked by their hourly wage. Be sure to give time-and-a-half for overtime (anything over 40 hours). To compute the net pay, deduct 20% of the gross for Federal income tax, and 7.5% of the gross for state income tax.
A function, printCheck() that prints out a pay check for each employee.
The major function of this first exercise is to test your Employee class. You will upload 3 files:
employee.h, employee.cpp, main.cpp
Your main() function does the following.
Creates two Employee objects with data that you can glean from the output below. These objects will be 'hard coded' into your .cpp file. There will be no interactive input for this program.
Calls the needed getter member functions to display the employee's name, number, address, and phone, as shown below.
Calls printCheck() to print the check, which follows the employee's personal information. Note that printCheck calls calcPay, and prints the whitespace that you see below before and after the check portion.
For this project, you will create 3 files: main.cpp, Employee.h, and Employee.cpp. You will place your Employee class definition in Employee.h. The bodies of the Employee member functions go in Employee.cpp.
Explanation / Answer
//Employee.h
#include <string>
using namespace std;
class Employee
{
public:
Employee(int, string, string, string, double, double);
string getName();
string getAddress();
string getPhone();
double getHourlyWage();
double getHourlyWorked();
void setName(string);
void setAddress(string);
void setPhone(string);
void setHourlyWaged(double);
void setHourlyWorked(double);
double calcPay();
void printCheck();
private:
int emplyeeNumber;
string name;
string address;
string phone;
double hourlyWage;
double hoursWorked;
};
//Employee.cpp
#include "./Employee.h"
Employee::Employee(int empNum, string n, string ph, string add, double h_wage, double h_work){
emplyeeNumber = empNum;
name = n;
phone = ph;
address = add;
hourlyWage = h_wage;
hoursWorked = h_work;
}
string Employee::getName()
{
return name;
}
string Employee::getAddress()
{
return address;
}
string Employee::getPhone()
{
return phone;
}
double Employee::getHourlyWage()
{
return hourlyWage;
}
double Employee::getHourlyWorked()
{
return hoursWorked;
}
void Employee::setName(string n)
{
name = n;
}
void Employee::setAddress(string add)
{
address = add;
}
void Employee::setPhone(string ph)
{
phone = ph;
}
void Employee::setHourlyWaged(double hours)
{
hourlyWage = hours;
}
void Employee::setHourlyWorked(double hours)
{
hoursWorked = hours;
}
double Employee::calcPay()
{
double pay = hoursWorked * hourlyWage;
if (hoursWorked > 40)
{
pay += (hoursWorked - 40) * 1.5 * hourlyWage;
}
pay = pay - ((pay * 0.2) + (pay * 0.075)); //20% = 0.20; 7.5% = 0.075
return pay;
}
void Employee::printCheck()
{
cout << "Pay Check: " << calcPay() << endl;
}
//main.cpp
#include <iostream>
#include "Employee.cpp"
using namespace std;
int main()
{
Employee *emp1 = new Employee(1234, "Someswar Rao", "657-267-2763", "Andhra Pradesh, India", 200, 100);
cout << "Employee Name: " << emp1->getName() << endl;
cout << "Employee Phone Number: " << emp1->getPhone() << endl;
cout << "Employee Address: " << emp1->getAddress() << endl;
cout << "Employee hourly wage: " << emp1->getHourlyWage() << endl;
cout << "Employee hours worked: " << emp1->getHourlyWorked() << endl;
emp1->printCheck();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.