Question: Complete the linked list program given in Program 1 by writing the implementation for all of the List class's member functions and completing the main

Complete the linked list program given in Program 1 by writing the implementation for all of the List class's member functions and completing the main function to accomplish each of the following tasks:

Complete the linked list program given in Program 1 by writing the

implementation for all of the List class's member functions and completing the

main function to accomplish each of the following tasks: ou WN 1/Program

1 class FruitNode { private: string name; float price; public: FruitNode *next;

FruitNode (string n, float p) { name - n; price - p;

} void get FruitInfo() ! cout > Apple - RM11.95 >> Kiwi

ou WN 1/Program 1 class FruitNode { private: string name; float price; public: FruitNode *next; FruitNode (string n, float p) { name - n; price - p; } void get FruitInfo() ! cout > Apple - RM11.95 >> Kiwi -RM21.89 Figure 2: Sample output after executing the task2 function Task 3: Define a function named task3. The function should be able to insert a new fruit node at a specific location. The value of the first argument passed to this function determines the position of the node that will be inserted. Assume the value of the first argument to this function is 2. This means that the node that will be inserted will become the second node in the list. Figure 3 depicts the outcome of this task after executing the task3 function with 2 as the first argument value. In this task, you should use a loop. (9.5 marks) Before executing the task3 function headNode rame next name price next price 16.5 Orange Apple 11.95 . 21.89 Kiwi Hext rame price After executing the task3 function with 2 as the first argument value headNode rame nex name next price 16.5 price 19.95 Orange Grape 21.89 Kiwi 11.95 Apple next price name next price rame Figure 3: Current nodes in the list after inserting a new fruit node into the list Task 4: Define a function named taska. The function should be able to remove the last fruit node from the list. Figure 4 depicts the outcome of this task after a number of function calls were made (6.5 marks) 4. Before executing the taske function head Node price mer price Orange 16.5 Grape 19.95 21.89 Kiwi 11.95 Apple next price mame price name Results of the first taske function call head Node name price met mame price Orange 16.5 Grape 19.95 11.95 Apple price mame Results of the second task4. function call head Node price Red ME price re Orange 16.5 Grape 19.95 Figure 4: Current nodes in the list after the deletion of the last node in the list Task 5: Complete the main function with a few function calls. Please use the appropriate function that has been defined and the appropriate argument to obtain the output shown in Figure 5. (14 marks) 5 Fruit List Kiwi - RM21.89 Fruit List Apple - N11.95 >>Kiwi - RM21.89 Fruit List Orange - RM6.50 >> Apple - RM11.95 >> Kivi - RM21.89 Fruit List Orange - RNI 6.50 >> Grape - FM19.95 >> Apple - RM1.95 >> Kivi - RM21.89 Fruit List Orange - RMI 6.50 >> Grape - RM19.95 >> Apple - RM11.95 Fruit List Orange - RM 6.50 >> Grape - FM19.95 Figure 5: The output of the completed Program 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!