Hello, I was wondering how to pass an array to a class constructor. When I run my program, I get the same gross pay for every different employee even if I enter in a different number of hours for each one. That might be where I have a problem. Any help is appreciated! Here is my code:
#ifndef PAYROLL_H
#define PAYROLL_H
class Payroll
{
private:
int hours_worked;
double payRate;
double grossPay;
public:
Payroll()
{
hours_worked = 0;
grossPay = 0.0;
grossPay = 0.0;
}
Payroll(int hours, double rate = 7.25)
{
payRate = rate;
hours_worked = hours;
}
double getGrossPay() const
{
return hours_worked * payRate;
}
};
#endif
#include <iostream>
#include <iomanip>
#include "Payroll.h"
using namespace std;
int main()
{
const int NUM_EMPLOYEES = 7;
int hours[NUM_EMPLOYEES];
double payRate;
for (int index = 0; index < NUM_EMPLOYEES; index++)
{
cout << "Enter the number of hours worked by Employee # " << (index + 1) << ": ";
cin >> hours[index];
}
Payroll employee(payRate, hours[6]);
cout << "Here is the gross pay for each employee:\n";
cout << fixed << showpoint << setprecision(2);
for (int index = 0; index < NUM_EMPLOYEES; index++)
{
cout << "The gross pay for employee # " << (index + 1) << " is: " << employee.getGrossPay() << endl;
}
return 0;
}