Question
Need to modify the LIB.C and LIB.H files to match the expected output. MAIN.C was provided. C programming not C++ MAIN.C #include #include #include libel.h
Need to modify the LIB.C and LIB.H files to match the expected output. MAIN.C was provided. C programming not C++
MAIN.C
#include
int main () { const char * filename = "directory.txt"; char * csv_prefix = "csv_list"; char find_name[25]; pi person; el emp_list; emp_list.num_people = 0; load_el(&emp_list, filename); printf("%d employees loaded. ", emp_list.num_people); char cont = 'x', //initialize continue to something other than 'Y' or 'N' tmp; // int state = -1, correct_search_val; char srch_critera[25] = "init"; while (state != 4){ while(state 4){ printf("1:\tAdd employee and salary "); printf("2:\tSearch directory by first name "); printf("3:\tGenerate CSV "); printf("4:\tSave and exit program "); printf("Enter an option (1-4): "); scanf("%d", &state); if(state 4) { printf(" Error: number not in range "); } }
switch(state) {
//add employee and salary case 1: //add one person printf("Enter a first name: "); scanf("%s", person.first); printf("Enter %s's last name: ", person.first); scanf("%s", person.last); printf("Enter %s's occupation: ", person.first); scanf("%s", person.position); printf("Enter %s's Salary: ", person.first); scanf("%lf", &person.salary); scanf("%c", &tmp); printf("Employee added. "); add_person(&emp_list, person); //determine to add more people to the employee list while(cont != 'N' && emp_list.num_people
//search directory by first name case 2:
cont = 'x'; //reset continue to neither 'Y' nor 'N' while(cont != 'N'){ cont = 'x'; printf("Enter a person's name to search for: "); scanf("%s", find_name); scanf("%c", &tmp); search_el(emp_list, find_name); while(cont != 'Y' && cont != 'N'){ printf(" Continue (Y/N)? "); scanf("%c", &cont); fflush(stdout); //, &tmp); scanf("%c", &tmp); if (cont != 'Y' && cont != 'N') { printf("Error: User entered '%c'. Must enter either 'Y' or 'N'. ", cont); }
} } printf(" Returning to main menu... "); state = -1; break;
//generate CSV file case 3: correct_search_val = -1; while(correct_search_val != 0) { printf("Generate CSV based on? (\"Salary\", \"Position\"): "); scanf("%s", srch_critera); if(!strcmp(srch_critera, "Salary")){ printf("Generating CSV based on salary... "); gen_csv_sal(&emp_list); correct_search_val = 0; } else if(!strcmp(srch_critera, "Position")){ printf("Generating CSV based on position... "); gen_csv_pos(&emp_list); correct_search_val = 0; } else printf("Options are: \"Salary\", \"Position\" "); } printf("Returning to main menu... "); state = -1;
case 4: break; }//end switch }//end while
//save the employee list save_el(&emp_list, filename); printf("%d employees saved. ", emp_list.num_people); return 0; }//end main
LIB.H
#ifndef _LIBCL_H_ #define _LIBCL_H_ #define MAXPPL 500 #define MAXLEN 25
//ADD STRUCTURE(S) HERE:
struct personal_info {
char first[MAXLEN];
char last[MAXLEN];
char position[MAXLEN];
double salary[];
};
typedef struct personal_info pi;
struct employee_list {
struct personal_info person[MAXPPL];
int num_people;
};
typedef struct employee_list el;
//ADD PROTOTYPES HERE:
void load_el(el * emp list, const char * filename); void add_person(el * emp list, pi person); void search_el(el emp list, char find name[ ]); void save_el(el * emp list, const char * filename);
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
LIB.C
#include "libcl.h" #include
//ADD FUNCTION DEFINITIONS FOR LOAD_EL, SAVE_EL, ADD_PERSON, AND SEARCH_EL HERE
void load_el(el * emp list, const char * filename); {
void add_person(el * emp list, pi person); {
void search_el(el emp list, char find name[ ]); {
void save_el(el * emp list, const char * filename); {
//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"*/) {
//ADD 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
EXPECTED OUTPUT:
2: 4: 10 employees loaded. Add employee and salary Search directory by first name Generate CSV Save and exit program Enter an option (1-4): 1 Enter a first name: Mary Enter Mary's last name: Sue Enter Mary's occupation: Engineer Enter Mary's Salary: 70000 Employee added. Would you like to enter another name (Y/N): N Returning to main menu... 1: Add employee and salary Search directory by first name 3: Generate CSV Save and exit program Enter an option (1-4): 2 Enter a person's name to search for: Mary 4: Name: Mary Sue (Engineer) Salary: 70000.00 Continue (Y/N) ? N Returning to main menu... 3: 1: Add employee and salary Search directory by first name Generate CSV 4: Save and exit program Enter an option (1-4): 3 Generate CSV based on? ("Salary", "Position") : Salary Generating CSV based on salary... Search for salaries (format: 65000.00 less or 100000 more): 60000 more Wrote: Kelly, Schmitt, Engineer, 100000.000000 Wrote: Kristina, Thompson, Secretary,67500.000000 Wrote: Bob, Ross, Painter, 80000.000000 Wrote: Shana, Bryd, Engineer, 90000.000000 Wrote: Kelly, Juan, Teacher, 70000.000000 Wrote: Sam, Smith, Singer, 4000000.000000 Wrote: Paul, Leach, CEO, 7000000.000000 Wrote: Geneva, Olivares, Engineer, 200000.000000 Wrote: Jamila, Thong, Engineer, 150000.000000 Wrote: Mary, Sue, Engineer, 70000.000000 CSV generated: Csv list sall.csv Returning to main menu... 3: 1: Add employee and salary Search directory by first name Generate CSV 4: Save and exit program Enter an option (1-4): 4 11 employees saved. 2: 4: 10 employees loaded. Add employee and salary Search directory by first name Generate CSV Save and exit program Enter an option (1-4): 1 Enter a first name: Mary Enter Mary's last name: Sue Enter Mary's occupation: Engineer Enter Mary's Salary: 70000 Employee added. Would you like to enter another name (Y/N): N Returning to main menu... 1: Add employee and salary Search directory by first name 3: Generate CSV Save and exit program Enter an option (1-4): 2 Enter a person's name to search for: Mary 4: Name: Mary Sue (Engineer) Salary: 70000.00 Continue (Y/N) ? N Returning to main menu... 3: 1: Add employee and salary Search directory by first name Generate CSV 4: Save and exit program Enter an option (1-4): 3 Generate CSV based on? ("Salary", "Position") : Salary Generating CSV based on salary... Search for salaries (format: 65000.00 less or 100000 more): 60000 more Wrote: Kelly, Schmitt, Engineer, 100000.000000 Wrote: Kristina, Thompson, Secretary,67500.000000 Wrote: Bob, Ross, Painter, 80000.000000 Wrote: Shana, Bryd, Engineer, 90000.000000 Wrote: Kelly, Juan, Teacher, 70000.000000 Wrote: Sam, Smith, Singer, 4000000.000000 Wrote: Paul, Leach, CEO, 7000000.000000 Wrote: Geneva, Olivares, Engineer, 200000.000000 Wrote: Jamila, Thong, Engineer, 150000.000000 Wrote: Mary, Sue, Engineer, 70000.000000 CSV generated: Csv list sall.csv Returning to main menu... 3: 1: Add employee and salary Search directory by first name Generate CSV 4: Save and exit program Enter an option (1-4): 4 11 employees saved
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started