Well first your problem is in your functions inside of the employee class, you have
1 2 3 4 5 6
|
void setInfo (int pin, float pay, int hours)
{
empInfo[pin].id = pin;
empInfo[pin].payRate = pay;
empInfo[pin].maxHours = hours;
}
|
empInfo is something you declared in your main function, so there is no way for the employee class to know what that is since it isn't in the same scope.
When you call empInfo[pin].setInfo(pin, pay, hours); inside your main you're calling the setInfo function inside your employee class FOR the object empInfo[pin], so the attributes and functions in the employee class are only working for that particular element in the array at this point.
An example, lets pretend I have a Phone class and I'm setting up some objects for it:
1 2 3 4 5
|
Phone droid;
Phone iphone;
iphone.setInfo("3G", "White"); // Call 1
droid.setInfo("4G", "Black"); // Call 2
|
When I get to Call 1, everything that happens inside of that call inside of my Phone class, only pertains to iphone.
Everything that happens inside of the Phone class for Call 2, only deals with the droid object.
So for your functions you can just have
1 2 3 4 5 6
|
void setInfo (int pin, float pay, int hours)
{
id = pin;
payRate = pay;
maxHours = hours;
}
|
And the same goes for your other function
1 2 3 4 5 6
|
void viewInfo () // Took out the parameter, will explain down below
{
cout << id;
cout << endl << payRate;
cout << endl << maxHours;
}
|
Now the problems in your main function, you probably changed some names around and forgot to change these but
|
empInfo[pin].setData(pin, pay, hours);
|
should be
|
empInfo[pin].setInfo(pin, pay, hours);
|
Same thing for
|
empInfo.viewDate(record);
|
should be
|
empInfo[record].viewInfo();
|
I took out the int record parameter from the viewInfo() function since your array is in the main function, so you can just access the specific element from there, then call the viewInfo() method from it