Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in c++ Class Specification File (IntList.h) In the IntList.h file, declare a class named IntList. The class must declare a struct for a linked list
in c++
Class Specification File (IntList.h) In the IntList.h file, declare a class named IntList. The class must declare a struct for a linked list of integers: struct ListNode \{ int value; struct ListNode *next; \} The IntList class must contain a member variable that is a pointer to ListNode: ListNode *head; // List head pointer The IntList class must define a constructor that takes no arguments and sets the head member variable to the nullptr pointer value. The IntList class must also declare function prototypes for the following member functions: IntList ( ) ; void appendNode (int); // Append a new node at the end of the list. void insertNode (int); // Insert a new node into the list, maintaining a sorted order. void deleteNode (int); // remove a node from the list. void print (); // output the contents of the list to the screen int length (); // display the list length (number of nodes) to the caller. void maxValue (); // display the largest data value in the list. int total (); // return the total (sum) of all list values to the caller. Interactive "Main" Program In the main function, implement an interactive command-loop similar to those we have used in other labs. (Feel free to copy/paste from other labs if you wish.) Interactive Commands The program must support the following commands: a APPEND a new node at the end of the list c COUNT the nodes in the list (display the list length). d DELETE a node from the list i INSERT a node into the list, maintaining the sorted order. m display the MAXIMUM (largest) value in the list. p PRINT the contents of the list on the console. Format the output as shown in the Sample Output section of this document. That is, the output must include the memory address of each node, the value field, and the value of the next pointer. (We should be able to look at the console output and follow the links from one node to the next in the list.) h HELP text q QUIT (end the program) t display the TOTAL (sum) of all values in the list. The APPEND, DELETE, and INSERT commands must prompt the user to enter an integer value. If the list is empty, the MAXIMUM command must display a "List is empty" message. Sample Output In the sample session shown (below and on the following pages), the text that the user types is shown in bold font. In actuality, all text appears in the same font. (As always, the exact memory addresses of dynamically allocated memory is potentially different each time the program runs.) Sample Input / Output Command: m List is empty. Command: t Total of all list values =0. Command: i Enter number to insert into the list: 12 Command: i Enter number to insert into the list: 4 Command: i Enter number to insert into the list: 32 Command: p head =000001C373181CB0 000001C373181CB0: value =4 next =000001C373181990 000001C373181990: value =12 next =000001C373181F30 000001C373181F30 : value =32 next =0000000000000000 Command: a Enter number to append to the list: 5 Command: p head =000001C373181CB0 000001C373181CB0: value =4 next =000001C373181990 000001C373181990: value =12 next =000001C373181F30 000001C373181F30: value =32 next =000001C3731813F0 000001C3731813F0 : value =5 next =0000000000000000 Command: m Maximum value in list =32 Command: t Total of all list values =53. Command: d Enter number to delete from the list: 5 Command: t Total of all list values =48. Command: m Maximum value in list =32 Sample Input / Output Command: p head =000001C373181CB0 000001 C373181CB0: value =4 next =000001C373181990 000001C373181990: value =12 next =000001C373181F30 000001C373181F30 : value =32 next =000000000000000 Command: i Enter number to insert into the list: 23 Command: i Enter number to insert into the list: 9 Command: C Length of list =5 nodes Command: p head =000001C373181CB0 000001C373181CB0: value =4 next =000001C373181530 000001C373181530 : value =9 next =000001C373181990 000001C373181990: value =12 next =000001C3731816C0 000001C3731816C0: value =23 next =000001C373181F30 000001C373181F30: value =32 next =000000000000000 Command: i Enter number to insert into the list: 2 Command: p head =000001C373181FD0 000001C373181FD0: value =2 next =000001C373181CB0 000001C373181CB0: value =4 next =000001C373181530 000001C373181530: value =9 next =000001C373181990 000001C373181990: value =12 next =000001C3731816C0 000001C3731816C0: value =23 next =000001C373181F30 000001C373181F30: value =32 next =000000000000000 Command: i Enter number to insert into the list: 65 Command: p head =000001C373181FD0 000001C373181FD0: value =2 next =000001C373181CB0 000001C373181CB0: value =4 next =000001C373181530 000001C373181530: value =9 next =000001C373181990 000001C373181990: value =12 next =000001C3731816C0 000001C3731816C0: value =23 next =000001C373181F30 000001C373181F30: value =32 next =000001C373181850 000001C373181850: value =65 next =0000000000000000 Command: C Length of list =7 nodes Sample Input / Output Command: m Maximum value in list =65 Command: t Total of all list values =147. Command: d Enter number to delete from the list: 12 Command: p head =000001C373181FD0 000001C373181CB0: value =4 next =000001C373181530 000001C3731816C0: value =23next=000001C373181F30 000001C373181F30: value =32 next =000001C373181850 000001C373181850 : value =65 next =0000000000000000 Command: C Length of list =6 nodes Command: d Enter number to delete from the list: 8 Data value 8 not found. Command: p head =000001C373181FD0 000001C373181FD0: value =2 next =000001C373181CB0 000001C373181CB0: value =4 next =000001C373181530 000001C373181530: value =9 next =000001C3731816C0 000001C373181F30: value =32 next =000001C373181850 000001C373181850 : value =65 next =0000000000000000 Command: d Enter number to delete from the list: 2 Command: p head =000001C373181CB0 000001C373181CB0 : value =4 next =000001C373181530 000001C373181530: value =9 next =000001C3731816C0 000001C373181F30: value =32next=000001C373181850 000001C373181850 : value =65 next =0000000000000000 Command: d Enter number to delete from the list: 65 Sample Input / Output Command: p head =000001C373181CB0 000001C373181CB0 : value =4 next =000001C373181530 000001C373181530 : value =9 next =000001C3731816C0 000001C3731816C0: value =23 next =000001C373181F30 000001C373181F30: value =32 next =000000000000000 Command: C Length of list =4 nodes Command: m Maximum value in list =32 Command: t Total of all list values =68. Command: d Enter number to delete from the list: 32 Command: p head =000001C373181CB0 000001C373181CB0: value =4 next =000001C373181530 000001C373181530 : value =9 next =000001C3731816C0 000001C3731816C0 : value =23 next =0000000000000000 Command: m Maximum value in list =23 Command: t Total of all list values =36. Command: d Enter number to delete from the list: 4 Command: p head =000001C373181530 000001C373181530 : value =9 next =000001C3731816C0 000001C3731816C0 : value =23 next =0000000000000000 Command: C Length of list =2 nodes Command: t Total of all list values =32. Command: m Maximum value in list =23 Command: d Sample Input / Output Enter number to delete from the list: 9 Command: C Length of list =1 nodes Command: p head =000001C3731816C0 000001C3731816C0 : value =23 next =0000000000000000 Command: d Enter number to delete from the list: 23 Command: C Length of list =0 nodes Command: m List is empty. Command: q Exiting program with status =0 If your program is working correctly, then your results should be the same as shown in the Sample Input/Output aboveStep 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