HOMEWORK 7 Simple Pointers

HOMEWORK 7 Simple Pointers

HOMEWORK 7
SIMPLE POINTERS

Write a C program that will calculate the gross pay of a set of employees.  Declare an array of structures to hold your employees as well as a pointer to it.  Do not use any array references with indexes.

  emp[i].wage  /* this is bad, it uses an array reference with an index, in this case, i */

  emp_ptr->wage;  /* this is good, it uses a pointer to reference the wage value */

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.

    ---------------------------------------------------------_x000D_
    Name            Clock#   Wage   Hours     OT     Gross_x000D_
    ---------------------------------------------------------_x000D_
    Connie Cobol    098401   10.60   51.0    11.0    598.90_x000D_
    Mary Apl        526488    9.75   42.5     2.5    426.56_x000D_
    Frank Fortran   765349   10.50   37.0     0.0    388.50_x000D_
    Jeff Ada        034645   12.25   45.0     5.0    581.88_x000D_
    Anton Pascal    127615   10.00   40.0     0.0    400.00_x000D_
    ---------------------------------------------------------

You should implement this program using a structure similar to the suggested one below to store the information for each employee.  Feel free to tweak it if you wish.  For example, its OK to have a first and last name member instead of just a name member, and if you want to use different types (such as long or double), that is OK as well.

  struct employee
  {
  char  name [20];
  int  id;
  float wage;
  float hours;
  float overtime;
  float gross;
  };Use the following information to initialize your data.

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

Create an array of structures with 5 elements, each being of type struct employee

Initialize the array with the data provided.

Set a pointer to it and then use that pointer going forward to access elements (and their associated members) in your array of structures.  Again, do not use array references with indexes.

Challenge:  If you wish, optionally add code needed to generate a total and average of the hour, overtime, and gross pay values, just like you did in the previous homework.

Here is a template to use for homework 7.  If you want to deviate from it, that is fine, as long as you follow the rules mentioned above.  The template will compile and start printing values right out of the box.  It is your job to fill in the missing code and provide input so that it displays the correct information.

/************************************************************************/_x000D_
/*                                                                      */_x000D_
/*  HOMEWORK:   7                                                       */_x000D_
/*                                                                      */_x000D_
/*  Name:   Joe Student                                                 */_x000D_
/*                                                                      */_x000D_
/*  Class:  C Programming, Cybercourse                                  */_x000D_
/*                                                                      */_x000D_
/*  Date:   6/29/2012                                                   */_x000D_
/*                                                                      */_x000D_
/*  Description:  Program which determines gross pay based on overtime  */_x000D_
/*                and outputs a formatted answer.  Employee information */_x000D_
/*                is stored in an array of structures and referenced    */_x000D_
/*                through the use of pointers.                          */_x000D_
/************************************************************************/_x000D_
_x000D_
#include <stdio.h>_x000D_
#include <stdlib.h>_x000D_
/* define all constants here */_x000D_
#define STD_HOURS  40.0_x000D_
#define TIME_HALF  1.5_x000D_
#define SIZE       5_x000D_
_x000D_
/* type to hold employee information */_x000D_
struct employee_x000D_
{_x000D_
     char name [20];  /* Employee first and last name */_x000D_
     int id;          /* unique employee identifier */_x000D_
     float wage;      /* hourly wage rate */_x000D_
     float hours;     /* hours worked in a given week */_x000D_
     float overtime;  /* hours worked after the standard work week */_x000D_
     float gross;     /* total gross pay, standard pay + overtime pay */_x000D_
};_x000D_
    /************************************************************************/_x000D_
    /*                      Function: getHours                              */_x000D_
    /*                                                                      */_x000D_
    /*  Purpose:    Obtains the number of hours worked per employee from    */_x000D_
    /*              user and stores the results in an array that is         */_x000D_
    /*              passed back to the calling program by reference.        */_x000D_
    /*                                                                      */_x000D_
    /*  Parameters: emp_ptr - pointer to array of structures                */_x000D_
    /*              size - number of employees to process                   */_x000D_
    /*                                                                      */_x000D_
    /*  Returns:    Nothing, since emp_ptr is passed by reference           */_x000D_
    /************************************************************************/_x000D_
_x000D_
void getHours ( struct employee * emp_ptr, int size )_x000D_
{_x000D_
_x000D_
}_x000D_
_x000D_
    /************************************************************************/_x000D_
    /*                      Function: calcOvertime                          */_x000D_
    /*                                                                      */_x000D_
    /*  Purpose:    Calculates the number of overtime hours given the number*/_x000D_
    /*              of hours worked. Overtime hours are the number of hours */_x000D_
    /*              worked after 40 hrs.                                    */_x000D_
    /*                                                                      */_x000D_
    /*  Parameters: emp_ptr - pointer to array of structures                */_x000D_
    /*              size - number of employees to process                   */_x000D_
    /*                                                                      */_x000D_
    /*  Returns:    Nothing, since emp_ptr is passed by reference           */_x000D_
    /************************************************************************/_x000D_
_x000D_
void calcOvertime ( struct employee * emp_ptr, int size )_x000D_
{_x000D_
_x000D_
}_x000D_
_x000D_
    /************************************************************************/_x000D_
    /*                      Function: calcGrossPay                          */_x000D_
    /*                                                                      */_x000D_
    /*  Purpose:    Calculates gross pay including overtime given the number*/_x000D_
    /*              of hours an employee works and wage rate.               */_x000D_
    /*                                                                      */_x000D_
    /*  Parameters: emp_ptr - pointer to array of structures                */_x000D_
    /*              size - number of employees to process                   */_x000D_
    /*                                                                      */_x000D_
    /*  Returns:    Nothing, since emp_ptr is passed by reference           */_x000D_
    /************************************************************************/_x000D_
_x000D_
void calcGrossPay ( struct employee * emp_ptr, int size )_x000D_
{_x000D_
_x000D_
}_x000D_
_x000D_
    /************************************************************************/_x000D_
    /*                      Function: printTable                            */_x000D_
    /*                                                                      */_x000D_
    /*  Purpose:    Outputs to screen in a table format the following:      */_x000D_
    /*                  - Employee First and Last Name                      */_x000D_
    /*                  - Employee clock number                             */_x000D_
    /*                  - Wage rate for an employee.                        */_x000D_
    /*                  - Total hours worked by employee.                   */_x000D_
    /*                  - Overtime Hours.                                   */_x000D_
    /*                  - Gross Pay.                                        */_x000D_
    /*                                                                      */_x000D_
    /*  Parameters: emp_ptr - pointer to array of structures                */_x000D_
    /*              size - number of employees to process                   */_x000D_
    /*                                                                      */_x000D_
    /*  Returns:    Nothing, since emp_ptr is passed by reference           */_x000D_
    /************************************************************************/_x000D_
_x000D_
void printTable ( struct employee * emp_ptr, int size )_x000D_
{_x000D_
    int n;  /* counter used in for loop to keep track of iterations */_x000D_
_x000D_
    /* prints the table header to the screen */_x000D_
    printf ("n-------------------------------------------------------------------n");_x000D_
    printf ("  Name               Clock#    Wage      Hours      OT      Grossn");_x000D_
    printf ("---------------------------------------------------------------------n");_x000D_
_x000D_
    /* prints the output for all employees to the screen */_x000D_
    for (n = 0; n < SIZE; n++)_x000D_
    {_x000D_
        printf ("%-20.20s %06i   $%5.2f     %4.1f      %4.1f    $%7.2f n", _x000D_
                emp_ptr->name,_x000D_
                emp_ptr->id, _x000D_
                emp_ptr->wage, _x000D_
                emp_ptr->hours, _x000D_
                emp_ptr->overtime, _x000D_
                emp_ptr->gross);_x000D_
_x000D_
        ++emp_ptr;  /* move to next employee */_x000D_
    }_x000D_
    printf ("n");_x000D_
}_x000D_
    /************************************************************************/_x000D_
    /*                           Function: Main                             */_x000D_
    /************************************************************************/_x000D_
_x000D_
int main()_x000D_
{_x000D_
_x000D_
    /* A structure array to hold information on employees */_x000D_
    struct employee emp [SIZE]  =  { {"Connie Cobol", 98401, 10.60},_x000D_
                                     {"Frank Fortran", 526488, 9.75},_x000D_
                                     {"Mary Apl", 765349, 10.50},_x000D_
                                     {"Jeff Ada", 34645, 12.25},_x000D_
                                     {"Anton Pascal", 127615, 10.0}_x000D_
                                   };_x000D_
  _x000D_
    /* Get user input for the hours worked for each employee */_x000D_
    getHours ( emp, SIZE );_x000D_
_x000D_
    /* Calculate gross pay for each employee */_x000D_
    calcOvertime ( emp, SIZE );_x000D_
_x000D_
    /* Calculate gross pay for each employee */_x000D_
    calcGrossPay ( emp, SIZE );_x000D_
_x000D_
    /* Print results to the screen */_x000D_
    printTable ( emp, SIZE );_x000D_
_x000D_
    return 0;_x000D_
}_x000D_

"You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.


Discount Code: CIPD30



Click ORDER NOW..

order custom paper