Question

Create a header file (lastname_employeerec.h) that defines an employee data structure (sEMPLOYEE) that can be linked...

  1. Create a header file (lastname_employeerec.h) that defines an employee data structure (sEMPLOYEE) that can be linked onto a linked list. The data structure should have the following fields:

a. First Name (firstName)

b. Last Name (lastName)

c. Employee ID (id)

d. Start Year (startYear)

e. Starting Salary (startSalary)

f. Current Salary (currentSalary)

g. next

Create a library of functions that operate on this data structure. The source code for the functions should be in lastname_employeerec.c and the function prototypes should be included in lastname_employeerec.h. The following functions should be in the library:

  1. sEMPLOYEE *create_employee_record() – allocates memory for a new employee record, prompts user, through the console, to enter the data for the employee, returns a pointer to the newly created employee record
  2. sEMPLOYEE *add_employee_record(sEMPLOYEE *employeeListHead, sEMPLOYEE *employee) – adds the employee record to a linked list; returns the new list head (it might have changed)
  3. sEMPLOYEE *delete_employee_record(sEMPLOYEE *employeeListHead, unsigned int id) – deletes the employee record with the specified employee ID (can linear search to find record); returns the new list head (it might have changed)
  4. void print_employee_record(sEMPLOYEE *employee) – prints the data in the employee record
  5. sEMPLOYEE *sort_employee_records(sEMPLOYEE *employeeListHead) – sorts the list of employee records according to entire last name; returns the new list head (it might have changed)
  6. int write_employee_records(char *filename, sEMPLOYEE *employeeListHead) – writes the list of employee records to a file; returns 0 on SUCCESS, 1 on FAILURE g. sEMPLOYEE
  7. *read_employee_records(char *filename, sEMPLOYEE *employeeListHead) – reads employee records from a file and adds them to the specified linked list; the new list head (it might have changed)

Add the following functions to your program’s library of functions:

  1. sEMPLOYEE *find_employee_record_by_name(sEMPLOYEE *employeeListHead, char *lastName, char *firstName) – searches for the employee record that matches both queried employee last and first names; returns pointer to record if found, NULL otherwise
  2. sEMPLOYEE *find_employee_record_by_id (sEMPLOYEE *employeeListHead, unsigned int id) – searches for the employee record that matches the queried employee id; returns pointer to record if found, NULL otherwise
  3. int update_employee_record_id(sEMPLOYEE *employeeRecord, unsigned int id) – updates the employee record with the specified employee ID; returns 0 on SUCCESS, 1 on FAILURE

  1. int update_employee_record_current_salary(sEMPLOYEE *employeeRecord, float currentSalary) – updates the employee record with the specified current salary; returns 0 on SUCCESS, 1 on FAILURE
  1. Create an application with source code in lastname_main.c that is an employee record management system:

1 – add a new employee record

2 – delete an employee record

3 – sort employee records by last name

4 – print all employee records

5 – write all employee records to a file

6 – read employee records from a file

7 – search employee records (last & first names)

8 – search employee records (employee id)

9 – update employee record (employee id)

10 – update employee record (current salary)

0 – exit

  1. Create a Makefile to build two versions of your application: a normal version (employee) and a debug version (employee_dbg) that is ready for use in GDB. Your Makefile should be designed so that a source file is compiled only if it has been modified.

In C language please

Homework Answers

Answer #1

#include <stdio.h>
typedef struct EMPLOYEE {
char* firstName;
char* lastName;
unsigned int id ;
int startYear;
double startSalary;
double currentSalary;
struct EMPLOYEE* next;
} sEMPLOYEE;

int showMenu();
void deleteRecord(sEMPLOYEE* rec );
void deleteList(sEMPLOYEE* employeeList );
sEMPLOYEE* create_sEMPLOYEE_record();
sEMPLOYEE* add_sEMPLOYEE_records(sEMPLOYEE* sEMPLOYEEList, sEMPLOYEE* rec);
sEMPLOYEE* delete_sEMPLOYEE_record(sEMPLOYEE* sEMPLOYEEList ,unsigned int ID );
void print_sEMPLOYEE_record(sEMPLOYEE *sEMPLOYEE);
sEMPLOYEE* sort_sEMPLOYEE_records(sEMPLOYEE *sEMPLOYEEList);
int write_sEMPLOYEE_record(char* filename, sEMPLOYEE* sEMPLOYEEList);
sEMPLOYEE* read_employee_record(char* filename, sEMPLOYEE* employeeList );

############# c file ###########
#include "lastname_employee.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int showMenu()
{
printf(" Enter your choice from following : \n");
printf(" 1. add a new employee record.\n");
printf(" 2.delete an employee record.\n");
printf(" 3. sort employee record by last name\n");
printf(" 4. print all employee records.\n");
printf(" 5. Write all employee records to a file.\n");
printf(" 6. read employee records from a file.\n");
printf(" 7. exit .\n");
int ip ;
char c1 ;
scanf("%d%c", &ip , &c1 );
//printf(" GOt - %d \n",ip);
return ip ;
}

sEMPLOYEE* create_sEMPLOYEE_record()
{
char line[1024] ;
char * buf = line ;
size_t len = 50;
size_t x = 0;
  
sEMPLOYEE* nRec = (sEMPLOYEE *) malloc( sizeof(sEMPLOYEE));
  
nRec->next = NULL;
printf("Enter LastName : " );
x = getline( &buf, &len , stdin);
buf[x-1] = 0;
//printf(" Got line %s , len %x , %d \n",buf,len, x);
  
nRec->lastName = (char* ) malloc( sizeof(char) * x );
strncpy(nRec->lastName,buf,x);
  
  
printf("Enter first Name : " );
x = getline( &buf, &len , stdin);
buf[x-1] = 0;
//printf(" Got line %s , len %x , %d \n",buf,len, x);
  
nRec->firstName = (char* ) malloc( sizeof(char) * x );
strncpy(nRec->firstName,buf,x);
  
printf("Enter Employee ID : " );
x = getline( &buf, &len , stdin);
buf[x-1] = 0;
//printf(" Got line %s , len %x , %d \n",buf,len, x);
nRec->id = atoi(buf);
  
  
printf("Enter Start Year : " );
x = getline( &buf, &len , stdin);
buf[x-1] = 0;
//printf(" Got line %s , len %x , %d \n",buf,len, x);
nRec->startYear = atoi(buf);
  
  
printf("Enter Starting Salary : " );
x = getline( &buf, &len , stdin);
buf[x-1] = 0;
//printf(" Got line %s , len %x , %d \n",buf,len, x);
nRec->startSalary = atof(buf);
  
  
printf("Enter current Salary : " );
x = getline( &buf, &len , stdin);
buf[x-1] = 0;
//printf(" Got line %s , len %x , %d \n",buf,len, x);
nRec->currentSalary = atof(buf);
  
return nRec;
}
sEMPLOYEE* add_sEMPLOYEE_records(sEMPLOYEE* employeeList, sEMPLOYEE* rec)
{
if ( employeeList != NULL )
rec->next = employeeList;
  
return rec;
  
}
sEMPLOYEE* delete_sEMPLOYEE_record(sEMPLOYEE* employeeList ,unsigned int ID )
{
sEMPLOYEE* tmpNode = employeeList;
sEMPLOYEE* pNode = NULL;
  
sEMPLOYEE* head = employeeList;
  
while ( tmpNode != NULL )
{
if ( tmpNode->id == ID )
break;
  
pNode = tmpNode;
tmpNode = tmpNode->next;
}
  
// if found tmpNode
if ( tmpNode != NULL )
{
if ( pNode != NULL )
{
pNode->next = tmpNode->next ;
} else
{
// tmpNode is head
head = tmpNode->next ;
}
tmpNode->next = NULL;
  
}
deleteRecord(tmpNode);
return head;
}
void print_sEMPLOYEE_record(sEMPLOYEE * rec)
{
printf(" Employee ID : %d \n" , rec->id);
printf(" Employee last Name : %s \n" , rec->lastName);
printf(" Employee first Name : %s \n" , rec->firstName);
printf(" Employee Start year - %4d \n" , rec->startYear);
printf(" Employee start Salary : %.2f \n" , rec->startSalary);
printf(" Employee current Salary : %.2f \n" , rec->currentSalary);
  
return;
}

sEMPLOYEE* sort_sEMPLOYEE_records(sEMPLOYEE * employeeList)
{
  
sEMPLOYEE* tmpNode = NULL;
sEMPLOYEE* head = employeeList;
sEMPLOYEE* pNode = NULL;
sEMPLOYEE* tmp1Node = NULL;
bool flag = false ;
  
sEMPLOYEE* sortedList = NULL;
  
while ( head != NULL )
{
tmpNode = head ;
head = tmpNode->next ;
  
tmpNode->next = NULL;
  
tmp1Node = sortedList ;
pNode = NULL;
while ( tmp1Node != NULL )
{
  
if ( strcmp( tmpNode->lastName, tmp1Node->lastName) < 0 )
break;
  
pNode = tmp1Node;
tmp1Node = tmp1Node->next;
}
  
if ( tmp1Node != NULL )
{
tmpNode->next = tmp1Node ;
}
if ( pNode != NULL )
{
pNode->next = tmpNode ;
} else {
sortedList = tmpNode ;
}
  
  
  
  
}
  
return sortedList;
}
int write_sEMPLOYEE_record(char* filename, sEMPLOYEE* employeeList)
{
  
FILE * fp = fopen(filename,"w");
if ( fp == NULL ) {
fprintf(stderr," Cannot open file %s \n" , filename );
return -1;
}
  
sEMPLOYEE* tmpNode = employeeList;
  
while (tmpNode != NULL )
{
fprintf(fp,"%s,%s,%d,%4d,%.2f,%.2f\n",
tmpNode->lastName,tmpNode->firstName, tmpNode->id,tmpNode->startYear, tmpNode->startSalary, tmpNode->currentSalary);
tmpNode = tmpNode->next;
}
  
return 0;
}
sEMPLOYEE* read_employee_record(char* filename, sEMPLOYEE* employeeList )
{
  
FILE * fp = fopen(filename,"r");
if ( fp == NULL ) {
fprintf(stderr," Cannot open file %s \n" , filename );
return employeeList;
}
  
char line[1024];
char *buf = line ;
size_t len = 150;
int x = 0 ;
  
  
char *tok ;
char s[2] = ",";
sEMPLOYEE* nNode = NULL;
sEMPLOYEE* nList = employeeList;
while ( getline(&buf , &len, fp) > 0 ) {
  
//printf(" read line - %s \n", buf);
nNode = (sEMPLOYEE*) malloc( sizeof(sEMPLOYEE) );
  
tok = strtok(buf,s );
  
//printf("Got tok %s \n",tok);
if (tok != 0 )
{
x = strlen(tok);
nNode->lastName = (char* ) malloc( sizeof(char) * x );
strncpy(nNode->lastName,tok,x);
}
  
tok = strtok(NULL, s);
  
if (tok != 0 )
{
x = strlen(tok);
nNode->firstName = (char* ) malloc( sizeof(char) * x );
strncpy(nNode->firstName,tok,x);
}
  
  
  
tok = strtok(NULL, s);
if (tok != 0 )
nNode->id = atoi(tok);
  
tok = strtok(NULL, s);
if (tok != 0 )
nNode->startYear = atoi(tok);
  
  
tok = strtok(NULL, s);
if (tok != 0 )
nNode->startSalary = atof(tok);
  
  
tok = strtok(NULL, s);
if (tok != 0 )
nNode->currentSalary = atof(tok);
  
//print_sEMPLOYEE_record(nNode);
nList = add_sEMPLOYEE_records(nList , nNode);
  
}
  
return nList;
  
}
void deleteRecord(sEMPLOYEE* rec )
{
if ( rec != NULL )
{
if ( rec->lastName != NULL)
{
free( rec->lastName );
//printf("Deleting last");
}
if ( rec->firstName != NULL)
{
free( rec->firstName );
//printf("Deleting fist ");
}
//printf("Deleting rec\n");
free(rec);
}
}
void deleteList(sEMPLOYEE* employeeList )
{
sEMPLOYEE* tNode = employeeList;
sEMPLOYEE* pNode = NULL;
while (tNode != NULL )
{
pNode = tNode ;
tNode = tNode->next ;
deleteRecord(pNode);
}
}
int main()
{
sEMPLOYEE* xRec = NULL;
sEMPLOYEE* recordList = NULL;
int input = 0 ;
char filename[25] ;
int id ;
sEMPLOYEE* tmpNode = recordList;
while ( input != 7 )
{
input = showMenu();
  
switch( input) {
  
case 1 :
xRec = create_sEMPLOYEE_record();
recordList = add_sEMPLOYEE_records(recordList,xRec);
break;
case 2 :
printf(" Enter the Employee ID to search :");
scanf("%d" ,& id );
recordList = delete_sEMPLOYEE_record(recordList, id);
break;
case 3:
recordList = sort_sEMPLOYEE_records(recordList);
case 4 :
tmpNode = recordList;
while(tmpNode != NULL)
{
print_sEMPLOYEE_record(tmpNode);
tmpNode = tmpNode->next;
}
break;
case 5 :
printf(" Enter the File to Write :");
scanf("%s" , filename );
write_sEMPLOYEE_record(filename, recordList);
break;
  
case 6 :
printf(" Enter the File to Read :");
scanf("%s" , filename );
recordList = read_employee_record(filename, recordList);
break;
  
case 7 :
break;
  
}
}
  
deleteList(recordList);
}

===========================================================================

Note: Could you please consider my effort on this work and give me a UPVOTE. Thank you :)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
"C language" Take this code and make the minor modification necessary to create a circular linked...
"C language" Take this code and make the minor modification necessary to create a circular linked list (Hint: Store a pointer to the first node in the next pointer of the last node.) Demonstrate that this is working by traversing the list until the first pointer is encountered 3 times. Next redefine the node structure to include a back pointer. This will enable your program to move from front to back and then from back to front. It is not...
I am having some trouble trying to create a linked list from a text file input...
I am having some trouble trying to create a linked list from a text file input from user The three lines respectively represent a long integer ID of a person, the name of the person, and an integer ranging from 0 to 5 indicating the threat level posed by a person. 389114 Paul Bunion 5 399012 John Doe 0 685015 Johnny Appleseed 3 179318 Tom Sawyer 2 284139 Ebenezer Scrooge 5 The full connection is: Paul Bunion -> John Doe...
C++ See the provided specification files. Complete the implementation for each as a separate file. void...
C++ See the provided specification files. Complete the implementation for each as a separate file. void seen(std::string); If there is already a Word object in the Words list, then the number of occurrences for this word is incremented. If there is no Word object for this word already, create a new word object with occurrence =1, and insert this object into the list of Word objects. std::string getNextWord(); Returns the next word of the list and sets the currentItem pointer...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
Objectives:The focus of this assignment is to create and use a recursive method given a moderately...
Objectives:The focus of this assignment is to create and use a recursive method given a moderately difficult problem. Program Description: This project will alter the EmployeeManager to add a search feature, allowing the user to find an Employee by a substring of their name. This will be done by implementing the Rabin-Karp algorithm. A total of seven classes are required. Employee (From previous assignment) HourlyEmployee (From previous assignment) SalaryEmployee (From previous assignment) CommissionEmployee (From previous assignment) EmployeeManager (Altered from previous...
C LANGUAGE IMPLEMENTATION - Writing source files implement several functions, declared in student.h, transcript.h and internal.h...
C LANGUAGE IMPLEMENTATION - Writing source files implement several functions, declared in student.h, transcript.h and internal.h (with support from common.h). There are 3 rules: 1. There are three types of students: undergraduate, MEng and PhD. 2. Undergraduates must complete 40 courses, MEng students 5 and PhD students 2. 3. Undergraduate students require a mark of 50 to pass; graduate students need a 65. ----------------Common.h-------------------------------------------------------------------------------------------------------------------------------------------------------------- #ifndef COMMON_H #define COMMON_H /*Portable macros for declaring C functions visible to C++.*/ #ifdef __cplusplus #define...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions are suggested for easier procedure of making function.) void search_node(struct linked_list* list, int find_node_ value) (The function to make) This function finds the node from the list that value is same with find_node_value and count the order of the node. This function should print message “The order of (node_value) is (order).” and error message “Function search_node : There is no such node to search.”....
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings....
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings. You must base your code on the doubly linked list implementation given in my Week 8 slides. Change the code so that instead of an ‘int’ each node stores a string (choose a suitable size). Each node should also have a next node pointer, and previous node pointer. Then write functions to implement the following linked list operations: • A printList function that prints...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT