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 -1 to
indicate that they are finished entering values (the -1 is intended to be a sentinel, not actual data).
Each value before the -1 entered is to manually added as a Node to a Linked List made up of
dynamically-allocated 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 assn1Test.cpp did not use dynamically-allocated Node instances. You should know how to
dynamically allocate Node instances from CS 112 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 -1, 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 dynamically-allocated 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 List(by 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 assn1Test.cpp, and have
your main() function call listPlay() at the end of its code block just before ending execution
Node.cpp File code:
// CS 211 Fall 2024- Programming Assignment #1
//
// Implements the methods for the Node class
//
// written by: Sharon Tuttle
// modified by: David Tuttle
// last modified: 11 Sep 2024
#include
#include
#include
#include "Node.h"
using namespace std;
// constructors
// Zero-argument 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;
}
// One-argument 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::Node(Node *initLink){
dataField = valueType();
linkPtr = initLink;
}
// One-argument 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::Node(const valueType& initData){
dataField = initData;
linkPtr = NULL;
}
// Two-argument 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::Node(const 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::setData(const 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::setLink(Node *newLinkPtr){
linkPtr = newLinkPtr;
}
Node.h file code:
// CS 211 Fall 2024- Programming Assignment #1
//
#ifndef NODE_H
#define NODE_H
#include
#include
#include
typedef double valueType;
// class: Node
// purpose: could be used to implement a node within a
// singly-linked 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 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 Programming Questions!