Question: (Please write in C). This lab will focus on the use and manipulation of structures. Each section of the lab should be designed within its
(Please write in C). This lab will focus on the use and manipulation of structures. Each section of the lab should be designed within its own function, passing parameters as necessary. You are to construct a C program,database.c, that will retrieve and manipulate a company's payroll database,payfile.txt. The data for each employee should be read into astructcontaining the following field identifiers: The data for each employee should be read into a struct containing the following field indentifiers: - first: 7 characters maximum - initial: 1 character maximum - last: 9 characters maximum - street: 16 characters maximum - city: 11 characters maximum - state: 2 characters maximum - zip: 5 characters maximum - age: integer - sex: 1 character maximum (M/F) - tenure: integer representing years of employment - salary: double representing weekly salary Your program should perform each of the operations indicated below. Be sure to clearly label your output for each section. *Remember, each section of the lab should be designed within itsownfunction, passing paramaters as necessary. a) Read data for employees into an array of structures. b) Output the contents of each structure into an easily read format, similar to the format of the input file. c) Output out the first and last name of all men on the payroll. d) Output out the first and last name of the highest paid woman on the payroll. e) Output out the first and last name of the lowest paid man on the payroll. f) Output out the average salary for all the employees. g) Output out the first and last name of all women earning less than the average salary. h) Output to three decimal places the ration of the number of men above the average salary to the number of men below the average salary. i) Output out the first and last name of all employees who make more than $35,000 per year, have been with the company for at least 5 years, and who are over 30 years old. j) Give a 10% raise to all employees who make less than $350.00 per week and output the first and last name and new salary for each of the employees who received the raise. k) Sort the structures according to zip codes and output the first and last name and zip code for each of the employees. (Extra Credit) Here is a C function,strsub(), that grabs a substring,sub, from a string,buf, given thestartandendindex within the string. void strsub(char buf[], char sub[], int start, int end) { int i, j; for (j=0, i=start; i<=end; i++, j++) { sub[j] = buf[i]; } sub[j] = '\0'; } This function might be useful when you read a line of data from the file and need to grab the different information from the line of data to place into the fields of the struct. Remember that arrays use zero-base indexing. while (!feof(fp)) { fgets(buf, MAX, fp); strsub(buf, workers[i].first, 0, 6); strsub(buf, workers[i].first, 8, 8); strsub(buf, workers[i].first, 10, 18); . . } You can assume the following declaration: #define MAX 100 The following three functions from the C library,stdlib.handstring.h, might be useful for the lab: atoi ( ) converts a string to an integer atof ( ) converts a string to a float strcmp ( ) compares two strings
The contents of payfile.txt are given below: ADA A AGUSTA 33 BABBAGE ROAD LOVELACE GB 19569 28 F 2 350.50 ISSAC A ASIMOV 99 FICTION WAY AMHERST MA 63948 58 M 6 423.88 HUMPHRY R BOGART 71 SAM STREET HOLLYWOOD CA 48482 56 M 5 366.00 ALBERT G EINSTEIN 94 ENERGY WAY PRINCETON NJ 47474 67 M 8 780.00 EMMYLOU L HARRIS 66 COUNTRY ROAD NASHVILLE TN 72647 38 F 2 767.42 JAMES T KIRK 11 SPACE STREET VULCAN CA 82828 46 M 1 235.70 TED L KOPPEL 55 ABC PLACE WASHINGTON DC 37376 48 M 9 909.44 DAVID T LETTERMAN 14 WNBC AVENUE NEW YORK NY 19338 47 M 5 445.65 STEVIE R NICKS 31 MUSIC ROAD CHICAGO IL 23459 38 F 8 460.88 MONTY P PYTHON 76 SILLY STREET LONDON GB 80939 44 M 2 320.50 ROGER R RABBIT 15 LOONEY TOONS HOLLYWOOD CA 91343 24 M 4 259.53 SALLY W RIDE 21 COLUMBIA WAY HOUSTON TX 91123 30 F 9 707.80 ROD Q SERLING 11 TWLIGHT ZONE SAN DIEGO CA 93939 56 M 1 440.00 LUKE R SKYWALKER 43 MILKY WAY NEW YORK NY 12343 35 M 5 660.00
Remember that themain()function should appear as the first function in the program. Be sure to use function prototypes for each of the functions that are used in your program. Output from your program should be sent to the terminal window (your screen) as well as requestedcsis.txtoutput file.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
