Question
Purpose : To perform basic operations on linked list structures using C Language Due date : For Gr1 : 18/1/2022, For Gr2 : 19/1/2022 Definition
Purpose : To perform basic operations on linked list structures using C Language
Due date : For Gr1 : 18/1/2022,
For Gr2 : 19/1/2022
Definition of the Problem :Using linked list data structure, do the following basic operations
Prepare the necessary functions to create three linked list structures using a data file(employee.txt) and do the following main operations.
Insertion, Sorting, Searching, Deletion , and Traversing(Listing)
employee.txt file contains the following fields and data in it.
EmpNumber Name Worked Hours Hourly Salary
Each record consists of following fields:
Employee Number
Employee Name
Employee Worked Hours in a month
Employee Hourly Salary
You may define the structure as follows.
#include
struct employeeInfo
{
int empNr;
char name[15];
float workHours;
float hourlySalary;
float monthlySalary;/* will be calculated by workHours x hourlySalary */
};
Steps of operation will be done in the following order of steps.
- (20 points)Read data file(employee.txt) and create a linked list structure which is given below(During this step monthly salary will be calculated).(Solution already given below) . Head node of that linked list will be head1.
struct node
{
struct employeeInfo info;
struct node *link;
};
typedef struct node *NODEPTR;
NODEPTR head1, headNum, headNam;
- (25 Points) Create two additional sorted linked list structures using linked list structure which has a head node head1
- First linked list will be sorted based on name and head node will be headNam.
- Second linked list will be sorted based on empNr and head node will be headNum as shown in the figure below.
head1
headNam
headNum
- (5 points) Search a given employee(read employee number from the monitor) and list his node fields using third linked list starting with a head node headNum. Give error message if given employee number is not found.
- (5 points) Search a given employee(read employee name from the monitor) and list his node fields using second linked list starting with a head node headNam. Give error message if given employee name is not found.
- (15 Points)Insert a new employee(read employee information using the monitor) into the second and third linked list structure with the head nodes headNum, headNam.
- (15 points)Delete an employee(read employee number from the monitor) from both linked list structures. Search and find and delete from the second and third linked list structure starting the head nodes headNum, headNam.
To create linked list structure(Step1), you may use the following code, and complete the rest of the program.
#include
#include
#include
#define NULL 0
struct employeeInfo
{
int empNr;
char name[15];
float workHours;
float hourlySalary;
float monthlySalary;/* will be calculated by workHours x hourlySalary */
};
struct node
{
struct employeeInfo info;
struct node *link;
};
typedef struct node *NODEPTR;
NODEPTR getnode(void);
void readFileIntoLinkList(NODEPTR *);
void list1(NODEPTR);
void menu();
int main()
{
NODEPTR head1, headNum, headNam;
int choice;
/* Step1 will be done using these two functions
head1 = NULL;
readFileIntoLinkList(&head1);
list1(head1);
do{
menu();
scanf("%d",&choice);
switch(choice)
{ // complete each section calling necessary function that you coded
case 1:{. . . . . . . . . . . . . . . . . . . . . . . . . break;}
case 2:{. . . . . . . . . . . . . . . . . . . . . . . . . .break;}
case 3:{. . . . . . . . . . . . . . . . . . . . . . . . . break;}
case 4:{. . . . . . . . . . . . . . . . . . . . . . . . . .break;}
case 5:{. . . . . . . . . . . . . . . . . . . . . . . . . break;}
case 6:{. . . . . . . . . . . . . . . . . . . . . . . . . ;}
}
}while(choice!=7);
return 0;
} // end of main program
void readFileIntoLinkList(NODEPTR *head)
{
NODEPTR p, save ;
struct employeeInfo temp;
FILE *empFile;
empFile = fopen("C:\\assgn2Solution\\employee.txt" , "r");
while ( !feof(empFile))
{
fscanf(empFile ,"%d %s %f %f" ,&temp.empNr,temp.name,&temp.workHours,&temp.hourlySalary);
temp.monthlySalary = temp.hourlySalary*temp.workHours;
p = getnode();
p->info = temp;
if (*head == NULL)
{
*head = p;
save = p;
}
else{
save->link = p;
save = p;
}
}
p->link=NULL;
fclose(empFile);
}
void menu()
{
printf(" *********MAIN MENU********** ");
printf("1.Create Sorted Link list using Names and List ");
printf("2.Create Sorted Link list using Employee Number and List ");
printf("3.Search with an employee Number ");
printf("4.Search with an Employee Name ");
printf("5.Insert a New Employee information ");
printf("6.Delete an Employee from both of the link list structure ");
printf("7.Exit ");
}
void list1(NODEPTR head)
{
NODEPTR save;
save = head;
while(save!=NULL)
{
printf("%d %s %f %f %f ",save->info.empNr,save->info.name,save->info.hourlySalary, save->info.workHours,save->info.monthlySalary);
save = save->link;
}
}
NODEPTR getnode()
{
NODEPTR q;
q = (NODEPTR) malloc(sizeof(struct node));
return(q);
}
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