Can anyone figure out why I get -9.032654e something from my biWeeklySalary function?
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include "HireDate.h"
#include <string>
using std::string;
class Employee
{
public:
Employee();
Employee( const string &, const string &, const string &, const HireDate & );
~Employee();
void setFirstName( const string & );
string getFirstName() const;
void setLastName( const string & );
string getLastName() const;
void setSocialSecurityNumber( const string & );
string getSocialSecurityNumber() const;
void print() const;
private:
string firstName;
string lastName;
string socialSecurityNumber;
const HireDate hireDate;
};
#endif
#include <iostream>
using std::cout;
using std::endl;
#include "Employee.h"
#include "HireDate.h"
#include "MailCarrier.h"
//constructor
Employee::Employee()
{
}
//Constructor
Employee::Employee(const string &first, const string &last, const string &ssn, const HireDate &dateOfHire )
: firstName( first ), lastName( last ), socialSecurityNumber( ssn ), hireDate( dateOfHire )
{
}
Employee::~Employee() //destructor
{
}
//function to set Employee's first name
void Employee::setFirstName( const string &first )
{
firstName = first;
}
//function to get Employee's first name
string Employee::getFirstName() const
{
return firstName;
}
//function to set Employee's last name
void Employee::setLastName( const string &last )
{
lastName = last;
}
//function to get Employee's last name
string Employee::getLastName() const
{
return lastName;
}
// function to set Employee's Social Security Number
void Employee::setSocialSecurityNumber( const string &ssn )
{
socialSecurityNumber = ssn;
}
//function to get Employee's Social Security Number
string Employee::getSocialSecurityNumber() const
{
return socialSecurityNumber;
}
//function to print Employee object
void Employee::print() const
{
cout << "Employee: " << getFirstName() << ' ' << getLastName()
<< "\nSocial Security Number: " << getSocialSecurityNumber()
<< "\nTotal of your paycheck: " << MailCarrier::getTotalPay() << endl;
}
#ifndef MAILCARRIER_H
#define MAILCARRIER_H
#include "Employee.h"
#include "HireDate.h"
#include <iostream>
using std::cout;
using std::endl;
class MailCarrier : public Employee
{
public:
MailCarrier();
MailCarrier( const string &, const string &, const string &, const HireDate &, double );
void setPayRate( double );
double getPayRate() const;
double getTotalPay() const;
void getHoursFromUser();
double biWeeklySalary();
private:
double payRate;
double hours[ 12 ];
double totalPay;
};
#endif
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include "MailCarrier.h"
//Constructor
MailCarrier::MailCarrier()
{
for (int i = 0; i <= 12; i++)
hours[i] = 0;
}
//Constructor
MailCarrier::MailCarrier( const string &first, const string &last, const string &ssn,
const HireDate &, double pay )
//explicitly call base-class constructor
: Employee( first, last, ssn, HireDate( ) )
{
setPayRate( pay ); // validate and store payRate
}
// function to set payRate
void MailCarrier::setPayRate( double pay )
{
payRate = ( pay > 0.0 && pay < 35.0 ) ? pay : 17.17;
}
double MailCarrier::getPayRate() const
{
return payRate;
}
//function to get total pay for paycheck
double MailCarrier::getTotalPay() const
{
return totalPay;
}
//Function to get hours from user
void MailCarrier::getHoursFromUser()
{
for (int j = 0; j <= 11; j++)
{
cout << "Enter hours for" << Employee::getFirstName() << "day " << j+1 << ": ";
cin >> hours[ j ];
}
}//End function
//Function to calculate total pay
double MailCarrier::biWeeklySalary()
{
double pay = 0;
double totalPay = 0;
for (int k = 0; k < 11; k++)
{
if ( hours[ k ] > 10)
pay = ((payRate * 2 * ( hours[ k ] - 10)) + (payRate * 1.5 * 2) + (payRate * 8));
else if ( hours[ k ] > 8)
pay = ((payRate * 1.5 * (hours[ k ] - 8)) + ( payRate * 8));
else if ( hours[ k ] >= 0)
pay = payRate * 8;
else cout << "Hours entered incorrectly, Please try again!\n" << endl;
totalPay += pay;
}
return totalPay;
}