Question

I am really struggling with this assignment, can anyone help? It is supposed to work with...

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;

}

  • Note that the constructor and set functions do validation on the data that is to be stored in the Employee object. They are similar to the validation in the Rectangle class from the textbook in Section 7.11 Focus on Software Engineering: Separating class Specification, Implementation and Client Code. For a more detailed discussion of validation for class objects, and the Employee class validation, see Employee Data Validation.
  • 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 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:

  • 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 $20 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.

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:

  • 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.

Requirements/Hints:

  1. Global variables are variables that are declared outside any function. Do not use global variables in your programs. Declare all your variables inside functions
  2. A sample Master file and Transaction file can downloaded here:
    master9.txt
    trans9.txt

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.

  1. Use the C++ string class to hold the employee name.
  2. You should use an Employee class object to hold the master file information for one employee.
  3. The Payroll Report should be written to a file.
  4. Notes on reading C++ string objects:

    The getline function is first introduced in Chapter 3 and then covered more thoroughly in the Files chapter. The C++ code:

    string name;
    getline( cin, name );

    will read all characters up to the end of the line (to the first newline character in the input stream). You can specify a character other than the newline character to stop the input. For example:

    getline( cin, name, '#' );

    will read all characters until the '#' is found in the input. The Transaction file uses the '#' to mark the end of the names so that they are all 20 characters long.
    Note that you can use getline with input file streams by replacing cin with the input file object.
0 0
Add a comment Improve this question Transcribed image text
Answer #1


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;
}

Add a comment
Know the answer?
Add Answer to:
I am really struggling with this assignment, can anyone help? It is supposed to work with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 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...

    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...

  • Design a Payroll class with the following fields:

    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)...

    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...

    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...

    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...

    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...

  • C++ Simple Employee Tracking System

    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 Employee...

    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:...

    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[]) { //...

    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 =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT