Question: Using C + + Now, using the same Node.h and Node.cpp , create new files named listPlay.cpp and listPlay.h ( with all the appropriate parts
Using C
Now, using the same Node.h and Node.cpp create new files named listPlay.cpp and listPlay.h with all the
appropriate parts and pieces a cpp and h file should have and create inside of them a new function
void listPlay that creates and lightly "plays with" a Linked List made up of Node instances, with the
following requirements:
Ask the user to enter as many numeric values as they would like, one at a time, with a value of to
indicate that they are finished entering values the is intended to be a sentinel not actual data
Each value before the entered is to manually added as a Node to a Linked List made up of
dynamicallyallocated Node instances. Your code should add each new Node to the end of the Linked
List, and correctly have the new Node point to NULL since it's added to the end of the list.
Note that assnTest.cpp did not use dynamicallyallocated Node instances. You should know how to
dynamically allocate Node instances from CS class, but here's a quick reminder:
Node nodePtr;
nodePtr new Node; You may choose to call whichever constructor you think is appropriate
After the user has entered the value of your code should then print to the screen a message saying
that it is about to show the user the numbers they entered, and then it should "walk" through the
Linked List, printing to the screen the values stored in each Node, in order, printing all values on one
line with appropriate spacing for readability.
If there is anything else you'd like to do with this lovely Linked List before freeing the memory of its
Node elements? Feel free to do so but no extra points awarded :
Because dynamicallyallocated Node instances were created, before your function listPlay returns,
write a loop that again "walks" through the list and appropriately deletes each Node instance from the
Linked Listby using the delete statement on each Node so that no dynamically allocated Node
instances remain.
Add appropriate code so that listPlay function can be called from main in assnTest.cpp and have
your main function call listPlay at the end of its code block just before ending execution
Node.cpp File code:
CS Fall Programming Assignment #
Implements the methods for the Node class
written by: Sharon Tuttle
modified by: David Tuttle
last modified: Sep
#include
#include
#include
#include "Node.h
using namespace std;
constructors
Zeroargument constructor: expects nothing, and creates
a new Node instance whose data field is the default
for the valueType, and whose link field is NULL
Node::Node
dataField valueType;
linkPtr NULL;
Oneargument constructor: expects a pointer to a Node, and
creates a new Node instance whose data field is the default
for the valueType, and whose link field is set to the given
pointer
Node::NodeNode initLink
dataField valueType;
linkPtr initLink;
Oneargument constructor: expects a valueType value, and
creates a new Node instance whose data field is the given
value, and whose link field is set to NULL
Node::Nodeconst valueType& initData
dataField initData;
linkPtr NULL;
Twoargument constructor: expects a valueType value and a pointer
to a Node, and creates a new Node instance whose data field is
the given valueType value and whose link field is set to the
given pointer
Node::Nodeconst valueType& initData, Node initLink
dataField initData;
linkPtr initLink;
accessors
getData: void valueType
Expects nothing
Returns the value of the calling Node's data field
valueType Node::getData const
return dataField;
getLink: void Node
Expects nothing
Returns the value of the calling Node's link field
TWO VERSIONS provided:
One returns a const version of the Node and one does not
Compiler allegedly uses the "correct" one for a given call.
Node Node::getLink const
return linkPtr;
Node Node::getLink
return linkPtr;
setters
setData: valueType void
Expects data to be stored in a Node
Returns nothing
Side Effects: sets the calling Node's data field to the value
void Node::setDataconst valueType& newData
dataField newData;
setLink: Node void
Expects a pointer to a Node
Returns nothing
Side Effects: sets the calling Node's link field to the given Node
void Node::setLinkNode newLinkPtr
linkPtr newLinkPtr;
Node.h file code:
CS Fall Programming Assignment #
#ifndef NODEH
#define NODEH
#include
#include
#include
typedef double valueType;
class: Node
purpose: could be used to implement a node within a
singlylinked list; each node instance has
two data fields, one holding data and one holding
the address of the next node instance in a list
valueType should be set to be the desired type
for the data to be
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
