Question: Using this node.h file. Create node.cpp file to implement node.h, then create a main.cpp file to: - Read in a file (input.txt) that has at
Using this node.h
file. Create node.cpp file to implement node.h, then create a main.cpp file to:
- Read in a file (input.txt) that has at least two lines (you can assume 2 lines). Insert each line into a node creating single linked list (using the definitions in node.h). Then delete the first and last lines. Then print out the remaining list to both the screen and a file named output.txt.
Most of this information can be found in your text book, so you do not have to reinvent the wheel....just understand what you are writing. (Names have been changed to force you to read and understand the List Toolkit listed in the textbook.) Please use the names of member variables and member functions in the attached node.h. For this assignment, you may use the .
You shouldn't have to change node.h but if you do, make sure that you document any changes. Your main.cpp should be really quite short, and your node.cpp should be very similar to the one in the book....please don't just cut and paste...try to understand why you are writing lines of code.
node.h:
#ifndef NODE_H #define NODE_H #include/eeded for NULL #include using namespace std; namespace HW4 { class node { public: // Node data type typedef string dataType; //Default Constructor node(); //Constructor node(dataType &newData); //Accessor Functions dataType getData(); node* getNextPtr(); // Mutator Functions void setData(node::dataType &newData); void setNextPtr(node* &newNextPtr); private: dataType data; node* nextPtr; }; //End of Class /**************************************** Non-member functions The Textbook chooses to make these functions instead of member functions. This is a style call. I would have probably made them member functions, but kept them this way to match your book code. Note that since they are not member functions, you will need to use member accessor and mutator functions in your code! *****************************************/ /*Returns value of the length of the list*/ int listLength(const node* headPtr); /*Inserts a single node at the front of a list*/ void insertAtFront(node*& headPtr,node::dataType &newData); /*Inserts a single node just after the pointer sent in the parameter */ void insertAfterNode(node* previous_ptr,node::dataType &newData); /*Removes a node at the front of the list */ void removeAtFront(node*& head_ptr); /*Remove a single node just after the pointer sent in the parameter*/ void removeAtNode(node* previous_ptr); /*Displays to the stream listed, an entire list from the pointer location to the end of the list*/ void printList(istream &stream, node* headPtr); } //End of Namespace #endif
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
