203k views
4 votes
Assume the input data is structured as follows: first there is a non-negative integer specifying the number of employee timesheets to be read in. This is followed by data for each of the employees. The first number for each employee is an integer that specifies their pay per hour in cents. Following this are 5 integers , the number of hours they worked on each of the days of the workweek. Given this data, and given that an int variable total has been declared , write a loop and any necessary code that reads the data and stores the total payroll of all employees in total. Note that you will have to add up the numbers worked by each employee and multiply that by that particular employee’s pay rate to get the employee’s pay for the week– and sum those values into total.ASSUME the availability of a variable , stdin, that references a Scanner object associated with standard input.

1 Answer

5 votes

Answer:

Following are the code of the program.

//set an integer data type variable

int num_Timesheets;

//set an integer data type variable and initialize to 0

int cents_PerHours = 0;

//set an integer data type variable

int hours_Worked;

//already declared and initialize to 0

total = 0;

//get input from the user

num_Timesheets = stdin.nextInt();

//set the for loop

for(int i = 1; i <= num_Timesheets; i++)

{

//initialize to 0

hours_Worked = 0;

//get input from the user

cents_PerHours = stdin.nextInt();

//set the for loop

for (int ii = 1; ii <= 5; ii++)

{

hours_Worked = hours_Worked + stdin.nextInt();

}

//perform calculation to find employee’s pay for the week

total = total + (hours_Worked * cents_PerHours);

}

Step-by-step explanation:

Here, we set three integer data type variables "num_Timesheets", "cents_PerHours", and "hours_Worked" and initialize the value in the variable "cents_PerHours" to 0.

Then, initialize the value in the integer variable "total" to 0 which is already declared.

Finally, we set two for loop first one to get input from the user and the second one to perform a calculation to find employee’s pay for the week.

User DaveJohnston
by
6.1k points