Ask your own question, for FREE!
Computer Science 21 Online
OpenStudy (anonymous):

help with passing vector array to a function (c++)?

OpenStudy (anonymous):

i need to do this: For each employee, compute and print the employee's base pay, which includes overtime (paid at one and a half times the normal rate) for each hour over 40. For example, if an employee earning $20.00 per hour works for 48 hours, then she will be paid for 40 hours at her normal rate plus 8 extra hours at $30.00 (one and a half times $20.00). check the attachments below for code and input file.

OpenStudy (rsmith6559):

You can pass a vector to a function by reference: void function( vector & passedIn )

OpenStudy (anonymous):

ok thank you that's a start

OpenStudy (anonymous):

so inside the function first of all how would i compute the base pay? (this is only one small part of the assignment btw i'm not freeloading here just trying to get a grasp on the whole thing.) can i use the same names for them as in main()? e.g., int bp = employee.rate * employee.hours; -- would that work verbatim? also i need to store the base pay for each individual employee in their respective records in the array, i'm pretty sure; how do i do that??? in the function being passed the vector array all i do is code as if it's only a single record that i'm dealing with/in question, right? and then that will apply to each record in the vector?

OpenStudy (rsmith6559):

Functions have their own namespace. In other words, you can call variables any (legal) thing that you want. int bp = employee.rate * employee.hours; // wouldn't work double bp = employee.rate * employee.hours; // would work The employee objects are completely separate entities. Your vector (arrays are a different thing, not as easy to use as vectors) would probably be holding employee objects. Each employee would have their own base pay, if that's part of the employee object. You may want to code it so that the function that calculates pay just deals with one employee object, and another function takes care of iterating through the vector, passing each employee to the calculating function in turn. The calculating function could also be part of the employee object, a member function (method) that the iterating function just calls on each employee object. The down side to versatile languages is that there can be too many ways to do something.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!