Write a C program that calculate the gross pay

Write a C program that will calculate the gross pay of a set of employees.


The program should prompt the user to enter the number of hours each employee worked. The output should be similar to your previous homework.

The program determines the overtime hours (anything over 40 hours), the gross pay and then outputs a table in the following format. Column alignment, leading zeros in Clock#, and zero suppression in float fields is important. Use 1.5 as the overtime pay factor.

You should implement this program using the following structure to store the information for each employee.

struct employee
char first_name [10];
char last_name [10];
int id_number; /* use can use long int if you wish */
float wage;
float hours;
float overtime;
float gross;

struct employee *next;

Create a linked list of structures using the following data:

Connie Cobol 98401 10.60
Mary Apl 526488 9.75
Frank Fortran 765349 10.50
Jeff Ada 34645 12.25
Anton Pascal 127615 8.35

Unlike previous homework, you need to prompt the user for all of the above information, … and you still need to prompt for the hours worked for each employee.

Hint: Use one or two scanf statements to read in the first and last names with the %s format.

Get the data above from the terminal, and for each one:

  • get dynamic memory, using malloc, for an employee node
  • put the employee data in the dynamic memory node
  • link the nodes with pointers in the above order

After the list pointers are in place you must get at the second and later instances of the structure by going from the first structure down the chain of list pointers.

Then, for each employee, read in the hours worked from the terminal. Do all appropriate computations, and write out the table.

You do not need an array of structures like you used in homework 6 and 7. Use the template and dynamically allocate linked list nodes as needed. Similar to the previous homework assignment:

a) Add a Total row at the end to sum up the hours, overtime, and gross columns
b) Add an Average row to print out the average of the hours, overtime, and gross columns.

Your code should work for any number of employees, and that is how the template is designed.

Tip: Use left justification to line up character array name values … for example: %-10.10s or %-10s

Remember: Use the Template!

I added comments in bold and purple below that start with TODO to indicate what needs to change.

Relax, its OK if you use this code as is and then expand from it … you have my permission to use all of it. The template can also be found at: http://ideone.com/UJcIrz

#include <stdio.h>
#include <stdlib.h>   /* for malloc */
#include <ctype.h>    /* for toupper */
struct employee
     int id_number;
     float wage;
     /* TODO - Add other members */

     struct employee *next;

/* TODO - Add Function Prototypes as needed */

/* TODO - Add Functions here as needed */

/* Optional TODO - Add Challenge Functions here as needed */

/*                                                                             */
/* FUNCTION:  print_list                                                       */
/*                                                                             */
/* DESCRIPTION:  This function will print the contents of a linked             */
/*               list.  It will traverse the list from beginning to the        */
/*               end, printing the contents at each node.                      */
/*                                                                             */
/* PARAMETERS:   emp1 - pointer to a linked list                               */
/*                                                                             */
/* OUTPUTS:      None                                                          */
/*                                                                             */
/* CALLS:        None                                                          */
/*                                                                             */
void print_list(struct employee *emp1)
        struct employee *tmp;   /* tmp pointer value to current node */
        int i = 0;              /* counts the nodes printed          */
        /* Start a beginning of list and print out each value               */
        /* loop until tmp points to null (remember null is 0 or false)      */
        for(tmp = emp1; tmp ; tmp = tmp->next)

            /* TODO - print other members as well */
            printf("nEmployee ID: %6d, Wage: %8.2fn",tmp->id_number,
        printf("nnTotal Number of Employees = %dn", i);
/*                                                                            */
/* FUNCTION:  main                                                            */
/*                                                                            */
/* DESCRIPTION:  This function will prompt the user for an employee           */
/*               id and wage until the user indicates they are finished.      */
/*               At that point, a list of id and wages will be                */
/*               generated.                                                   */
/*                                                                            */
/* PARAMETERS:   None                                                         */
/*                                                                            */
/* OUTPUTS:      None                                                         */
/*                                                                            */
/* CALLS:        print_list                                                   */
/*                                                                            */
int main ()
    char   answer[80];       /* to see if the user wants to add more employees */
    int    more_data = 1;    /* flag to check if another employee is to be processed */
    char   value;            /* gets the first character of answer */
    struct employee *current_ptr,   /* pointer to current node */
                    *head_ptr;      /* always points to first node */
   /* Set up storage for first node */
    head_ptr = (struct employee *) malloc (sizeof(struct employee));
    current_ptr = head_ptr;
    while (more_data)

        /* TODO - Prompt for Employee Name and Hours as well here */

       /* Read in Employee ID and Hourly Wage */
        printf("nEnter employee ID: ");
        scanf("%i", & current_ptr -> id_number);
        printf("nEnter employee hourly wage: ");
        scanf("%f", & current_ptr -> wage);
        /* TODO - Call Function(s) to calculate Overtime and Gross */
printf("Would you like to add another employee? (y/n): "); scanf("%s", answer);
        /* Ask user if they want to add another employee */
        if ((value = toupper(answer[0])) != 'Y')
           current_ptr->next = (struct employee *) NULL;
           more_data = 0; 
           /* set the next pointer of the current node to point to the new node */
           current_ptr->next = (struct employee *) malloc (sizeof(struct employee));
          /* move the current node pointer to the new node */
           current_ptr = current_ptr->next;
    } /* while */
    /* TODO: Call Function(s) to determine totals and averages */
    /* Optional TODO: Call Challenge Functions to determine min and max values */
    /* print out listing of all employee id's and wages that were entered */
    printf ("nnEnd of programn");
    return (0);
Place your order
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
The price is based on these factors:
Academic level
Number of pages
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more
error: Content is protected !!