Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is a code template to get started: #include #include /* for malloc */ #include struct employee { int id_number; float wage; /* TODO -

image text in transcribed

image text in transcribed

Here is a code template to get started:

#include #include /* for malloc */ #include 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 - 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) { i++;

/* TODO - print other members as well */ printf(" Employee ID: %6d, Wage: %8.2f ",tmp->id_number, tmp->wage); } printf(" Total Number of Employees = %d ", 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(" Enter employee ID: "); scanf("%i", & current_ptr -> id_number); printf(" Enter 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): "); 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; } else { /* 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 */ /* Optional - Call Challenge Functions to determine totals, min, max, and averages */

/* print out listing of all employee id's and wages that were entered */ print_list(head_ptr); printf(" End of program "); return (0); }

Write a C program that will calculate the gross pay of a set of employees. Note that there are two items that will help you with this assignment. 1) Please use the template provide in the Homework 8 folder. Use this template "as is" to jump start your success in completing this homework. It should compile and run right out the box. 2) Watch the videos this week to help you better visualize and understand how the template code works. Also, read through and make sure you understand the concepts in the lecture notes WHAT YOU NEED TO DO: 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 float wage float hours; float overtime; float gross; *use can use long int if you wish 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions