Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ : Passing Arguments to Constructors: I need help! The pay of an hourly worke

ID: 3777088 • Letter: C

Question

C++ : Passing Arguments to Constructors: I need help!

The pay of an hourly worker is calculated by multiplying the hours worked by the hourly rate—up to 40 hours; any hours worked beyond 40 are paid at time-and-a-half (one and a half times the hourly rate). Given the variables hours, rate, and pay have already been declared and assigned  values , write a fragment of code (one or more statements ) that assigns to pay the proper value , taking into account time-and-a-half. (basic arithmetic, basic conditional )

Explanation / Answer

Given variables are: hours, rate, pay.

Fragment of code (one or more statements ) that assigns to pay the proper value , taking into account time-and-a-half.

pay = hours * rate;

if(hours > 40)

pay += (hours - 40) * rate * 0.5;