HOMEWORK 7
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.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
12 years ago
Purchase the answer to view it
- grosspay.c