Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

*** WRITE CODE IN C LANGUAGE PLEASE *** Problem: Mother Goose Department Store h

ID: 3562992 • Letter: #

Question

*** WRITE CODE IN C LANGUAGE PLEASE ***

Problem: Mother Goose Department Store has decided to hire your software company to build a database for their organization. You have been selected to work on the database project. At the last team meeting, your team lead divided the final design tasks. Your assignment is to read in Employee data and provide methods for querying this information.

Objectives: The objective of this assignment is for students to demonstrate a working knowledge of :

- structs

- linked list operations

In your program you are required to:
1. Create an employeeData struct to represent employees. Your struct should have the following fields:

     -   An integer EMP_ID,      

- name which stores the candidate

Explanation / Answer

#include #include #include #define NAME_LENGTH 20 typedef struct employeeData { int EMP_ID; char* Name; int Dept; int Rank; double Salary; struct employeeData *next; }employee; employee* InitializeList(int EMP_ID, char* Name, int Dept, int Rank, double Salary) { employee* ptr = (employee*)(malloc(sizeof(struct employeeData))); ptr->Name = (char*)malloc(sizeof(char)*NAME_LENGTH); strcpy(ptr->Name, Name); ptr->EMP_ID = EMP_ID; ptr->Dept = Dept; ptr->Rank = Rank; ptr->Salary = Salary; ptr->next = NULL; return ptr; } employee* insert_by_employee(employee* head, employee* ptr) { employee* current = NULL; current = head; if(current == NULL || strcmp(current->Name, ptr->Name) > 0) { ptr->next = current; return ptr; } else { while(current->next != NULL && strcmp(current->next->Name, ptr->Name) < 0) { current = current->next; } } ptr->next = current->next; current->next = ptr; return head; } void query(employee *head, int submenu) { printf(" Emp name "); employee* current; current = head; while (current != NULL) { if(current->Rank == submenu) { printf("%s ", current->Name); current = current->next; } current = current->next; } return; } void printlist(employee* head) { employee* current; current = head; printf("EMP_ID EMP NAME DEPT RANK SALARY "); while ( current != NULL) { printf(" %d %s %d %d %d ", current->EMP_ID, current->Name, current->Dept, current->Rank, current->Salary); current = current->next; } return; } int main(void) { FILE* ifp = fopen("empInfo.txt", "r"); int EMP_ID, Dept, Rank, menu_choice = -1, submenu; double Salary; char* Name = (char*)malloc(sizeof(char*)*NAME_LENGTH); employee *head = NULL; while(!feof(ifp)) { fscanf(ifp, "%d %s %d %d %d", &EMP_ID, Name, &Dept, &Rank, &Salary); { if (EMP_ID == 0) break; } employee* hold = InitializeList(EMP_ID, Name, Dept, Rank, Salary); head = insert_by_employee(head, hold); } while (menu_choice != 0) { printf(" Please select an action from the following menu "); printf("1 to add a new employee "); printf("2 to delete an employee "); printf("3 to modify an employee record "); printf("4 to query employees by rank "); printf("5 to print all employee information "); printf("0 (or any other number) to stop "); scanf("%d", &menu_choice); if(menu_choice == 1) { printf("choice 1 "); menu_choice = -1; } if (menu_choice == 2) { printf("Choice 2 "); menu_choice = -1; } if (menu_choice == 3) { printf("Choice 3 "); menu_choice = -1; } if (menu_choice == 4) { printf("Please provide rank that you would like to query. "); scanf("%d", &submenu); query(head, submenu); menu_choice = -1; } if (menu_choice == 5) { printlist(head); menu_choice = -1; } } fclose(ifp); return 0; }