函数不会将数据存储到struct数组中

时间:2016-03-12 19:22:46

标签: c++

我有一个函数,假设根据员工类型和工作小时数计算员工时间。如果管理层直接支付,无论工作时间如何,如果工会加班费。

我有两个struct数组,一个用于员工数据,另一个用于他们的时间表。 我遇到的问题是我不认为我的功能是存储计算的数据。当我运行我的打印功能时,我得到零。

我一直坚持这一点,我试图尽我所能调试我的代码,但我没有得到任何东西,它没有编译任何问题。

我的问题是什么?还是问题?

C ++

//*********************************************************************************************
//         Structure to hold employee ID, Name, Pay rate per hour, Employee type
//*********************************************************************************************

struct employeeRecord {
    int IDnum;    // holds employee id number
    string name;    // holds employess name
    float payRate;    // holds employee pay rate
    int empType;    // holds employee type
};

//*********************************************************************************************
//                         structure to hold time sheet
//*********************************************************************************************

struct timeSheet{
    float hoursWorked;    //hours worked
    float grossPay;    // gross pay
    float netPay;    // net pay
    float taxAmount;    // tax amount deduction
};

//*********************************************************************************************
//                               function prototype
//*********************************************************************************************
void addEmployee(employeeRecord *employee, int &index);
void addTime(timeSheet *time, employeeRecord *employee, int &index);
void calcTime(timeSheet *time, employeeRecord *employee, int &index, float taxRate);
void outTime(timeSheet *time, employeeRecord *employee, int &index);

//*********************************************************************************************
//                                 main function
//*********************************************************************************************

int main(){


    float taxRate = .15;    // taxrate on pay
    char choice;    // holds user choice option
    int index = 0; // index of array

    // create struct arrays to hold data
    employeeRecord employee[2];
    timeSheet time[2];
//*********************************************************************************************
//                      ^^^^^^not my entire main function^^^^^Can post if needed^^^^^^
//*********************************************************************************************

/*********************************************************************************************
//                    function to to calculate timesheet
//*********************************************************************************************

void calcTime(timeSheet *time, employeeRecord *employee, int &index, float taxRate){
    index = 0;    // set index back to zero to start at first array index
    float tempHours;    //temp hour hold
    float overTime;    // overTime hours
    float hoursWorked = time[index].hoursWorked;    //hours worked 
    float grossPay = time[index].grossPay;    //employes's gross pay
    float netPay = time[index].netPay;    //employes's net pay
    float taxAmount = time[index].taxAmount;    ////employes's tax deduction
    int empType = employee[index].empType;    // employee type
    float payRate = employee[index].payRate;    // employes pay rate

    for (int i=0; i < 2; i++){
        if (empType == 0){
            if(hours > 40){
                tempHours = 40;
                overTime = hoursWorked - 40;
                grossPay = (overTime * (payRate * 1.5)) + (tempHours * payRate);
                taxAmount = grossPay * taxRate;
                netPay = grossPay - taxAmount;
            }
            else{
                grossPay = hoursWorked * payRate;
                taxAmount = grossPay * taxRate;
                netPay = grossPay - taxAmount;
            }
        }
        else{
            grossPay = hoursWorked * payRate;
            taxAmount = grossPay * taxRate;
            netPay = grossPay - taxAmount;
        }

        // increase index number
        index++;

    }
}

4 个答案:

答案 0 :(得分:1)

在计算时间内,您只将事物存储在局部变量中。

    float hoursWorked = time[index].hoursWorked;    //hours worked 

这会创建一个名为hoursWorked的局部变量,当它超出范围时会消失,它不会创建对time[index].hoursWorked的快捷引用。您正在做的所有工作都发生在这些临时的当地人身上,而不会影响时间或员工。

如果您将其更改为:

    float& hoursWorked = time[index].hoursWorked;    //hours worked 

这使hoursWorked成为time[index].hoursWorked的引用或别名,因此您对其所做的任何更改实际上都会更改time[index].hoursWorked

这应该使代码按预期工作。

答案 1 :(得分:0)

您是否尝试更改函数头以将结构作为数组指针传递?

void addTime(timeSheet *time[], employeeRecord *employee[], int &index){

答案 2 :(得分:0)

函数calcTime()仅写入结构中这些值的副本的本地值。如果您想对存储的值进行操作,则应使用引用:

// Assignments to netPay will modify timesheet[i]
float& netPay = timesheet[i].netPay

// netPay is a copy.
float netPay = timesheet[i].netPay

答案 3 :(得分:0)

您已经拥有自己的基础,让我们改进您已有的基础。我要将您的结构employeeRecord重命名为EmployeeInfo,您会明白为什么我会这样做。

stdafx.h应该至少包含iostream,字符串和内存,以及您需要的任何其他std库容器,方法和算法。

<强> EmployeeRecord.h

#ifndef EMPLOYEE_RECORD_H
#define EMPLOYEE_RECORD_H

struct EmployeeInfo {
    std::string name;
    unsigned    ID;
    unsigned    type;
    float       payRate;
}; // EmployeeInfo

struct TimeSheet {
    float hoursWorked;
    float grossPay;
    float netPay;
    float taxAmount;
}; // TimeSheet

class EmployeeRecord {
public:
    static const float m_fTaxRate;
    static const float m_fFullTimeHours;
    static const float m_fOverTimeRate;

    enum EmployeeType {
        ET_MANAGEMENT = 1,
        ET_UNION,
    }; // EmployeeType

private:
    std::shared_ptr<EmployeeInfo> m_pEmployeeInfo;
    std::shared_ptr<TimeSheet>    m_pTimeSheet;

public:
    EmployeeRecord();
    explicit EmployeeRecord( const std::string& strName );
    EmployeeRecord( const std::string& strName, const unsigned id );
    EmployeeRecord( const std::string& strName, const unsigned id, const EmployeeType type );
    EmployeeRecord( const std::string& strName, const unsigned id, const EmployeeType type, const float payRate );
    EmployeeRecord( const std::string& strName, const unsigned id, const EmployeeType type, const float payRate, const float hoursWorked );

    EmployeeRecord(const std::string& strName, const unsigned id, const unsigned type);
    EmployeeRecord(const std::string& strName, const unsigned id, const unsigned type, const float payRate);
    EmployeeRecord(const std::string& strName, const unsigned id, const unsigned type, const float payRate, const float hoursWorked);

    explicit EmployeeRecord( const EmployeeInfo& info );
    EmployeeRecord( const EmployeeInfo&, const float hours );

    ~EmployeeRecord();

    // To set Individual Parameters To The Employee Info Struct
    void setName( const std::string& strName );
    void setId( const unsigned id );
    void setType( const EmployeeType type );
    void setType( const unsigned type );
    void setPayRate( const float rate );

    // To Set A Fully Predefined EmployeeInfo
    void setEmployeeInfo( const EmployeeInfo& info );

    // To Retrieve Individual Parameters From EmpolyeeInfo
    std::string     getName() const;
    unsigned        getId() const;
    float           getPayRate() const;
    EmployeeType    getEmployeeType() const;
    unsigned        getEmployeeUType() const;

    // To Retrieve An Entire EmployeeInfo
    EmployeeInfo    getEmployeeInfo() const;

    // To Add Individual Parameters To The TimeSheet Struct
    void setHoursWorked( const float hours );

    // Calculate Values In Time Sheet
    void calculateWages();

    // To Get Individual Parameters From Time Sheet
    float getHoursWorked() const;
    float getGrossPay() const;
    float getNetPay() const;
    float getTaxAmount() const;

    // Retrieve An Entire Employee TimeSheet
    TimeSheet getTimeSheet() const;

}; // EmployeeRecord

#endif // EMPLOYEE_RECORD_H

<强> EmployeeRecord.cpp

#include "stdafx.h"
#include "EmployeeRecord.h"

const float EmployeeRecord::m_fTaxRate = 0.15f;
const float EmployeeRecord::m_fFullTimeHours = 40.0f;
const float EmployeeRecord::m_fOverTimeRate = 1.5f;

// ----------------------------------------------------------------------------
// EmployeeRecord()
EmployeeRecord::EmployeeRecord() :
m_pEmployeeInfo( nullptr ),
m_pTimeSheet( nullptr ),
m_bCalcWagesHasBeenCalled( false ) {
    m_pEmployeeInfo = std::make_shared<EmployeeInfo>();
    // m_pEmployeeInfo.reset( new EmployeeInfo );
    m_pEmployeeInfo->name    = std::string();
    m_pEmployeeInfo->ID      = 0;
    m_pEmployeeInfo->type    = 0;
    m_pEmployeeInfo->payRate = 0.0f;

    m_pTimeSheet = std::make_shared<TimeSheet>();
    //m_pTimeSheet.reset( new TimeSheet );
    m_pTimeSheet->hoursWorked  = 0.0f;
    m_pTimeSheet->grossPay     = 0.0f;
    m_pTimeSheet->netPay       = 0.0f;
    m_pTimeSheet->taxAmount    = 0.0f;

} // EmployeeRecord

// ----------------------------------------------------------------------------
// EmployeeRecord()
EmployeeRecord::EmployeeRecord( const std::string& name ) :
m_pEmployeeInfo( nullptr ),
m_pTimeSheet( nullptr ),
m_bCalcWagesHasBeenCalled( false ) {
    // EmployeeInfo
    m_pEmployeeInfo = std::make_shared<EmployeeInfo>();
    //m_pEmployeeInfo.reset( new EmployeeInfo );
    m_pEmployeeInfo->name     = name;
    m_pEmployeeInfo->ID       = 0;  
    m_pEmployeeInfo->type     = 0;
    m_pEmployeeInfo->payRate  = 0.0f;

    // TimeSheet
    m_pTimeSheet = std::make_shared<TimeSheet>();
    //m_pTimeSheet.reset( new TimeSheet );
    m_pTimeSheet->hoursWorked = 0.0f;
    m_pTimeSheet->grossPay    = 0.0f;
    m_pTimeSheet->netPay      = 0.0f;
    m_pTimeSheet->taxAmount   = 0.0f;
} // EmployeeRecord

// ----------------------------------------------------------------------------
// EmployeeRecord()
EmployeeRecord::EmployeeRecord( const std::string& name, const unsigned id ) :
m_pEmployeeInfo( nullptr ),
m_pTimeSheet( nullptr ),
m_bCalcWagesHasBeenCalled( false ) {
    // EmployeeInfo
    m_pEmployeeInfo = std::make_shared<EmployeeInfo>();
    //m_pEmployeeInfo.reset( new EmployeeInfo );
    m_pEmployeeInfo->name    = name;
    m_pEmployeeInfo->ID      = id;  
    m_pEmployeeInfo->type    = 0;
    m_pEmployeeInfo->payRate = 0.0f;

    // TimeSheet
    m_pTimeSheet = std::make_shared<TimeSheet>();
    //m_pTimeSheet.reset(new TimeSheet);
    m_pTimeSheet->hoursWorked = 0.0f;
    m_pTimeSheet->grossPay    = 0.0f;
    m_pTimeSheet->netPay      = 0.0f;
    m_pTimeSheet->taxAmount   = 0.0f;
} // EmployeeRecord

// ----------------------------------------------------------------------------
// EmployeeRecord()
EmployeeRecord::EmployeeRecord( const std::string& name, const unsigned id, const EmployeeType type ) :
m_pEmployeeInfo( nullptr ),
m_pTimeSheet( nullptr ),
m_bCalcWagesHasBeenCalled( false ) {
    // EmployeeInfo
    m_pEmployeeInfo = std::make_shared<EmployeeInfo>();
    //m_pEmployeeInfo.reset( new EmployeeInfo );
    m_pEmployeeInfo->name    = name;
    m_pEmployeeInfo->ID      = id;
    m_pEmployeeInfo->type    = static_cast<unsigned>( type );
    m_pEmployeeInfo->payRate = 0.0f;

    // TimeSheet
    m_pTimeSheet = std::make_shared<TimeSheet>();
    //m_pTimeSheet.reset(new TimeSheet);
    m_pTimeSheet->hoursWorked = 0.0f;
    m_pTimeSheet->grossPay    = 0.0f;
    m_pTimeSheet->netPay      = 0.0f;
    m_pTimeSheet->taxAmount   = 0.0f;
} // EmployeeRecord

// ----------------------------------------------------------------------------
// EmployeeRecord()
EmployeeRecord::EmployeeRecord( const std::string& name, const unsigned id, const EmployeeType type, float rate ) :
m_pEmployeeInfo( nullptr ),
m_pTimeSheet( nullptr ),
m_bCalcWagesHasBeenCalled( false ) {
    // EmployeeRecord
    m_pEmployeeInfo = std::make_shared<EmployeeInfo>();
    //m_pEmployeeInfo.reset( new EmployeeInfo );
    m_pEmployeeInfo->name    = name;
    m_pEmployeeInfo->ID      = id;
    m_pEmployeeInfo->type    = static_cast<unsigned>( type );
    m_pEmployeeInfo->payRate = rate;

    // TimeSheet
    m_pTimeSheet = std::make_shared<TimeSheet>();
    // m_pTimeSheet.reset( new TimeSheet );
    m_pTimeSheet->hoursWorked = 0.0f;
    m_pTimeSheet->grossPay    = 0.0f;
    m_pTimeSheet->netPay      = 0.0f;
    m_pTimeSheet->taxAmount   = 0.0f;
} // EmployeeRecord

// ----------------------------------------------------------------------------
// EmployeeRecord()
EmployeeRecord::EmployeeRecord(const std::string& name, const unsigned id, const EmployeeType type, const float rate, const float hours) :
m_pEmployeeInfo( nullptr ),
m_pTimeSheet( nullptr ),
m_bCalcWagesHasBeenCalled( false ) {
    // EmployeeInfo 
    m_pEmployeeInfo = std::make_shared<EmployeeInfo>();
    // m_pEmployeeInfo.reset( new EmployeeInfo );
    m_pEmployeeInfo->name    = name;
    m_pEmployeeInfo->ID      = id;
    m_pEmployeeInfo->type    = static_cast<unsigned>( type );
    m_pEmployeeInfo->payRate = rate;

    // TimeSheet
    m_pTimeSheet = std::make_shared<TimeSheet>();
    // m_pTimeSheet.reset( new TimeSheet );
    m_pTimeSheet->hoursWorked = hours;
    m_pTimeSheet->grossPay    = 0.0f;
    m_pTimeSheet->netPay      = 0.0f;
    m_pTimeSheet->taxAmount   = 0.0f;

    // Since We Have Enough Data Calculate Wages & Taxes Here
    calculateWages();
} // EmployeeRecord

// ----------------------------------------------------------------------------
// EmployeeRecord()
EmployeeRecord::EmployeeRecord(const std::string& name, const unsigned id, const unsigned type) :
m_pEmployeeInfo( nullptr ),
m_pTimeSheet( nullptr ),
m_bCalcWagesHasBeenCalled( false ) {
    // EmployeeInfo
    m_pEmployeeInfo = std::make_shared<EmployeeInfo>();
    //m_pEmployeeInfo.reset( new EmployeeInfo );
    m_pEmployeeInfo->name = name;
    m_pEmployeeInfo->ID = id;
    m_pEmployeeInfo->type = type;
    m_pEmployeeInfo->payRate = 0.0f;

    // TimeSheet
    m_pTimeSheet = std::make_shared<TimeSheet>();
    //m_pTimeSheet.reset(new TimeSheet);
    m_pTimeSheet->hoursWorked = 0.0f;
    m_pTimeSheet->grossPay = 0.0f;
    m_pTimeSheet->netPay = 0.0f;
    m_pTimeSheet->taxAmount = 0.0f;
} // EmployeeRecord

// ----------------------------------------------------------------------------
// EmployeeRecord()
EmployeeRecord::EmployeeRecord(const std::string& name, const unsigned id, const unsigned type, float rate) :
m_pEmployeeInfo( nullptr ),
m_pTimeSheet( nullptr ),
m_bCalcWagesHasBeenCalled( false ) {
    // EmployeeRecord
    m_pEmployeeInfo = std::make_shared<EmployeeInfo>();
    //m_pEmployeeInfo.reset( new EmployeeInfo );
    m_pEmployeeInfo->name = name;
    m_pEmployeeInfo->ID = id;
    m_pEmployeeInfo->type = type;
    m_pEmployeeInfo->payRate = rate;

    // TimeSheet
    m_pTimeSheet = std::make_shared<TimeSheet>();
    // m_pTimeSheet.reset( new TimeSheet );
    m_pTimeSheet->hoursWorked = 0.0f;
    m_pTimeSheet->grossPay = 0.0f;
    m_pTimeSheet->netPay = 0.0f;
    m_pTimeSheet->taxAmount = 0.0f;
} // EmployeeRecord

// ----------------------------------------------------------------------------
// EmployeeRecord()
EmployeeRecord::EmployeeRecord(const std::string& name, const unsigned id, const unsigned type, const float rate, const float hours) :
m_pEmployeeInfo( nullptr ),
m_pTimeSheet( nullptr ),
m_bCalcWagesHasBeenCalled( false ) {
    // EmployeeInfo 
    m_pEmployeeInfo = std::make_shared<EmployeeInfo>();
    // m_pEmployeeInfo.reset( new EmployeeInfo );
    m_pEmployeeInfo->name = name;
    m_pEmployeeInfo->ID = id;
    m_pEmployeeInfo->type = type;
    m_pEmployeeInfo->payRate = rate;

    // TimeSheet
    m_pTimeSheet = std::make_shared<TimeSheet>();
    // m_pTimeSheet.reset( new TimeSheet );
    m_pTimeSheet->hoursWorked = hours;
    m_pTimeSheet->grossPay = 0.0f;
    m_pTimeSheet->netPay = 0.0f;
    m_pTimeSheet->taxAmount = 0.0f;

    // Since We Have Enough Data Calculate Wages & Taxes Here
    calculateWages();
} // EmployeeRecord

// ----------------------------------------------------------------------------
// EmployeeRecord()
EmployeeRecord::EmployeeRecord( const EmployeeInfo& info ) :
m_pEmployeeInfo( nullptr ),
m_pTimeSheet( nullptr ),
m_bCalcWagesHasBeenCalled( false ) {
    // EmployeeInfo
    m_pEmployeeInfo = std::make_shared<EmployeeInfo>( info );

    // TimeSheet
    m_pTimeSheet = std::make_shared<TimeSheet>();
    //m_pTimeSheet.reset( new TimeSheet );
    m_pTimeSheet->hoursWorked = 0.0f;
    m_pTimeSheet->grossPay    = 0.0f;
    m_pTimeSheet->netPay      = 0.0f;
    m_pTimeSheet->taxAmount   = 0.0f;
} // EmployeeRecord

// ----------------------------------------------------------------------------
// EmployeeRecord()
EmployeeRecord::EmployeeRecord( const EmployeeInfo& info, const float hours ) :
m_pEmployeeInfo( nullptr ),
m_pTimeSheet( nullptr ),
m_bCalcWagesHasBeenCalled( false ) {
    // EmployeeInfo
    m_pEmployeeInfo = std::make_shared<EmployeeInfo>( info );

    // TimeSheet
    m_pTimeSheet = std::make_shared<TimeSheet>();
    // m_pTimeSheet.reset( new TimeSheet );
    m_pTimeSheet->hoursWorked = hours;
    m_pTimeSheet->grossPay = 0.0f;
    m_pTimeSheet->netPay = 0.0f;
    m_pTimeSheet->taxAmount = 0.0f;

    // Since We Have Enough Data Calculate Wages & Taxes Here
    calculateWages();
} // EmployeeRecord

// ----------------------------------------------------------------------------
// ~EmployeeRecord()
EmployeeRecord::~EmployeeRecord() {
    m_pEmployeeInfo.reset();
    m_pEmployeeInfo = nullptr;
    m_pTimeSheet.reset();
    m_pTimeSheet = nullptr;
} // ~EmployeeRecord

// ----------------------------------------------------------------------------
// setName()
void EmployeeRecord::setName( const std::string& name ) {
    m_pEmployeeInfo->name = name;
} // setName

// ----------------------------------------------------------------------------
// setId()
void EmployeeRecord::setId( unsigned id ) {
    m_pEmployeeInfo->ID = id;
} // setId

// ----------------------------------------------------------------------------
// setType()
void EmployeeRecord::setType( const EmployeeType type ) {
    if ( m_bCalcWagesHasBeenCalled ) {
        if ( m_pEmployeeInfo->type != static_cast<unsigned>( type ) ) { 
            m_pEmployeeInfo->type = static_cast<unsigned>( type );
            calculateWages();
        }
    } else {
        m_pEmployeeInfo->type = static_cast<unsigned>( type );
    }
} // setType

// ----------------------------------------------------------------------------
// setType()
void EmployeeRecord::setType( const unsigned type ) {
    if ( m_bCalcWagesHasBeenCalled ) {
        if ( m_pEmployeeInfo->type != type ) {
            m_pEmployeeInfo->type = type;
            calculateWages();
        }
    } else {
        m_pEmployeeInfo->type = type;
    }
} // setType

// ----------------------------------------------------------------------------
// setPayRate()
void EmployeeRecord::setPayRate( const float rate ) {
    if ( m_bCalcWagesHasBeenCalled ) {
        if ( m_pEmployeeInfo->payRate != rate ) {
            m_pEmployeeInfo->payRate = rate;
            calculateWages();
        }
    } else {
        m_pEmployeeInfo->payRate = rate;
    }
} // setPayRate

// ----------------------------------------------------------------------------
// setEmployeeInfo()
void EmployeeRecord::setEmployeeInfo( const EmployeeInfo& info ) {
    if ( nullptr == m_pEmployeeInfo ) {
        m_pEmployeeInfo = std::make_shared<EmployeeInfo>( info );
    } else {
        m_pEmployeeInfo.reset();
        m_pEmployeeInfo = std::make_shared<EmployeeInfo>( info );
    }
} // setEmployeeInfo

// ----------------------------------------------------------------------------
// getName()
std::string EmployeeRecord::getName() const {
    return m_pEmployeeInfo->name;
} // getName

// ----------------------------------------------------------------------------
// getId()
unsigned EmployeeRecord::getId() const {
    return m_pEmployeeInfo->ID;
} // getId

// ----------------------------------------------------------------------------
// getPayRate()
float EmployeeRecord::getPayRate() const {
    return m_pEmployeeInfo->payRate;
} // getPayRate

// ----------------------------------------------------------------------------
// getEmployeeType()
EmployeeRecord::EmployeeType EmployeeRecord::getEmployeeType() const {
    return static_cast<EmployeeType>( m_pEmployeeInfo->type );
} // getEmployeeType

// ----------------------------------------------------------------------------
// getEmployeeUType()
unsigned EmployeeRecord::getEmployeeUType() const {
    return m_pEmployeeInfo->type;
} // getEmployeeUType

// ----------------------------------------------------------------------------
// getEmployeeInfo
EmployeeInfo EmployeeRecord::getEmployeeInfo() const {
    return *m_pEmployeeInfo.get();
} // getEmployeeInfo

// ----------------------------------------------------------------------------
// setHoursWorked()
void EmployeeRecord::setHoursWorked( const float hours ) {
    if ( m_bCalcWagesHasBeenCalled ) {
        if ( m_pTimeSheet->hoursWorked != hours ) {
            m_pTimeSheet->hoursWorked = hours;
            calculateWages();
        }
    } else {
        m_pTimeSheet->hoursWorked = hours;
    }
} // setHoursWorked

// ----------------------------------------------------------------------------
// calculateWages()
void EmployeeRecord::calculateWages() {
    // Error Cases
    if ( m_pEmployeeInfo == nullptr ) {
        std::cout << "Error: m_pEmployeeInfo = nullptr; not enough information to calculate wages and taxes." << std::endl;
        return;
    }

    if ( m_pEmployeeInfo->payRate == 0.0f ) {
        std::cout << "Error: payRate = " << m_pEmployeeInfo->payRate << " can not caculate wages and taxes." << std::endl;
        return;
    }

    if ( m_pEmployeeInfo->type == 0 ) {
        std::cout << "Error: EmployeeType = " << m_pEmployeeInfo->type << " can not determine which pay scale to use." << std::endl;
        return;
    }   

    // Warning Cases
    if ( m_pEmployeeInfo->name.empty() ) {
        std::cout << "Warning: It is possible to calculate wages and taxes, but no name available to assign it to." << std::endl;
    }

    if ( m_pEmployeeInfo->ID == 0 || m_pEmployeeInfo->ID == -1 ) {
        std::cout << "Warning: It is possible to calculate wages and taxes, but current employeeID is invalid." << std::endl;
    }

    if ( m_pTimeSheet->hoursWorked == 0 ) {
        std::cout << "Warning: hours worked = " << m_pTimeSheet->hoursWorked << " it is possible that this employee worked 0 hours." << std::endl;
    }

    switch ( static_cast<EmployeeType>( m_pEmployeeInfo->type ) ) {
        case ET_MANAGEMENT: {
            m_pTimeSheet->grossPay  = m_pEmployeeInfo->payRate * m_pTimeSheet->hoursWorked;
            m_pTimeSheet->taxAmount = m_pTimeSheet->grossPay * m_fTaxRate;
            m_pTimeSheet->netPay    = m_pTimeSheet->grossPay - m_pTimeSheet->taxAmount;
            break;
        }
        case ET_UNION: {
            float overTimeHours = 0.0f;
            if ( m_pTimeSheet->hoursWorked > m_fFullTimeHours ) {
                overTimeHours = m_pTimeSheet->hoursWorked - m_fFullTimeHours;
            }

            m_pTimeSheet->grossPay  = (m_pEmployeeInfo->payRate * m_fFullTimeHours) + (overTimeHours * m_fOverTimeRate);
            m_pTimeSheet->taxAmount = m_pTimeSheet->grossPay * m_fTaxRate;
            m_pTimeSheet->netPay    = m_pTimeSheet->grossPay - m_pTimeSheet->taxAmount;
            break;
        }
    }

    m_bCalcWagesHasBeenCalled = true;
} // calculateWages

// ----------------------------------------------------------------------------
// getHoursWorked()
float EmployeeRecord::getHoursWorked() const {
    return m_pTimeSheet->hoursWorked;
} // getHoursWorked

// ----------------------------------------------------------------------------
// getGrossPay()
float EmployeeRecord::getGrossPay() const {
    return m_pTimeSheet->grossPay;
} // getGrossPay

// ----------------------------------------------------------------------------
// getNetPay()
float EmployeeRecord::getNetPay() const {
    return m_pTimeSheet->netPay;
} // getNetPay

// ----------------------------------------------------------------------------
// getTaxAmount()
float EmployeeRecord::getTaxAmount() const {
    return m_pTimeSheet->taxAmount;
} // getTaxAmount

// ----------------------------------------------------------------------------
// getTimeSheet()
TimeSheet EmployeeRecord::getTimeSheet() const {
    return *m_pTimeSheet.get();
} // getTimeSheet

这个类有几个构造函数:一个是默认的,它将创建一个空实例,以后需要通过传入单个字段或传入所需的结构来填充它。它有部分构造函数,其余部分必须在以后填写。它有几个完整的构造函数,如果成功构造,它们将自动调用该方法来计算工资和税收。这是一些设置函数,它们将检查是否已调用calculateWages(),并且如果传递的值有差异,如果两种情况都为真,那么它将更新该字段并调用calculateWages()再次,如果不是,它只会添加值。