Question: C++ Write a C++ program that defines a class named Node that contains two public data members. One data member is an integer (it doesn't

C++  C++ Write a C++ program that defines a class named Node

Write a C++ program that defines a class named Node that contains two public data members. One data member is an integer (it doesn't matter what the integer represents). The other data member is a pointer to a Node, name it next. The Node pointer points to another instance of the same class. When a new Node is created, it's constructor should accept 1 integer argument to assign to the data member. It should initialize the Node pointer to NULL. New nodes do not point to any other nodes initially. Print out the following message from inside the constructor: cout data; Related to this concept is the "this" pointer that can be use. to access the current object instance from inside the class. For this assignment, all objects should be created dynamically using pointers. Additionally, only use the "his" pointer to access the data members from inside the class. This will require you to use the "pointer-to-member access" operator in conjunction with the "this" pointer. From main, use a for loop to create a chain of 10 nodes (initialized with data values 1 - 10). Remember,all nodes should be created dynamically. Use the addNode method to chain them together. After creating the chain, use another loop to walk over the chain and display the values again. You do not need to worry about freeing the memory used by the program

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!