Question: You are provided a data file that contains data for the three parameters in the form: John Harris 50000.00 Lisa Smith 75000.48 Adam Johnson 68500.10
You are provided a data file that contains data for the three parameters in the form:
John Harris 50000.00 Lisa Smith 75000.48 Adam Johnson 68500.10 Sheila Smith 150000.50 Tristen Major 75800.76 Yannic Lennart 58000.55 Lorena Emil 43000.00 Tereza Santeri 48000.00
Use the following structure definition to create a singly-linked list.
struct Employee
{
string fname;
string lname;
double salary;
Employee *next;
};
Write the following functions.
a) A function of void return type named create_list that accepts the head of the list as the argument. This function needs to read the data file, read one line at a time and assign the read parameters to the structure members. Now, we need to attach this structure instance as a node to the list. Use this function to assign the elements for the head node as well.
b) A function of void return type called show_list that accepts the head of the list as the argument. In this function, you need to display the contents of all nodes in the list in the format of: LastName FirstName Salary
c) A function of void return type called insert_item that accepts the head of the list and the structure instance to insert. It should also accept the first name of the employee after which the new item needs to be inserted.
d) A function of void return type called delete_item that accepts the head of the list and the first name of the Employee to be deleted from the list.
To test if your program is working, use the following main function.
int main()
{
Employee *head=new Employee; //head of the list
create_list(head);
Employee *item=new Employee; //item to be inserted
item->fname="Robert";
item->lname="Johnson";
item->salary=75000.50;
insert_item(head,"Sheila",item);//insert after Sheila
delete_item(head, "Sheila");//delete Sheila
show_list(head);
return 0;
}
You must get the following output.
John Harris 50000
Lisa Smith 75000.5
Adam Johnson 68500.1
Robert Johnson 75000.5
Tristen Major 75800.8
Yannic Lennart 58000.6
Lorena Emil 43000
Tereza Santeri 48000
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
