research-writing-services
4.8
research-writing-services
4.9
research-writing-services
4.7

HOMEWORK 7 Simple Pointers

HOMEWORK 7SIMPLE POINTERSWrite 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.00Create an array of structures with 5 elements, each being of type struct employeeInitialize 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
#include
/* 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;
}

Related Posts

Quality Writing Features

Price Start $10
  • 24/7 Customer Support
  • All Subject Areas
  • Money-Back Guarantee
  • Timely Delivery
  • Originality report
  • Confidentiality guaranteed

Ordering Homework Writing Service

You can get our ideal online homework help services with four easy steps. All you have to do is inform us of your requirements. Immediately we will match with a specialist in your academic discipline. After that, we will track your order, review it to ensure it meets your requirements, and submit it to your email.

research-writing-services

Submit Requirements

Fill in your assignment instructions on the order form

research-writing-services

Writer match

Immediately you contact us for homework help; we will assign your assignment to an academic expert.

research-writing-services

Quality review

We have a team of editors, who will thoroughly review your assignment, ensuring there are no errors before submission

research-writing-services

Get Your Completed Paper

Once we have completed the assignment, we will deliver it to your account. Additionally, we will send a notification to your email.

ordernow

Affordable

Budget-friendly writing services

ordernow

Privacy

We don’t share our client’s information with a third party

ordernow

Unique

We write every assignment from scratch

Amazing Homework Writing Features

Once you consult us for homework help online services, you will attest to why we are among the USA's best essay writing services.

Read on and find out some of the features that make our services superlative.

Free Homework Writing Services

Free plagiarism checker

You can confirm that the content you get is original for free using our plagiarism checker.

Free samples

We offer unlimited access to our essay homework samples.

Free title page and bibliography

Once you place an order, we format it accordingly without demanding additional charges.

Free unlimited revisions

We offer free unlimited revisions until your assignment is of your desired quality..

Free editing and proofreading

We have a team of specialized editors who review your assignment before submission.

Free customer support

You can track the progress of your homework for free.

Request for Homework Writing Service Today!

We have over 500 homework writing experts, ready and waiting to help you improve your writing skills