COSC 1320 - C++ Programming
Bob Comer, Professor of Computer Studies


Assignment 8 - Payroll Version 2.0

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

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 this partial Employee class:


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.

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 employee IDs in the master file are exactly the same as the employee IDs in the transaction file.

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. Print one line for each transaction that contains:

The final line of the payroll report should print the total amount of gross pay and total amount of net pay for the week.

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. The Master file and Transaction file can downloaded here:
    master8.txt
    trans8.txt
  3. Use the C++ string class to hold the employee name.
  4. You should use an Employee class object to hold the master file information for one employee.
  5. The Payroll Report should be written to a file.
  6. 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.


Return to C++ Home Page

Copyright: © 2011 by the Austin Community College
Department of Computer Studies. All rights reserved.
Comments to:
Bob Comer
Last updated: April 13, 2011