Can you help me change this in c++ update your payroll program to use a C++ class.
Question:
Can you help me change this in c++
update your payroll program to use a C++ class. Each employee class object should hold the master file information for one employee. You can assume that the company has exactly 6 employees. Use an array of employee objects to hold the master file information for the company employees.
Do not put any pay information, including hours worked, in an Employee object. You might want to create a paycheck struct or object to hold pay information for one employee (this could include the hours worked).
DO NOT DO ANY INPUT OR OUTPUT IN ANY CLASS MEMBER FUNCTION.
The employee information and hours worked will come from input files instead of from the keyboard.
Employee class
Create a class to represent the master file information for one employee. Start with the following partial Employee class. You will need to add a "get" function for each class data member to return its value.
class Employee
{
private:
int id; // employee ID
string name; // employee name
double hourlyPay; // pay per hour
int numDeps; // number of dependents
int type; // employee type
public:
Employee( int initId=0, string initName="",
double initHourlyPay=0.0,
int initNumDeps=0, int initType=0 ); // Constructor
bool set(int newId, string newName, double newHourlyPay,
int newNumDeps, int newType);
};
Employee::Employee( int initId, string initName,
double initHourlyPay,
int initNumDeps, int initType )
{
bool status = set( initId, initName, initHourlyPay,
initNumDeps, initType );
if ( !status )
{
id = 0;
name = "";
hourlyPay = 0.0;
numDeps = 0;
type = 0;
}
}
bool Employee::set( int newId, string newName, double newHourlyPay,
int newNumDeps, int newType )
{
bool status = false;
if ( newId > 0 && newHourlyPay > 0 && newNumDeps >= 0 &&
newType >= 0 && newType <= 1 )
{
status = true;
id = newId;
name = newName;
hourlyPay = newHourlyPay;
numDeps = newNumDeps;
type = newType;
}
return status;
}
Note that the constructor and set functions do validation on the data that is to be stored in the Employee object.
You should be able to copy this class into your editor by highlighting the code, making a copy of it (ctrl-c in Windows), and then pasting the code into your editor window.
Do not make any changes to the data members of the class. Do not add any new data members to the class. Do not make any changes to the constructor and set functions.
To complete the class, add a "get" function for each of the private data members (that is, 5 functions). Each get function should return the value of a data member.
Program input
The program input consists of two files - a master file and a transaction file. Your code must work for the 2 input files provided. You may also want to test your program with other input data.
Master file
The master file has one line of input per employee containing:
employee ID number (integer value)
name (20 characters) - see Hint 6 below on how to input the name
pay rate per hour (floating-point value)
number of dependents (integer value)
type of employee (0 for union, 1 for management)
This file is ordered by ID number and contains information for 6 employees. You can assume that there is exactly one space between the employee ID number and the name. You can also assume that the name occupies 20 columns in the file. Important: See the Requirements/Hints section at the bottom of this page for more information on the input files.
Transaction file (weekly timesheet information)
The transaction file has one line for each employee containing:
number of hours worked for the week (floating-point value)
This file is also ordered by employee ID number and contains information for the 6 employees. Note: You can assume that the master file and the transaction file have the same number of records, and that the first hours worked is for the first employee, etc. You can also assume that the employee IDs in the master file are exactly the same as the employee IDs in the transaction file. Important: See the Requirements/Hints section at the bottom of this page for more information on the input files.
Calculations
Gross Pay - Union members are paid 1.5 times their normal pay rate for any hours worked over 40. Management employees are paid their normal pay rate for all hours worked (they are not paid extra for hours over 40).
Tax - All employees pay a flat 15% income tax.
Insurance - The company pays for insurance for the employee. Employees are required to buy insurance for their dependents at a price of $30 per dependent.
Net Pay is Gross Pay minus Tax minus Insurance.
Payroll Processing
Notice that when you store employee master information in an Employee object, the set() function does data validation. If any of the employee master information is invalid, the set() function stores default values in the Employee object. In particular, the ID of the employee is set to zero.
When processing the payroll:
If the employee master information for the employee is invalid (if the ID is 0), print an appropriate error message on the screen and do not pay the employee. The employee should not appear in the Payroll Report.
If the hours worked for an employee is invalid (less than 0.0), print an appropriate error message on the screen. The employee should not be paid and should not appear in the Payroll Report.
When all employees have been processed, print on the screen the total number of transactions that were processed correctly during the run.
This report should be printed to a file. It should not be printed on the screen. The payroll report should be printed in a tabular (row and column) format with each column clearly labeled. Do not use tabs to align your columns - you need to use the setw() manipulator. Print one line for each transaction that contains:
employee ID number
name
gross pay
tax
insurance
net pay
The final line of the payroll report should print the total gross pay for all employees, and the total net pay for all employees.
Here is my existing code
*******************************************************************************
#include
#include
#include
#include
using namespace std;
class Employee
{
private:
int ID; //employee ID variable
string name; //employee name variable
float hourlyPay; //hourlypay variable
int numDepend; //num of dependents variable
int type;//employee type
public:
void set(int, string, float, int, int);
int getID();
string getName();
float getHourlyPay();
int getNumDepend();
int getType();
}; // end of class Employee
// setter for the employee data attributes (ID, name, and hourly pay)
void Employee::set(int newID, string newName, float newHourlyPay, int newNumDepend, int newType)
{
ID = newID;
name = newName;
hourlyPay = newHourlyPay;
numDepend = newNumDepend;
type = newType;
} // end of setter for employee data attributes
// getter for the employee ID
int Employee::getID()
{
return ID;
}// end of getID()
// getter for the employee name
string Employee::getName()
{
return name;
} // end of getName()
// getter for the hourly pay
float Employee::getHourlyPay()
{
return hourlyPay;
} // end of getHourlyPay()
// getter for the dependents
int Employee::getNumDepend()
{
return numDepend;
}// end of getNumDepend()
// getter for the type
int Employee::getType()
{
return type;
}// end of Type()
// function prototypes
bool populateClass(Employee []);
void header(string);
int main()
{
int MAX_SIZE = 100; // max number of employees
Employee emp[MAX_SIZE]; // array of Employee objects
if (!populateClass(emp))
{
cout << "File not found" << endl;
return 1;
} // end of function call
system("PAUSE");
return 0;
} // end of main()
// populateClass() will instantiate an array of
//Employee class objects one time for each line
bool populateClass(Employee empArray[])
{
int counter = 0;
int ID;
char name[20];
float hourlyPay;
int numDepend = 0;
int type = 0;
ifstream masterFile("masterfile.txt");
if (!masterFile)
{
cout << "Can not open master file "masterfile.txt"" << endl;
return false;
}
// Display the column headers
cout << fixed << setprecision(2);
cout << setw(3) << left << "ID" << setw(21) < << setw(5) <
//read records from the file as long as there are records left to read
while(!masterFile.eof())
{
masterFile >> ID;
masterFile.ignore(); // ignores one character between ID and name
masterFile.get(name, 21);
masterFile >> hourlyPay;
masterFile >> numDepend;
masterFile >> type;
masterFile.ignore(2);
empArray[counter].set(ID, name, hourlyPay, numDepend, type);
cout << setw(3) << left << ID << setw(21) << left << name << setw(10) < hourlyPay << setw(5) << right << numDepend << setw(4) <
counter++; // increment the counter
}
masterFile.close();
return true;
} // end of populateClass()
Elementary Statistics Picturing the World
ISBN: 978-0321911216
6th edition
Authors: Ron Larson, Betsy Farber