I am really struggling with this assignment, can anyone help? It is supposed to work with two files, one that contains this data:
5 Christine Kim # 30.00 3 1 15 Ray Allrich # 10.25 0 0 16 Adrian Bailey # 12.50 0 0 17 Juan Gonzales # 30.00 1 1 18 J. P. Morgan # 8.95 0 0 22 Cindy Burke # 15.00 1 0
and another that contains this data:
5 40.0 15 42.0 16 40.0 17 41.5 18 -40.0 22 20.0
Please include comments, so that I can understand what you are doing more easily (especially on the part where you read the data from the input file into the array of objects).
Be sure to read all of Chapters 8 and 9 before starting this assignment. Your job is to update your payroll program for Armadillo Automotive Group 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; } |
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:
This file is ordered by ID number and contains information for 6 emplyees. 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:
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
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:
Payroll Report
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:
The final line of the payroll report should print the total gross pay for all employees, and the total net pay for all employees.
Requirements/Hints:
Your program must work correctly for these files.
Maybe the best way to copy a file to your computer is to right-click on the link, then choose "Save As" or "Save Link As" from the popup menu. Optionally you may be able to open the text file in your browser and select "Save As" or "Save Page As" from your browser menu.
If you create your own test files in a text editor, be sure to press the enter key after the last line of input and before you save your text. If you choose to copy the text from my sample file and paste it into a text editor, be sure to press the enter key after the last line of input and before you same your text.
Please let me know if you have any doubts or you want me to modify
the answer. And if you find this answer useful then don't forget to
rate my answer as thumps up. Thank you! :)
#include <iostream>
#include <iomanip>
#include <string>
#include <limits>
#include <fstream>
using namespace std;
class Employee
{
private:
int
id;
string
name;
double hourlyPay;
int
numDeps;
int
type;
public:
Employee( int initId=0, string
initName="",
double initHourlyPay=0.0,
int initNumDeps=0, int initType=0 );
bool set(int newId, string newName, double
newHourlyPay,
int newNumDeps, int newType);
int getID(){ return id; }
string getName() { return name; }
double getHourlyPay() { return hourlyPay;
}
int getNumDeps() { return numDeps; }
int getType() { return type; }
};
int main()
{
const int TOTAL_EMPS = 6,
INSURANCE = 20;
const float TAX_RATE = .15;
int insurance;
float hoursWorked,
grossPay,
tax,
netPay;
int
id;
string
name;
double hourlyPay;
int
numDeps;
int
type;
float totalGross = 0.0,
totalNet = 0.0;
int transactions = 0;
Employee employee[6];
ifstream inFile("/Users/swapnil/CLionProjects/EmployeePayrollReport/Input1.txt");
for (int i = 0; i < TOTAL_EMPS; i++)
{
inFile >>
id;
inFile.ignore();
getline(inFile, name,
'#');
inFile >>
hourlyPay >> numDeps >> type;
employee[i].set(id,
name, hourlyPay, numDeps, type);
}
inFile.close();
ifstream inFile2("/Users/swapnil/CLionProjects/EmployeePayrollReport/Input2.txt");
ofstream outFile("/Users/swapnil/CLionProjects/EmployeePayrollReport/report.txt");
// Write report
outFile << fixed <<
setprecision(2)
<< setw(2) << "ID" << " "
<< setw(20) << left << "Employee Name"
<< setw(10) << right << "Gross Pay"
<< setw(10) << "Tax"
<< setw(12) << "Insurance"
<< setw(10) << "Net Pay" << endl;
outFile <<
"----------------------------------------------"
<< "-------------------" << endl;
for (int i = 0; i < TOTAL_EMPS; i++)
{
inFile2 >>
id;
inFile2 >>
hoursWorked;
if
(!employee[i].getID())
cout << "Entry #" << i+1 << " in employee master
file "
<< "-- invalid employee data!\n";
else if (hoursWorked
< 0.0)
cout << "Entry #" << i+1 << " employee #"
<< id << " in transaction file -- invalid hours
worked!\n";
else
{
if (hoursWorked <= 40 || employee[i].getType())
grossPay = hoursWorked * employee[i].getHourlyPay();
else
grossPay = (40 * employee[i].getHourlyPay()) +
((hoursWorked - 40) * employee[i].getHourlyPay() * 1.5);
tax = grossPay * TAX_RATE;
insurance = employee[i].getNumDeps() * INSURANCE;
netPay = grossPay - tax - insurance;
outFile << fixed << setprecision(2)
<< setw(2) << id << " "
<< setw(20) << left <<
employee[i].getName()
<< setw(10) << right << grossPay
<< setw(10) << tax
<< setw(12) << insurance
<< setw(10) << netPay << endl;
totalGross += grossPay;
totalNet += netPay;
transactions++;
}
}
inFile2.close();
outFile <<
setw(23) << "Total gross pay: "
<< setw(10) << totalGross
<< setw(22) << "Total net pay: "
<< setw(10) << totalNet << endl;
outFile.close();
cout << "Total transactions processed: " << transactions << endl;
}
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;
}
I am really struggling with this assignment, can anyone help? It is supposed to work with...
In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an array of structs to hold the employee information for all employees. If you choose to declare a separate struct for each employee, I will not deduct any points. However, I strongly recommend that you use an array of structs. Be sure to read through Chapter...
IN JAVADesign a Payroll class with the following fields:• name: a String containing the employee's name• idNumber: an int representing the employee's ID number• rate: a double containing the employee's hourly pay rate• hours: an int representing the number of hours this employee has workedThe class should also have the following methods:• Constructor: takes the employee's name and ID number as arguments• Accessors: allow access to all of the fields of the Payroll class• Mutators: let the user assign values...
I would like help and there are three different classes in the coding.. 14.11 Prog11 Inheritance(PayrollOvertime) Create three files to submit: • Payroll class.java -Base class definition • PayrollOvertime.jave - Derived class definition • ClientClass.java - contains main() method Implement the two user define classes with the following specifications: Payroll class (the base class) (4 pts) • 5 data fields(protected) o String name - Initialized in default constructor to "John Doe" o int ID - Initialized in default constructor to...
Given attached you will find a file from Programming Challenge 5 of chapter 6 with required you to write a Payroll class that calculates an employee’s payroll. Write exception classes for the following error conditions: An empty string is given for the employee’s name. An invalid value is given to the employee’s ID number. If you implemented this field as a string, then an empty string could be invalid. If you implemented this field as a numeric variable, then a...
I was wondering if I could get some help with a Java Program that I am currently working on for homework. When I run the program in Eclipse nothing shows up in the console can you help me out and tell me if I am missing something in my code or what's going on? My Code: public class Payroll { public static void main(String[] args) { } // TODO Auto-generated method stub private int[] employeeId = { 5658845, 4520125, 7895122,...
Lesson is about Input validation, throwing exceptions, overriding toString Here is what I am supposed to do in the JAVA Language: Model your code from the Time Class Case Study in Chapter 8 of Java How to Program, Late Objects (11th Edition) by Dietel (except the displayTime method and the toUniversalString method). Use a default constructor. The set method will validate that the hourly employee’s rate of pay is not less than $15.00/hour and not greater than $30.00 and validate...
This assignment involves creating a program to track employee information. Keep the following information on an employee:1. Employee ID (string, digits only, 6 characters)2. Last name (string)3. First Name (string)4. Birth date (string as MM/DD/YYYY)5. Gender (M or F, single character)6. Start date (string as MM/DD/YYYY)7. Salary per year (double)Thus you must create a class that has all of this, and get/set methods for each of these fields. Note: The fields that are designated as string should use the string...
C# Hey I am having trouble implementing additonal function to this assignment: Problem: Implement three IComparer classes on Employee - NameComparer, AgeComparer, and PayComparer - that allow Employees to be compared by the Name, Age, and Pay, respectively. Code: Employee.Core.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Employees { partial class Employee { // Field data. private string empName; private int empID; private float currPay; private int empAge; private string empSSN = ""; private string empBene...
I am having a hard time with my program to assignment 4.12. Here are the instructions: The Payroll Department keeps a list of employee information for each pay period in a text file. The format of each line of the file is the following: <last name> <hours worked> <hourly wage> Write a program that inputs a filename from the user and prints to the terminal a report of the wages paid to the employees for the given period. The report...
My Java code from last assignment: Previous Java code: public static void main(String args[]) { // While loop set-up boolean flag = true; while (flag) { Scanner sc = new Scanner(System.in); // Ask user to enter employee number System.out.print("Enter employee number: "); int employee_number = sc.nextInt(); // Ask user to enter last name System.out.print("Enter employee last name: "); String last_name = sc.next(); // Ask user to enter number of hours worked System.out.print("Enter number of hours worked: "); int hours_worked =...