Question: This is an example of using default parameters. The function will accept up to 2 parameters and calculate a gross pay The function header is

This is an example of using default parameters.

The function will accept up to 2 parameters and calculate a gross pay

The function header is similar to

float calcGrossPay(float hours, float rate)

return hours * rate

if there is no rate in the function call, the pay rate defaults to $8.75

if no hours are in the function call, the hours defaults to 20 hours

call the function three times to ensure the function works

  1. calcGrossPay()
  2. calcGrossPay(hours, rate)
  3. calcGrossPay(hours)

float calcGrossPay(float hours=20 float rate=8.75)

{

return hours * rate

}

Output is from main

calcGrossPay( )

oputput should be hours are ?????.??

rate is ?????.??

gross pay is ?????.??

calcGrossPay(5, 3.33)

oputput should be hours are 5.00

rate is 3.33

gross pay is 16.65

calcGrossPay(5)

oputput should be hours are 5.00

rate is 8.75

gross pay is 43.75

call the function three times to ensure the function works

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!