Question: PLEASE HELP C PROGRAM Problem Description : The company XYZ is looking for a system to keep track of each employees wages. Each employees name,

PLEASE HELP C PROGRAM

Problem Description: The company XYZ is looking for a system to keep track of each employees wages. Each employees name, salary and occupation must be stored in a database. The system must also be able to generate a comma separated value (CSV) ?le based on a particular position in the company (i.e. engineer, secretary, painter, etc.) or all salaries above or below any given number (i.e. a list of people that make over/under x dollars/year). XYZ had complications with their previous intern which led to his termination before he could complete the program. As a result, most of the functionality of the employee-list system is still incomplete. They would like to hire EAS240 interns to complete this system in C programming language.

The intern completed the main ?le employee list.c, but, did not have any chance to complete most of the library ?les (the .c and the .h). As a result, the library ?les for the employee list (the list of all the employees and the required information) have not yet been completed. Each student must write their own implementation of the functions described below to complete the program and make it functional. The function prototypes are given, but must be added to libel.h and the corresponding de?nitions in libel.c.

Main ?le (employee list.c): Main function is found in employee list.c and begins by loading the employees that are already saved in a ?le named directory.txt. Loading the employee list is done by calling the function load el(). A state machine is then entered to determine what the user would like to do. Options 1-4 are given: 1 adds a employee, 2 searches all employees by ?rst name, 3 generates a CSV, and 4 saves the changes to the ?le and exits the program. If any other number is entered, the program remains at this menu. A more detailed description of each option is given below.

If the user enters 1, the function add_person() is called, and the program enters a loop. The user is prompted to enter Y or N. If Y is entered, the function is called again. The loop only breaks when N is entered. The program then returns to the main menu.

If the user enters 2, search el() is called. The user is prompted to enter Y or N, if the user enters Y then search el() is called again. The searching continues until the user enters N. The program then returns to the main menu.

If the user enters 3, a prompt is given to enter a string. If the string matches Position then the function gen_csv_pos() is called; if the string matches Salary then gen_csv_sal() is called. If any other string is entered, the user is reminded of the options and prompted again. After one of the functions is called, the program returns to the main menu.

If the user enters 4, the program breaks out of the state machine, saves the employee list (by calling save el()), and exits the program. Note that the employee list is only saved if the user enters 4, NOT if the user presses ctrl+c.

Note: The main function is given in employee list.c. The above is an explanation of main function. The employee list.c ?le should not be edited.

Structures: The system uses two structures. The ?rst structure holds information about each employee. This structure is to be named personal _info. personal_info is to have 3 character arrays (of length MAXLEN de?ned in libel.h) to hold the employees ?rst name, last name, position. The structure must also hold a double for the salary. In the line directly below the structure, add the following line: typedef struct personal info pi; This line literally renames struct personal_info to pi. This means that create a new instance of this structure, pi newpi; may be written instead of struct personal_info newpi; (it saves quite a bit of typing).

The second structure is a list of all the employees. It contains an array of personal_info structures, and an integer to store the current number of people in the employee list. Name this structure employee_list. The maximum number of people in the array is MAXPPL, which is also de?ned in libel.h. Use typedef struct employee list el; for this structure. Both structures must be declared ONLY in libel.h Hint: MAXLEN is already de?ned to be 25, and may be found in libel.h. To make an array of length MAXLEN, use: array[MAXLEN]; same with MAXPPL.

Functions:

1: Write a function to load a employee list from a ?le. A sample ?le may be seen in the supplemental materials directory.txt. This function must take a pointer to a employee_list, and a const char * string (which is the ?lename). The ?rst element in directory.txt is an integer - the number of people in the list. In this function, create a loop that initializes a employee list to the elements of a ?le (directory.txt). Use the prototype below: void load el(el * emp list, const char * filename);

After all the employees have been loaded from the ?le, print ''%d employees loaded. '', where %d is the number of employees loaded.

Hint: fscanf(fp, "%s %s %s %lf",...); will read in a users ?rst name, last name, occupation, and salary from the ?le pointer fp. You may want to put this fscanf in a loop to load each employee in the ?le. You must still decide where to store the scanned variables (replace the ...). 2: Write a function to add an employee personal_info (pi) to the employee list (el) using the prototype below: void add person(el * emp list, pi person); Add this prototype to libel.h and the de?nition to libel.c. Read the employee list.c carefully. The employee_list.c prompts the user to enter the information. After the new employee information is entered, the program will call the function add_person() and pass this information to the function. In your function de?nition you need to add this new employee to the employee_list.

3: Write a second function using the prototype below to search the employee list for a ?rst name. void search el(el emp list, char find name[ ]); Read the employee_list.c carefully. The employee _list.c prompts the user to enter a name to search for, and then it will pass this name to the function search_el. In your function de?nition you need to search for all the employees that match the searched ?rst name and print full information of each employee that has the same ?st name with the format seen in the provided executable ?le.

Hint: To compare two strings, include the string.h library in your libel.c and use the function strcmp(char *, char *); no linker ?ags are needed for this library. strcmp() returns 0 (or false) if the strings are the same. You can use !strcmp() to return true if they are the same. If there is no employee found, print 'No entries with that name. '.

4: Write a function by using the prototype below to save the employee list in the same manner as directory.txt. void save el(el * emp list, const char * filename); This can be done by replacing fscanf with fprintf in the load_el function. Keep in mind each ?eld of the personal info structure must be on its own line. So the fscanf mentioned in the hint above must be modi?ed (replace the spaces with linefeeds where necessary).

5: Complete the function gen_csv sal in libel.c by ?lling in the statements in the while loop. The ?rst if (in the while loop) should check if the variable (string) ml is equal to less. If the strings are equal, then generate a Comma Separated Variable (CSV) ?le of all the people in the employee list with a salary LESS than sal.

The second (else if) statement should check if the string ml is equal to more. If this is true, generate a CSV of all the people in the employee list with a salary MORE than sal. Populate the ?le using the ?le pointer fp and by using fprintf. Consider changing the fprintf line from that function to seperate elements by commas instead of linefeeds. Also note that there is a linefeed after each employee.

6: Complete the function gen_csv pos by adding the missing code. This function generates a CSV based on occupation. The code should compare pos to the company position (occupation) of each employee in the list. If the occupation is the occupation we are searching for, write it to the CSV with the ?le pointer fp.

Note: Any function that opens a ?le, should also close that ?le (using fclose(fp)) before the function returns. Final Steps: Now that the system is implemented, test it by generating a CSV of all the employees (this can be done by using all employees with salary greater than 0), a second CSV for all engineers, and a third CSV for salaries over $100k. Open the CSVs in Microsoft Excel or LibreO?ce Calc (in Linux). Calculate the average wages for all employees and all engineers (compare the these two numbers, are engineers of this company earning more than average?!). Also calculate the standard deviation of wages (for all employees). List and comment on your ?ndings and results In a Word or LibreO?ce Writer ?le. This ?le should be printed to a PDF named Report.pdf and submitted in the tarball with the code.

GIVEN FILES:

directory

9 Kelly Schmitt Engineer 100000.000000 Kristina Thompson Secretary 67500.000000 Bob Ross Painter 80000.000000 Shana Bryd Engineer 90000.000000 Kelly Juan Teacher 70000.000000 Sam Smith Singer 4000000.000000 Paul Leach CEO 7000000.000000 Geneva Olivares Engineer 200000.000000 Jamila Thong Engineer 150000.000000

LIBEL.H

#ifndef _LIBCL_H_ #define _LIBCL_H_ #define MAXPPL 500 #define MAXLEN 25

//ADD STRUCTURE(S) HERE

//ADD PROTOTYPES HERE

void gen_csv_sal(el * emp_list); void gen_csv_pos(el * emp_list); char * gen_file_name(char * filename, int filename_size, char * suffix, int suffix_size); #endif

LIBEL.C

#include "libel.h" #include #include #include

//ADD FUNCTION DEFINITIONS FOR LOAD_EL, SAVE_EL, ADD_PERSON, AND SERACH_EL HERE

//ADD FUNCTIONALITY TO THE BELOW FUNCTIONS

void gen_csv_sal(el * emp_list){ char csv_prefix[14] = "csv_list_sal"; char csv_suffix[5] = ".csv"; char * filename = gen_file_name(csv_prefix, 14, csv_suffix, 5); FILE * fp = fopen(filename, "w"); int search = -1; double sal; char ml[5];

while(search == -1) { printf("Search for salaries (format: 65000.00 less or 100000 more): "); scanf("%lf %s", &sal, ml); if(/*if 'ml' is "less"*/) {

//ADD CODE HERE TO PRINT TO THE CSV FILE AND SCREEN

search = 0; } else if(/*if 'ml' is "more"*/) {

//AD CODE HERE TO PRINT TO THE CSV FILE AND SCREEN

search = 0; } else printf("Must type more or less "); }

fclose(fp); printf("CSV generated: %s ", filename); return; }

//ADD FUNCTIONALITY TO THE BELOW FUNCTION

void gen_csv_pos(el * emp_list){ char csv_prefix[14] = "csv_list_pos"; char csv_suffix[5] = ".csv"; char * filename = gen_file_name(csv_prefix, 14, csv_suffix, 5); FILE * fp = fopen(filename, "w"); char pos[25]; printf("Enter company position to search for: "); scanf("%s", pos); //ADD CODE HERE TO PRINT TO THE CSV FILE AND SCREEN

fclose(fp); printf("CSV generated: %s ", filename); return; }

char * gen_file_name(char * filename, int filename_size, char * suffix, int suffix_size){ char file_num[3]; int max_file_num = 99, i; char * new_filename = (char *) malloc((filename_size + suffix_size + 2) * sizeof(char)); for(i = 0;i <= max_file_num; i++){ strcpy(new_filename, filename); sprintf(file_num, "%d", i); strcat(new_filename, file_num); strcat(new_filename, suffix); if (fopen(new_filename, "r") ==NULL) {//if the filename doesnt exsist //fp = fopen(new_filename, "w"); break; } } // printf("File name generated: %s ", new_filename); return new_filename; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!