# HOMEWORK 7 Simple Pointers

Oct 20th, 2014
HelloWorld
Category:
Computer Science
Price: \$5 USD

Question description

# HOMEWORK 7SIMPLE 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.

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

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.

```/************************************************************************/
/*                                                                      */
/*  HOMEWORK:   7                                                       */
/*                                                                      */
/*  Name:   Joe Student                                                 */
/*                                                                      */
/*  Class:  C Programming, Cybercourse                                  */
/*                                                                      */
/*  Date:   6/29/2012                                                   */
/*                                                                      */
/*  Description:  Program which determines gross pay based on overtime  */
/*                and outputs a formatted answer.  Employee information */
/*                is stored in an array of structures and referenced    */
/*                through the use of pointers.                          */
/************************************************************************/

#include <stdio.h>
#include <stdlib.h>
```
```/* define all constants here */
#define STD_HOURS  40.0
#define TIME_HALF  1.5
#define SIZE       5

/* type to hold employee information */
struct employee
{
char name [20];  /* Employee first and last name */
int id;          /* unique employee identifier */
float wage;      /* hourly wage rate */
float hours;     /* hours worked in a given week */
float overtime;  /* hours worked after the standard work week */
float gross;     /* total gross pay, standard pay + overtime pay */
};
/************************************************************************/
/*                      Function: getHours                              */
/*                                                                      */
/*  Purpose:    Obtains the number of hours worked per employee from    */
/*              user and stores the results in an array that is         */
/*              passed back to the calling program by reference.        */
/*                                                                      */
/*  Parameters: emp_ptr - pointer to array of structures                */
/*              size - number of employees to process                   */
/*                                                                      */
/*  Returns:    Nothing, since emp_ptr is passed by reference           */
/************************************************************************/

void getHours ( struct employee * emp_ptr, int size )
{

}

/************************************************************************/
/*                      Function: calcOvertime                          */
/*                                                                      */
/*  Purpose:    Calculates the number of overtime hours given the number*/
/*              of hours worked. Overtime hours are the number of hours */
/*              worked after 40 hrs.                                    */
/*                                                                      */
/*  Parameters: emp_ptr - pointer to array of structures                */
/*              size - number of employees to process                   */
/*                                                                      */
/*  Returns:    Nothing, since emp_ptr is passed by reference           */
/************************************************************************/

void calcOvertime ( struct employee * emp_ptr, int size )
{

}

/************************************************************************/
/*                      Function: calcGrossPay                          */
/*                                                                      */
/*  Purpose:    Calculates gross pay including overtime given the number*/
/*              of hours an employee works and wage rate.               */
/*                                                                      */
/*  Parameters: emp_ptr - pointer to array of structures                */
/*              size - number of employees to process                   */
/*                                                                      */
/*  Returns:    Nothing, since emp_ptr is passed by reference           */
/************************************************************************/

void calcGrossPay ( struct employee * emp_ptr, int size )
{

}

/************************************************************************/
/*                      Function: printTable                            */
/*                                                                      */
/*  Purpose:    Outputs to screen in a table format the following:      */
/*                  - Employee First and Last Name                      */
/*                  - Employee clock number                             */
/*                  - Wage rate for an employee.                        */
/*                  - Total hours worked by employee.                   */
/*                  - Overtime Hours.                                   */
/*                  - Gross Pay.                                        */
/*                                                                      */
/*  Parameters: emp_ptr - pointer to array of structures                */
/*              size - number of employees to process                   */
/*                                                                      */
/*  Returns:    Nothing, since emp_ptr is passed by reference           */
/************************************************************************/

void printTable ( struct employee * emp_ptr, int size )
{
int n;  /* counter used in for loop to keep track of iterations */

/* prints the table header to the screen */
printf ("\n-------------------------------------------------------------------\n");
printf ("  Name               Clock#    Wage      Hours      OT      Gross\n");
printf ("---------------------------------------------------------------------\n");

/* prints the output for all employees to the screen */
for (n = 0; n < SIZE; n++)
{
printf ("%-20.20s %06i   \$%5.2f     %4.1f      %4.1f    \$%7.2f \n",
emp_ptr->name,
emp_ptr->id,
emp_ptr->wage,
emp_ptr->hours,
emp_ptr->overtime,
emp_ptr->gross);

++emp_ptr;  /* move to next employee */
}
printf ("\n");
}
/************************************************************************/
/*                           Function: Main                             */
/************************************************************************/

int main()
{

/* A structure array to hold information on employees */
struct employee emp [SIZE]  =  { {"Connie Cobol", 98401, 10.60},
{"Frank Fortran", 526488, 9.75},
{"Mary Apl", 765349, 10.50},
{"Jeff Ada", 34645, 12.25},
{"Anton Pascal", 127615, 10.0}
};

/* Get user input for the hours worked for each employee */
getHours ( emp, SIZE );

/* Calculate gross pay for each employee */
calcOvertime ( emp, SIZE );

/* Calculate gross pay for each employee */
calcGrossPay ( emp, SIZE );

/* Print results to the screen */
printTable ( emp, SIZE );

return 0;
}
```

(Top Tutor) Daniel C.
(997)
School: Duke University

Studypool has helped 1,244,100 students

## Review from our student for this Answer

Sigchi4life
Oct 23rd, 2014
"Thank you, Thank you, for top quality work, this is your guy!!"

Type your question here (or upload an image)

1829 tutors are online

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors