Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

  1. (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;

  1. (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

  1. (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.
  2. (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.
  3. (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.
  4. (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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 1 Lnai 9284

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Carlos Soares ,Joao Gama ,Alipio Jorge

1st Edition

3319235273, 978-3319235271

More Books

Students also viewed these Databases questions