Question: Program c: Use a dynamically allocated linked list, each node in the list is an employee struct and should be dynamically allocated You are a
Program c: Use a dynamically allocated linked list, each node in the list is an employee struct and should be dynamically allocated
You are a business owner and you keep information on your employees stored in a text file. Each line contains the name of an employee, their employee id, the number of hours they worked during this pay period, and the hourly rate at which they are paid.
For each employee, calculates the net income and taxes withheld, storing it in their corresponding struct within the array
For each employee, writes the employee name, id, net income, and taxes withheld to the output file using fprintf
You will also implement an Employee Bonus feature which will allow you to choose one employee to give a bonus too. The employee name and the bonus amount to give should be entered as command line arguments. The bonus amount should be added directly to their calculated net income.If you enter an employee name which does not exist, no one gets the bonus.
An example execution of the program: programName employees.txt payday.txt rippetoe 100.00
Details:
1.You must implement the following new functions
a)append: add an employee struct to the linked list
i.Allocate memory for the employee
ii.If the list is empty,append should return a pointer to the newly allocated employee struct
iii.add the employee to the end of the list and return a pointer to the first item in the list
b)search: find an employee by name and return a pointer to their struct If an employee with the given name doesnt exist return NULL.
c)clearList:Deallocates all employee structs in the linked list passed in. This functions should be called when the user exists the program,so that all the memory allocated for the linked list is freed.
2.These new linked list related functions should be implemented in linkedList.c and declared in linkedList.h
3.ClearList should be called at the end of the program to deallocated all memory used by the linked list
4.You must make a makefile
--------------------------------------------------------------------------------------------------------------------------------
employee.c
#include #include "employee.h" #include "linkedList.h"
struct employee* buildEmployeeList(char* filename) { //Scan each line of file "filename" using fscanf and create a struct //containing the data that you get back. You should initialize the //other members which you did not get data for (netIncome, taxesWitheld, next pointer) //to some known value. It would be wise to set 'next' to NULL! }
void writeSalaryInfoToFile(struct employee* listHead, char* filename) {
}
--------------------------------------------------------------------------------------------------------------------------------
employee.h
#ifndef EMPLOYEE_H #define EMPLOYEE_H
#define MAX_NAME_LEN 15 #define MAX_NUM_EMPLOYEES 10
/*PUT YOUR STRUCT DEFINITION HERE*/
struct employee* buildEmployeeList(char* filename); void writeSalaryInfoToFile(struct employee* listHead, char* filename);
#endif //EMPLOYEE_H
--------------------------------------------------------------------------------------------------------------------------------
employeePayroll.c
#include #include "employee.h" #include "linkedList.h"
#define TAX_RATE 0.15f #define FULL_TIME 40 #define OVERTIME_RATE_MULTIPLIER 1.5f
void getSalaryInfo(struct employee* emp);
int main(int argc, char* argv[]) {
}
void getSalaryInfo(struct employee* emp) {
}
--------------------------------------------------------------------------------------------------------------------------------
linkedList.c
#include #include "linkedList.h" #include "employee.h"
//Add the struct 'emp' to the end of the linked list pointed to //by 'listHead' (the first node in the list) //return a pointer to the first node in the list (listHead) struct employee* append(struct employee* listHead, struct employee emp) {
}
//Search for an employee in the list who has the name 'name' //if found, return a pointer to the employee struct //otherwise return NULL struct employee* search(struct employee* listHead, char* name) {
}
//delete all nodes in the list. This means freeing memory void clearList(struct employee* listHead) {
}
-------------------------------------------------------------------------------------------------------------------------------
linkedList.h
#ifndef LINKED_LIST_H #define LINKED_LIST_H
struct employee* append(struct employee* listHead, struct employee emp); struct employee* search(struct employee* listHead, char* name); void clearList(struct employee* listHead);
#endif //LINKED_LIST_H
--------------------------------------------------------------------------------------------------------------------------------
employees.txt
rippetoe 324 23 12.50 walton 435 5 1000.00 billerson 235 45 13.23 cratchit 123 60 5.00
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
