Question: Create a program in C that calculates the paycheck amounts for four employees and shows the average paycheck amount. Write all your code in one

Create a program in C that calculates the paycheck amounts for four employees and shows the average paycheck amount. Write all your code in one file, including a main method that serves as a driver. You do not need to take user input; all the data can be hard-coded in main().

Use a struct for the employee records and create an array of instances of the struct on the *heap* using malloc().

Write a method called addEmployee() that takes a name, an hourly wage, and a number of hours worked, creates a struct instance with these values, and returns a pointer to the struct instance.

Write a method called calcPaychecks() that uses a for loop to iterate through the structs in the array, getting the name, hourly pay, and number of hours worked for each employee and printing this data, and then prints the average (mean) total pay. Make sure you stop iterating through the arrays when you reach the last employee (for example, if the size of the arrays is four, but there are only three employees, you don't show a default value or include it in the average calculation)

main() should call the other functions as follows:

call addEmployee() three times, each time taking the new employee record and adding it to the array. Use some reasonable data (for example "Bob Smith", 20.94, 40)

call calcPaychecks()

The output should look similar to this:

Bob Smith, wage 21.00, hours 21, total pay: $441

Sue Jones, wage 22.30, hours 12, total pay: $267.60

Carlos Suarez, wage 21.55 hours 15, total pay: $323.25

Average paycheck: $343.40

Turn in your C code and a cut-and-paste text file of your output.

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!